• 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

checkbox validation

 
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

following on from Ricardo's post - 'how to validate boolean field...' but that thread seems to have gone cold (my addition hasn't flagged up in the latest posts list) so I'll try again here - appologies if this is missuse

I'm trying to validate the same checkbox scenario but am obviously still doing something wrong. I had made the same mistake using 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 much appreciated. Thanks in advance, Hamish.

(NB further validation of text fields in the same multi page form do work)

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);
}
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try adding checkout.error.acceptTerms=msg in resources file
 
Hamish Rose
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
cheers but unfortunately I already had and even if I hadn't the server should have returned to the page with the checkbox on (letting me know it was doing something) rather than gaily continuing as if nothing was wrong - it seems to be accepting an unchecked box as valid the same as a checked one.

Ultimately I could avoid the problem by either using I Accept / I don't accept radio buttons or with a string value multibox but as others have managed to get this to work I'd like to understand how / why, rather than avoid the problem

H
 
bhuvan sundar
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<html:errors property="acceptTerms"> next to <bean:message>-does that mean that there is another input field by the name "acceptTerms". If that is the case, then, try changing the property value of <html:checkbox>
 
Hamish Rose
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No there is one property in the ActionForm called acceptTerms - the <html:checkbox> should both populate it and be populated by it and the <html:errors> tag should simply display a message from the resourcesbundle if validation on the input (checkbox) for this property fails - they have to have the same name or the error message displayed would relate to a different input field.

ta H
 
Hamish Rose
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again folks and folkettes

in true forum style I've fixed it myself but for those who're interested here's how I did it... I still have no idea how Ricardo did it, if you're there Ricardo let us know??

I added a validwhen clause in validate.xml, as follows

<field
property="acceptTerms"
depends="required, validwhen"
page="1" >
<arg0 key="checkout.error.acceptTerms"/>
<var>
<var-name>test</var-name>
<var-value>(*this* == "true")</var-value>
</var>
</field>

as far as I can tell it validates the depends="required" regardless cos the box either has a value of true or false but always has one (??? not how I thought they were handled) and therefore you have to test for true, but booleans aren't allowed, however fortunately you can test for the string "true" and it seems to work - hey!

cheers for the help, hope this helps some other frustrated sole

H
 
expectation is the root of all heartache - shakespeare. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic