In Struts1.3 How Handling Multiple FormBean property to action
Asked Answered
O

1

0

I am using Struts1.3, I have Jsp page which is showing the list of employees on that page. For this what i did is, I have a action inside that action i am calling a function which returns List and i am setting these list inside the session as session.setAttribute(Constant.EMPLIST,list). And now in my Jsp page i am using logic tag to iterate this list as below given.

<html:form method="post" action="test.do" styleId="empForm">
  <logic:iterate id="EmpForm" name="<%=Constant.EMPLIST%>">
    <table>
     <tr>
      <td>
        <html:text property="empName" name="EmpForm" styleClass="fieldbox2" styleId="textfield50"/>

      </td>
        <td>

        <html:text property="empSal" name="EmpForm" styleClass="fieldbox3" styleId="textfield50"/>

      </td>
 </table>
</logic:iterate>
 <table>
    <tr>
      <td>
        <img onclick="updateEmpDetails" src="images/update.jpg" />
      </td>
    </tr>
  </table>
</html>

And it's showing all the employee details and working fine. But one more job is that on this page i have a update button. And what i need to do is after clicking on updateEmpDetails button. I need to send all the employee updated details inside the updateAction but I am unable to do this, I don't know how to handle the multiple FormBean property value. I am able to fetch only one Employee details inside the updateAction. I am doing this inside my updateAction

 EmpForm empForm = (EmpForm) form;
System.out.println("EmpId:::" + empForm.getEmpId);

I don't know how to do this if possible List Or how to handle multiple FormBean Value. please guide me how to do this,if any example please it really appreciate me. Thanks

Update:: This is my plan java class with setter and getter property:

public class Sites {
    private String jobSite="";        
    private String engineerName="";
    private boolean isCheck;
}

This is my FormBean:

public class SiteToServiceForm extends org.apache.struts.action.ActionForm {


   private List<Sites> sites=new ArrayList<Sites>();

    public List<Sites> getSites() {
        return sites;
    }

    public void setSites(List<Sites> sites) {
        this.sites = sites;
    }


}

This is my action:

public class SiteToServicingAction extends org.apache.struts.action.Action {
 List<Sites> siteDetails=SiteSearchDataModel.getSiteDetails(serviceForm);


        ((SiteToServiceForm) form).setSites(siteDetails);
}

For display purpose working fine now i need to submit the update sites value, I am doing this inside action:

 List<Sites> siteList=serviceForm.getSites();
            if(siteList!=null && siteList.size()>0)
            {
                for(Sites site:siteList)
                {
                    if(site.isIsCheck()==true)
                    {
                        SiteSearchDataModel.updateRecord(serviceForm.getEngineerId(), site.getPropertyId());
                        System.out.println("properyID::::"+site.getPropertyId());
                    }
                }
            }

And i am not able to get the update list into my action class please help me.

Outboard answered 1/11, 2011 at 18:23 Comment(0)
L
1

1 have an Action Form 2 map action form to Action in struts-config.xml 3 have a field List<Employee> in your form 4 on JSP use the following code

<logic:iterate id="emp" indexId="i" name="FormName"
            property="employees">

 <html:text value="${FormName.employees[i].employeeName}" styleClass="fieldbox3"/>
 <html:text value="${FormName.employees[i].employeeSal}" styleClass="fieldbox3"/>

<logic:iterate>
Lambert answered 1/11, 2011 at 18:34 Comment(9)
Thanks,Jigar But it would not full fill my needs, can you give me any example or link that is based on Struts1.3. Which is adding multiple values and updating multiple FormBean values at a time. If it is possible for u than please help me. Thanks a lotOutboard
Jigar, The above is working fine but unable to get the update fields value from the jsp page to action class.It is showing only the original values coming from the DB, and after modifying the fields value it's remain same in action class.Outboard
Have you mapped action class and form bean ?Lambert
can you look at the raw request that is being sent ?Lambert
I used wrong property to access the field, the generated html name is different as i used.Outboard
Jigar, In case of boolean field i am not getting update record please help me, if i added this one <td><html:checkbox name="emp" value="${emp.isCheck}" property="isCheck" styleId="isCheck" indexed="true"/></td> then i am not getting update value true or false.Outboard
browser won't send data if it is false. so in form reset method you need to reset it or else take a hidden field that will submit the false valueLambert
that is different question , you should open new oneLambert
Please see this link,#8169163Outboard

© 2022 - 2024 — McMap. All rights reserved.