You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Sobkowski, Andrej" <An...@emergis.com> on 2002/03/22 16:59:13 UTC

Validating an ActionForm "conditionnally"

Hello,

I've been using the Struts Validator (nightly build of November) with no
problems for a few months (great work!).

Now I need to call the validation method of a specific "nested form" based
on a condition:

ParentForm
+useChild: boolean
+getChildForm:ChildForm

If useChild returns true, I want to call the validate(mapping, request) of
ChildForm (ie the nested form).

I thought that the validator only needed the "mapping.getAttribute()" (name
of the ActionForm) to perform the validation so I tried with the following
(ugly, I know):

if (parentForm.useChild()) {
	ActionMapping newMap = new ActionMapping();
	newMap.setAttribute("childForm"); 
	ActionErrors errors = parentForm.getChildForm().validate(newMap,
request);
}

The configuration is extremely basic:
- In struts-config.xml:
    <form-bean      name="childForm"
                    type="com.company.ChildForm"/>
- In validation.xml:
      <form name="childForm">
		...
      </form>

I'm getting a NullPointerException in the validator's code.

What am I doing wrong? Is this a good way to handle the problem (I doubt
it...)? Any suggestions?

Thanks.

Andrej

Re: Validating an ActionForm "conditionnally"

Posted by David Winterfeldt <dw...@yahoo.com>.
If you have a form nested like this, it probably
doesn't have the servlet reference set on it.

ServletContext application =
getServlet().getServletContext();

Otherwise what you are doing should be fine.

David

--- "Sobkowski, Andrej" <An...@emergis.com>
wrote:
> Hello,
> 
> I've been using the Struts Validator (nightly build
> of November) with no
> problems for a few months (great work!).
> 
> Now I need to call the validation method of a
> specific "nested form" based
> on a condition:
> 
> ParentForm
> +useChild: boolean
> +getChildForm:ChildForm
> 
> If useChild returns true, I want to call the
> validate(mapping, request) of
> ChildForm (ie the nested form).
> 
> I thought that the validator only needed the
> "mapping.getAttribute()" (name
> of the ActionForm) to perform the validation so I
> tried with the following
> (ugly, I know):
> 
> if (parentForm.useChild()) {
> 	ActionMapping newMap = new ActionMapping();
> 	newMap.setAttribute("childForm"); 
> 	ActionErrors errors =
> parentForm.getChildForm().validate(newMap,
> request);
> }
> 
> The configuration is extremely basic:
> - In struts-config.xml:
>     <form-bean      name="childForm"
>                     type="com.company.ChildForm"/>
> - In validation.xml:
>       <form name="childForm">
> 		...
>       </form>
> 
> I'm getting a NullPointerException in the
> validator's code.
> 
> What am I doing wrong? Is this a good way to handle
> the problem (I doubt
> it...)? Any suggestions?
> 
> Thanks.
> 
> Andrej
> 


__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards�
http://movies.yahoo.com/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>