You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Martin Braure de Calignon <br...@free.fr> on 2008/01/08 14:08:24 UTC

Validation question

Hello,

I'm currently using struts2 for a project.
I want to validate all elements of a list (each elements should have a
non-empty value, or the list should be empty).

what I have done in my validator is :
<!-- correct doctype above and some field-validator-->

<validator type="expression">
	<param name="expression">
		<![CDATA[
			
		((myList.isEmpty) || (myList{? #this.value != null}.size ==
myList.size))
		]]>
	</param>
	<message>error ${myList.size}</message>
</validator>
<!-- correct end of file below this line -->

Then in console I have a warning, and the validator does not do what I
want.
	WARN - Got result of null when trying to get Boolean
I don't know if it is related to my validator but it seems to be.

Any idea on how writing validator on all elements of the list ?

Thanks :-)
-- 
Martin Braure de Calignon

[S2] validation on list of bean (was Validation question)

Posted by Martin Braure de Calignon <br...@free.fr>.
Le mardi 08 janvier 2008 à 14:08 +0100, Martin Braure de Calignon a
écrit :

Sorry I've forgot [S2] in subject
> Hello,
> 
> I'm currently using struts2 for a project.
> I want to validate all elements of a list (each elements should have a
> non-empty value, or the list should be empty).
> 
> what I have done in my validator is :
> <!-- correct doctype above and some field-validator-->
> 
> <validator type="expression">
> 	<param name="expression">
> 		<![CDATA[
> 			
> 		((myList.isEmpty) || (myList{? #this.value != null}.size ==
> myList.size))
> 		]]>
> 	</param>
> 	<message>error ${myList.size}</message>
> </validator>
> <!-- correct end of file below this line -->
> 
> Then in console I have a warning, and the validator does not do what I
> want.
> 	WARN - Got result of null when trying to get Boolean
> I don't know if it is related to my validator but it seems to be.
> 
> Any idea on how writing validator on all elements of the list ?
> 
> Thanks :-)
-- 
Martin Braure de Calignon

Re: Validation question

Posted by Martin Braure de Calignon <br...@free.fr>.
Le vendredi 11 janvier 2008 à 15:46 -0800, Dave Newton a écrit :
> The validation interceptor will look for, and call, validate${methodName}
> (and validateDo${methodName}).
> 
> d.

Great ! thank you all :-)
-- 
Martin Braure de Calignon

Re: Validation question

Posted by Dave Newton <ne...@yahoo.com>.
The validation interceptor will look for, and call, validate${methodName}
(and validateDo${methodName}).

d.

--- Martin Braure de Calignon <br...@free.fr> wrote:

> 
> Le vendredi 11 janvier 2008 à 09:15 -0500, Ted Husted a écrit :
> > On Jan 11, 2008 8:10 AM, Martin Braure de Calignon <br...@free.fr>
> wrote:
> > > Of course yes :-). But I need a validate() per method.
> > 
> > I haven't used it myself, but the syntax validate-action is suppose to
> > work, in the same way that it works for the validation framework.
> 
> I don't think so. You see, with per alias or per method validation, you
> can have multiple xml files for the same action with the filename
> format : ActionName-alias-validation.xml
> 
> e.g.: 
> if I have defined my action like this :
> <action name="CycleManagement!*" class="...[a class]" method="{1}">
>         <result name="A">View1.jsp</result>
>         <result name="B">View2.jsp</result>
>         <result name="C">View3.jsp</result>
> </action>
> 
> I can per alias validation. As I'm using wildcards, it is as if I
> defined CycleManagement!A action and CycleManagement!B action ...
> 
> So I can have :
> CycleManagement-CycleManagement!A-validation.xml
> CycleManagement-CycleManagement!B-validation.xml
> CycleManagement-CycleManagement!C-validation.xml
> 
> I don't see how implementing Validatable allow me such a thing. I will
> only have one Validate() method (without parameter) for my action class.
> 
> No ? Am I missing something ?
> 
> Cheers,
> 
> -- 
> Martin Braure de Calignon
> 


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


Re: Validation question

Posted by Martin Braure de Calignon <br...@free.fr>.
Le vendredi 11 janvier 2008 à 09:15 -0500, Ted Husted a écrit :
> On Jan 11, 2008 8:10 AM, Martin Braure de Calignon <br...@free.fr> wrote:
> > Of course yes :-). But I need a validate() per method.
> 
> I haven't used it myself, but the syntax validate-action is suppose to
> work, in the same way that it works for the validation framework.

I don't think so. You see, with per alias or per method validation, you
can have multiple xml files for the same action with the filename
format : ActionName-alias-validation.xml

e.g.: 
if I have defined my action like this :
<action name="CycleManagement!*" class="...[a class]" method="{1}">
        <result name="A">View1.jsp</result>
        <result name="B">View2.jsp</result>
        <result name="C">View3.jsp</result>
</action>

I can per alias validation. As I'm using wildcards, it is as if I
defined CycleManagement!A action and CycleManagement!B action ...

So I can have :
CycleManagement-CycleManagement!A-validation.xml
CycleManagement-CycleManagement!B-validation.xml
CycleManagement-CycleManagement!C-validation.xml

I don't see how implementing Validatable allow me such a thing. I will
only have one Validate() method (without parameter) for my action class.

No ? Am I missing something ?

Cheers,

-- 
Martin Braure de Calignon

Re: Validation question

Posted by Ted Husted <hu...@apache.org>.
On Jan 11, 2008 8:10 AM, Martin Braure de Calignon <br...@free.fr> wrote:
> Of course yes :-). But I need a validate() per method.

I haven't used it myself, but the syntax validate-action is suppose to
work, in the same way that it works for the validation framework.

HTH, Ted
 * <http://www.StrutsMentor.com/>

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


Re: Validation question

Posted by Martin Braure de Calignon <br...@free.fr>.
Le vendredi 11 janvier 2008 à 07:36 -0500, Ted Husted a écrit :
> Rather than use the validation framework, I'd probably go with a
> Validate method (by implementing Validatable).

Firstly, thank you very much for your answer :)

Ok then... That what I though... But my problem is that Validate() is
called every time no ?
I mean, I currently use action like that :

<action name="CycleManagement!*" class="...[a class]" method="{1}">
	<result name="A">View1.jsp</result>
	<result name="B">View2.jsp</result>
	<result name="C">View3.jsp</result>
</action>

and I have per-method validation...
Is it possible with Validate() ? How can I do ? (I think it's possible
with ActionContext.(... get current method...))

> Then, instead of using an OGNL expression, you can loop through the
> list using Java, and call addFieldError if there's a problem.
Of course yes :-). But I need a validate() per method.

> Alternatively, a custom type converter that turned the nulls into
> false booleans might work, or there might be another way to form the
> OGNL expression. But given the choice between OGNL and Java, I'll take
> Java. :)

So for me it seems the better choice would be type converter ? what do
you think ?

Thanks,

-- 
Martin Braure de Calignon

Re: Validation question

Posted by Ted Husted <hu...@apache.org>.
Rather than use the validation framework, I'd probably go with a
Validate method (by implementing Validatable).

Then, instead of using an OGNL expression, you can loop through the
list using Java, and call addFieldError if there's a problem.

Alternatively, a custom type converter that turned the nulls into
false booleans might work, or there might be another way to form the
OGNL expression. But given the choice between OGNL and Java, I'll take
Java. :)

HTH, Ted
<http://www.StrutsMentor.com/>

On Jan 8, 2008 8:08 AM, Martin Braure de Calignon <br...@free.fr> wrote:
> Hello,
>
> I'm currently using struts2 for a project.
> I want to validate all elements of a list (each elements should have a
> non-empty value, or the list should be empty).
>
> what I have done in my validator is :
> <!-- correct doctype above and some field-validator-->
>
> <validator type="expression">
>         <param name="expression">
>                 <![CDATA[
>
>                 ((myList.isEmpty) || (myList{? #this.value != null}.size ==
> myList.size))
>                 ]]>
>         </param>
>         <message>error ${myList.size}</message>
> </validator>
> <!-- correct end of file below this line -->
>
> Then in console I have a warning, and the validator does not do what I
> want.
>         WARN - Got result of null when trying to get Boolean
> I don't know if it is related to my validator but it seems to be.
>
> Any idea on how writing validator on all elements of the list ?
>
> Thanks :-)
> --
> Martin Braure de Calignon

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