Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Struts 1.1 validation help on Requiredif  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to implement requiredif but it is not working for me in Tomcat
4.1 with Struts 1.1.
Can anybody please send me (mystruts2004@yahoo.com) a sample war file that
has one requiredif validation.
This help is very much helpful.
Thanks in advance.
 
pie sneak
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://jakarta.apache.org/struts/userGuide/dev_validator.html
This may direct you in the right direction.
There's a good reason why requiredif is already deprecated. It's ugly.
I recommend writing your own validation method to achieve the functionality. It's not too hard to do. Just have a method that returns false if you don't want to run any validations.
validwhen may even be a good option unless you are using the 1.1 production release.
 
chingh tangh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've gone through requiredif & validwhen in apache site. But, as our production release is struts 1.1, need to implement with requiredif until struts 1.2 goes into our prod.
Tried "requiredif" mentioned in apache, but of no luck. Only "required" validation is working, not getting why in the sameway "requiredif" is not working !!!
I am using Tomcat 4.1
here is my validations.xml
<field property="age" depends="required">
<arg0 key="label.age"/>
</field>
<field property="name" depends="requiredif">
<arg0 key="label.name"/>
<var>
<var-name>field[0]</var-name>
<var-value>age</var-value>
</var>
<var>
<var-name>fieldTest[0]</var-name>
<var-value>NOTNULL</var-value>
</var>
</field>
[ I have tried for NOTNULL and also NULL]
here is the form-bean
<form-bean name="TestForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="age" type="java.lang.String" />
<form-property name="name" type="java.lang.String" />
<form-property name="submit" type="java.lang.String" />
</form-bean>
jsp
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:form action="MedicalAction" onsubmit="return validateTestForm(this)" >
<html:text property="age" value="" />
<html:text property="name" value="" />
<html:submit property="submit" value="sbt" />
</html:form>
<html:javascript formName="TestForm"/>
Here required validation for 'age' is working fine, But 'name' is not being validated for "requiredif".
I have seen the html page generated, it doesn't have the javascript code for "name".
I am not sure - why required validation is working and why in the sameway requiredif is not working.
Any kind of guess is also thankful.
thanx in advance.
 
We don't have time to be charming! Quick, read this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!