Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to validate a boolean field using struts validation

 
Ricardo Estafan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

how can i validate a boolean field using struts validation.
The depends="required" doesn't seem to work...
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would you please explain your scenario? It isn't making sense to me why you are trying to do this in the first place.
 
Ricardo Estafan
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic