struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shirish <shirish...@yahoo.co.in>
Subject Need all functionality in one screen/form (check box , dynamic rows , user inputs , validation) & all using dynaform.
Date Tue, 17 May 2005 14:16:32 GMT
Need all functionality in one screen/form (check box , dynamic rows , user inputs , validation)
& all using dynaform.
Here is the code.
--------------------------------------------------------------------------------------
* Dynaform 
<form-bean name="adjustmentForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property   name="employees" type=""java.util.ArrayList"" />
</form-bean>
This form is in request scope.

* Not yet reach to validation configuration (using validation.xml)
--------------------------------------------------------------------------------------
* Action class 
        java.util.ArrayList empoyeebeans = getDataPopulatebean() // get data in list. get
data & populate below bean
 dynaForm.set("employees",empoyeebeans);
--------------------------------------------------------------------------------------
Here is bean ( 
public class EmployeeBean {
   public String getEmpid() {
        return empid;
    }
    public void setEmpid(String empid) {
        this.empid = empid;
    }
    public String getEmployeename() {
        return employeename;
    }
    public void setEmployeename(String employeename) {
        this.employeename = employeename;
    }
    public String getDate() {
        return date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public String getPremium() {
        return premium;
    }
    public void setPremium(String premium) {
        this.premium = premium;
    }
    public String getTier() {
        return tier;
    }
    public void setTier(String tier) {
        this.tier = tier;
    }
    private String empid;
    private String employeename;
    private String premium;
    private String date;
    private String tier;
}
-----------------------------------------------------------------------------------------------
JSP code

  <logic:iterate id="employee" name="adjustmentForm" property="employees" indexId="count">
                    <bean:define id="remainder" value="<%=Integer.toString(count.intValue()
% 2) %>"/>
  <tr>
                    <td> <html:checkbox name="employee" property = "empid" value="<%=((EmployeeBean)ebs.get(count.intValue())).getSsn()%>"
indexed="true"/></td>
                    <td>Employee SSN</td>
                    <td><bean:write name="employee" property = "empid" />  </td>
                </tr>
              <tr>
                    <td>&nbsp;</td>
                    <td>Employee Name</th>
                    <td><bean:write name="employee" property = "employeename" />
<html:hidden name="employee" property = "employeename"  indexed="true"/> </td>
                </tr>
                <tr>
                    <td >&nbsp;</td>
                    <td >Tier</th>
                    <td ><bean:write name="employee" property = "tier" /> <html:hidden
name="employee" property = "tier"  indexed="true"/></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>Premium</th>
                    <td><bean:write name="employee" property = "premium" /> <html:hidden
name="employee" property = "premium"  indexed="true"/> </td>
                </tr>
                <tr >
                    <td >&nbsp;</td>
                    <td >Reason</td>
                    <td><select  id="reason" name="reason"> <option value=""></option></select></td>
               </tr>
               <tr>
                   <td> &nbsp;</td>
                   <td>Termination Date</td>
                   <td><html:text name="employee" property = "date" indexed="true"
/> <html:hidden name="employee" property = "date"  indexed="true"/></td>
                </tr>
     </logic:iterate> 

-----------------------------------------------------------------------------------------------
HTML code
                <tr>
                    <td> <input type="checkbox" name="employee[0].empid" value="7464264327"
checked="checked"></td>
                    <td>Employee SSN</td>
                    <td>7464264327  </td>
                </tr>
              <tr>
                    <td>&nbsp;</td>
                    <td>Employee Name</th>
                    <td>BARKSDALE,JACK <input type="hidden" name="employee[0].employeename"
value="BARKSDALE,JACK"> </td>
                </tr>
                <tr>
                    <td >&nbsp;</td>
                    <td >Tier</th>
                    <td >ES <input type="hidden" name="employee[0].tier" value="ES"></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>Premium</th>
                    <td>150.00 <input type="hidden" name="employee[0].premium" value="150.00">
</td>
                </tr>
                <tr >
                    <td >&nbsp;</td>
                    <td >Reason</td>
                    <td><select  id="reason" name="reason"> <option value=""></option></select></td>
 // This is still under construction
               </tr>
               <tr>
                   <td> &nbsp;</td>
                   <td>Termination Date</td>
                   <td><input type="text" name="employee[0].date" value=""> <input
type="hidden" name="employee[0].date" value=""></td>
                </tr>
 
                <tr>
                        
                    <td> <input type="checkbox" name="employee[1].empid" value="7464264324"
checked="checked"></td>
                    <td>Employee SSN</td>
                    <td>7464264324  </td>
                </tr>
              <tr>
                    <td>&nbsp;</td>
                    <td>Employee Name</th>
                    <td>ARBOR,ROBERT B <input type="hidden" name="employee[1].employeename"
value="ARBOR,ROBERT B"> </td>
                </tr>
                <tr>
                    <td >&nbsp;</td>
                    <td >Tier</th>
                    <td >EMP <input type="hidden" name="employee[1].tier" value="EMP"></td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                    <td>Premium</th>
                    <td>100.00 <input type="hidden" name="employee[1].premium" value="100.00">
</td>
                </tr>
                <tr >
                    <td >&nbsp;</td>
                    <td >Reason</td>
                    <td><select  id="reason" name="reason"> <option value=""></option></select></td>
               </tr>
               <tr>
                   <td> &nbsp;</td>
                   <td>Termination Date</td>
                   <td><input type="text" name="employee[1].date" value=""> <input
type="hidden" name="employee[1].date" value=""></td>
                </tr>
 
------------------------------------------------------------------------------------------------
Here is the issue >>> when I click on submit >> bean is not get populated >>>
as bean not get populated, I can write validation code in validation.xml 
& require bean get populated with selected check box plus corresponding row also means
corresponding employee name , tier , premium & user input date & reason
------------------------------------------------------------------------------------------------
I thought that Struts framework will do this for me.
To overcome this I wrote below code in Action class which get call once clicked on submit.
Calling below method to populate bean & validation from Action class
public void validateForm(DynaValidatorForm dyna, HttpServletRequest request) {
        int size = ((java.lang.Integer) dyna.get("size")).intValue();
        ArrayList ebs = new ArrayList();
        for (int i = 0; i < size; i++) {
            if (request.getParameter("employee[" + i + "].ssn") != null) {
                com.edocs.application.hbmgrp.appflow.adjustments.EmployeeBean eb = new com.edocs.application.hbmgrp.appflow.adjustments.EmployeeBean();
                eb.setDate(request.getParameter("employee[" + i + "].date"));
                eb.setEmployeename(request.getParameter("employee[" + i + "].employeename"));
                eb.setPremium(request.getParameter("employee[" + i + "].premium"));
                eb.setSsn(request.getParameter("employee[" + i + "].ssn"));
                eb.setTier(request.getParameter("employee[" + i + "].tier"));
                ebs.add(eb);
            }
        }
        dyna.set("employees", ebs);
}
----------------------------------------------------------------------------------------------------
By doing above thing will solve my issue, but I am missing many things here (this is very
bad).
What I am missing?
 * Validation by configuration ( in validation.xml)
 * Populating form by hand.
 * Above points are related to each other (for validation form require to populate before
execute method).
Please suggest me steps to solve above issues?
----------------------------------------------------------------------------------------------------
 
 
 
 

 

		
---------------------------------
Do you Yahoo!?
 Yahoo! Mail - Find what you need with new enhanced search. Learn more.
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message