• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to validate a boolean field using struts validation

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

how can i validate a boolean field using struts validation.
The depends="required" doesn't seem to work...
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic