You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Wendy Smoak <We...@asu.edu> on 2003/04/02 00:16:08 UTC

Help with validation

I have what is basically a true/false radio button on a form, except that
I'm really doing it with a hidden field that I set based on some stuff
sitting in the session.

So in the JSP, it's either:
   <html-el:hidden property="staffPresent" value="true"/>
or
   <html-el:hidden property="staffPresent" value="false"/>
which is wrapped by a <logic-el:present/notPresent> arrangement.

What do I put in validation.xml to ensure that staffPresent=true when the
form is submitted, or else have the validator return an error?

I can do 'required' but I can't tell how to check whether a Boolean is true.

Is this something I should be doing manually in the validate method, or is
there a way to do it with Validator?  Do I need to write my own Validator
for this?  I see you can require a field to be in integer in a range, but
this would be like putting a radio button on a page ("I agree to these
terms: Yes/No") and then needing to validate that the user set it to "Yes".

The problem seems to be that when I call initialize() in the reset method,
the form property 'staffPresent' is set to false.  So if I just use
'required', that always passes since there's _something_ in staffPresent.


Snippets that may help...

validation.xml:
    <form name="clearanceRequestForm">
         <!-- Staff List is required at Finish -->
         <field property="staffPresent" depends="required">
         	<arg0 key="label.staff"/>
         </field>
    </form>    

struts-config.xml:
  <form-bean      name="clearanceRequestForm"
                  type="edu.asu.vpia.struts.ClearanceRequestForm">
      <form-property name="userAction"            type="java.lang.String"/>
      <form-property name="staffPresent"          type="java.lang.Boolean"
initial="false"/>
  </form-bean>               

ClearanceRequestForm.java:
   public ActionErrors validate( ActionMapping mapping,
         HttpServletRequest request )
   {
      //only validate if 'Finish' has been clicked
      if ( "Finish".equals( request.getParameter("userAction") ) {
         super.validate( mapping, request );
      }
   }

Thanks!

-- 
Wendy Smoak
Applications Systems Analyst, Sr.
Arizona State University PA Information Resources Management

Re: Help with validation

Posted by Rick Reumann <r...@reumann.net>.
On Tue, 01 Apr 2003 15:16:08 -0700
Wendy Smoak <We...@asu.edu> wrote:

  
> I have what is basically a true/false radio button on a form, except
> that I'm really doing it with a hidden field that I set based on some
> stuff sitting in the session.

Maybe I'm missing something because if you are setting this up why do
you really need to validate it? I usually only need the validation
framework for making sure the user doesn't mess up. It sounds like you
are using it to double check that you added the hidden field on the
page - but why would that need to be validated if you put it there?

Sorry if I'm missing something.

-- 
Rick Reumann

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org