Announcement Announcement Module
Collapse
No announcement yet.
How to validate command class which is an arraylist Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to validate command class which is an arraylist

    I have an arraylist object as commandclass -JoblessHistories which contains
    jobhistory objects. When jsp loop through JoblessHistories, startDateMonth in jobhistory should be validated.

    But my validation class seems does not work. Do you know any solutions?
    I don't like convert my JoblessHistories into a normal commandclass, since there are dynamic member jobhistory objects will be displayed in jsp

    My Bean
    <bean id="editUnemploymentHistoryForm" class="com.ameriquest.ea.web.UnemploymentHistoryCo ntroller">
    <property name="formView"><value>addUpdateUnemploymentHistor yForm</value></property>
    <property name="commandClass"><value>com.ameriquest.ea.domai n.JoblessHistory</value></property>
    <property name="successView"><value>unemploymentDataRedirect </value></property>
    <property name="backView"><value>employmentDataBackRedirect</value></property>
    <property name="validator"><ref local="unemploymentHistoryValidator"/></property>
    </bean>

    My jsp :
    jobLessHistories is an arraylist which contains mutilple jobhistory objects,
    In jobhistory object, there is an instance variable as startDateMonth. I want to validate to validate startDateMonth

    <c:forEach varStatus="loop" items="${command.joblessHistories}">
    <td valign="top" nowrap>
    <spring:bind path="command.joblessHistories[${loop.index}].startDateMonth">
    <FONT color="red">
    <B><c:out value="${status.errorMessage}"/></B>
    </FONT>
    <INPUT type="text" maxlength="2" size="2" name="<c:out value="${status.expression}" />" value="<c:out value="${status.value}"/>" >
    </spring:bind>
    /
    <spring:bind path="command.joblessHistories[${loop.index}].startDateYear">
    <INPUT type="text" maxlength="4" size="4" name="<c:out value="${status.expression}" />" value="<c:out value="${status.value}"/>" >
    </spring:bind>
    </td>
    </c:forEach>

    My validator

    public class UnemploymentHistoryValidator implements Validator {

    public boolean supports(Class clazz) {
    return JoblessHistory.class.isAssignableFrom(clazz);
    }


    public void validate(Object obj, Errors errors) {
    JoblessHistory jb = (JoblessHistory) obj;

    Iterator it = jb.getJoblessHistories().listIterator();
    while ( it.hasNext()){
    JobTimeOff jh= (JobTimeOff) it.next();
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "startDateMonth", "required", "required");
    System.out.println( "startDateMonth :" + jh.getStartDateMonth());
    System.out.println( "text:" + jh.getText());
    }




    }

    }
Working...
X