aspose file tools*
The moose likes Struts and the fly likes Struts Validation  with  ArrayLiist of beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts Validation  with  ArrayLiist of beans" Watch "Struts Validation  with  ArrayLiist of beans" New topic
Author

Struts Validation with ArrayLiist of beans

sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
I am trying to validate wether user selected a check box or not.
In jsp I have a collection of beans and displaying as follows.

<html:form action="/edit.do?method=edit">
<logic:iterate indexId="i" id="collection" name="dataForm" property="collection">
<%if (i.intValue()%2 == 0)
{%>
<tr>
<%}else{%>
<tr bgcolor=#C0C0C0>
<%}%>


<td>
<html:checkbox name="collection" property="sceneid" indexed="true"/>

</td>
<td>
<bean:write name="collection" property="personid" />

</td>
</tr>
</logic:iterate>
<tr><td><html:submit styleClass="button" property="edit">Edit</html:submit><td>
</html:form>

When I submit it is calling action class and edit method and returning the forward jsp. But it sgould validate.

Here is my validate.xml file

<form name="/edit">
<field property="sceneid" indexedListProperty="collection" depends="required">
<arg0 key="Select the check box" resource="false"/>

</field>
</form>

"/edit" is my action path name. I am not using formName but I tried with form name also.

Action Class :
public class LifeAAction extends DispatchAction {
public ActionForward edit(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {


return mapping.findForward("edit");
}
}
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
Can some one take a look at this please
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
Helooo, Any help on this please ?
Cendy Nguvy
Ranch Hand

Joined: May 25, 2005
Posts: 37
Could you show us action-mappings definition for LifeAAction ?
Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
First, you should be using c:if tag for your if statement and not scriptlets.

Have you gotten anything else in this form to validate?

Are you trying to validate that one or more is being checked?
[ August 08, 2005: Message edited by: Kerry Wilson ]

http://www.goodercode.com
SCJP 1.4
Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
Your action needs to extend ValidatorAction.

My Bad, form needs to extend ValidatorForm.
[ August 08, 2005: Message edited by: Kerry Wilson ]
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
Kerry, I will use C:if tag later after make it work. This is a test page, I may have some more validation on the form. But for now I am checking if user selects atleast on check box (Required), Then I want to check if user selects more than one check box and clicked edid button I should validate to show he can only select one check box.

Cendy,

Here is the mapping.

<action path="/edit" type="com.amfam.lifewkfl.web.actions.LifeAAction"
name="dataForm" scope="session" parameter="method" validate="true" input="page.lifeA">
<forward name="edit" path="page.edit" />
</action>
sudhakar Tadepalli
Ranch Hand

Joined: Dec 27, 2001
Posts: 130
Heloo...knock..knock...who is there ?..have a look
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts Validation with ArrayLiist of beans