aspose file tools*
The moose likes Struts and the fly likes How to validate a boolean field using struts validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to validate a boolean field using struts validation" Watch "How to validate a boolean field using struts validation" New topic
Author

How to validate a boolean field using struts validation

Ricardo Estafan
Ranch Hand

Joined: Mar 29, 2004
Posts: 84
Hello,

how can i validate a boolean field using struts validation.
The depends="required" doesn't seem to work...
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Would you please explain your scenario? It isn't making sense to me why you are trying to do this in the first place.


A good workman is known by his tools.
Ricardo Estafan
Ranch Hand

Joined: Mar 29, 2004
Posts: 84
On the screen there is a checkbox:


with the checkbox checked the user accepts the given terms and it corresponds with a boolean value in the form. It has to be true to proceed to the next page.

So in my struts validation i want to make sure the given boolean is set to true.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

"required" should work for that scenario. Post your validation declaration and we'll see if we can't get it working.
Ricardo Estafan
Ranch Hand

Joined: Mar 29, 2004
Posts: 84
Thanks i tried the required it worked. My jsp was still using a html tag instead of a struts tag, so the boolean was never set correctly.

Thanks for the effort!!
Hamish Rose
Greenhorn

Joined: Dec 14, 2005
Posts: 6
Hi Folks

I'm trying to validate the same scenario but am obviously still doing something wrong. I had made the same mistake with html input tags instead of struts html:checkbox tags. However rectifying this hasn't made any difference at all. Below are the relevant bits out of my code, if someone can tell me where I'm going wrong it'd be great. Thanks in advance, Hamish.

from jsp...

<html:hidden property="page" value="1"/>
<td colspan="5" class="bodyHeader"><bean:message key="checkout.custDetails.lable.acceptTerms"/><div class="bodyError"><html:errors property="acceptTerms"/></div></td>
<td></td>

<td colspan="3" align="right"><img src="<%=request.getContextPath()%>/images/rightArrow.gif" border="0"/> <bean:message key="cart.link.terms"/></td>
<td></td>
<td><html:checkbox property="acceptTerms"/></td>

from validate.xml...

<form name="orderForm">
<field
property="acceptTerms"
page="1"
depends="required">
<arg0 key="checkout.error.acceptTerms"/>
</field>

reset method in action form (which extends ValidatorForm)...

public void reset(){
this.setAcceptTerms(false);
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to validate a boolean field using struts validation