HI,
I am not sure if this reached the list the first time round.
I have the following DynaFormBean defined in tiles-def.xml:

<form-bean  name="answerDetailsForm"
                  dynamic="true"
                  type="org.apache.struts.action.DynaActionForm">
                  <form-property name="fieldIdMemberIds"
type="java.lang.String[]" />
                  <form-property name="questionName" type="java.lang.String"
/>

</form-bean>
 
I am using the following code excerpt from the form which creates the
<%=name%> dynamically
based on values returned from the database.I want to use DynaFormBeans or a
sub-class of it 
or DynaValidatorForm to make sure that the field is required and one of the
radio buttons for 
each field is checked. How can I do that ? 




<%
 for (int i1=0;i1 < fields.length; i1++) {
        Field field = (Field)fields[i1];
        long fieldId = field.getFieldId();
        String name = "fieldValue";
        String member = "memberId" + memberId;
        name = name + fieldId + member;
                            

%>
    <tr align="right">
       <td><input type="hidden" name="fieldIdMemberIds" value="<%=name %>"
/></td>
       <html:errors property="<%=name%>" />
       <td><%=field.getFieldName()%> </td>
       <%
           Collection colFieldValues =
FieldValuesHandler.getFieldValues(fieldId);
           Iterator iterFieldValues = colFieldValues.iterator();
           while (iterFieldValues.hasNext()) {
                    FieldValues fieldValue = (FieldValues)
iterFieldValues.next();
            
        %>

        <td><input type="radio" name="<%=name%>" value="<%=fieldValueDflt%>"
<%if (fieldValueAnswer.equals(fieldValueDflt)) {%>checked <%}%>
/><%=fieldValueDflt%></td>
        <%
             }
         %>


I have the following code in my action class and call validate(..) method
from the execute() method:

public ActionForward validate(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws
ServletException {
        boolean validated = true;
        DynaActionForm dynaForm = (DynaActionForm) form;
        String[] fieldIDMemberIds = (String[])
dynaForm.get("fieldIdMemberIds");
        for (int i = 0; i < fieldIDMemberIds.length; i++) {
            String fieldIdMemberId = fieldIDMemberIds[i];
            String answer = request.getParameter(fieldIdMemberId);
            if (answer == null || answer.length()<= 0) {

                ActionErrors errors = new ActionErrors();
                ActionError newError = new
ActionError("validate.error.required",fieldIdMemberId);
                errors.add(ActionErrors.GLOBAL_ERROR, newError);
                saveErrors(request, errors);
                // Return back to the previous state
                validated = false;

            }
        }
        if (validated) {
            return null;
        }  else {

           return mapping.getInputForward();
        }
    }


Unfortunately, when i try to use <html:errors />, it just prints out the
last error only.

Thanx in advance,
Vijay


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>

Reply via email to