You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Andrew Waite <an...@gmail.com> on 2005/02/12 16:54:45 UTC

Using Struts Validator on Map-backed ActionForms

I have searched far and wide for an update to this topic but can not
seem to find an actual solution.

Has anyone accomplished this? I know in one thread Ted Husted
mentioned it being possible but had questions about the use case, well
if you're listenening here's my use case.

I am writing a client to a web-service that returns layout information
and field required/data types dynamically. I never know what the
schema will be but I do get the metadata in regards to  what the data
type is and whether the field is required for form submission.

Hope that helps the creative juices out there.

Thanks for any help that can be provided.

Andrew

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


Re: Using Struts Validator on Map-backed ActionForms

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
OK I see what you mean and I agree its not possible to configure validator
in the traditional way. So the question is what mechanism do you have that
tells you how to validate these fields? You must be getting some meta data
that indicates what validation needs to be done for a specific property? My
first thought would be that when you receive that meta data, you use it to
create the validator resources - basically doing the job that the
ValidatorPlugIn does when it parses the validation.xml and loads the
validators resources.

Niall

----- Original Message ----- 
From: "Andrew Waite" <an...@gmail.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Sunday, February 13, 2005 11:30 AM
Subject: Re: Using Struts Validator on Map-backed ActionForms


> Niall,
>
> Thanks again for the reply. I am afraid this is not going to work for
> me, however.  The problem is I don't see how I can "do nothing
> different than normal validation".  Normal validation requires the
> field names and validations to be declared in the validation.xml file.
>  I do not know in advance what those values will be. :(
>
> If I am missing something let me know but I am just not able to comply
> with the validation.xml declaration requirement since I don't know
> what to put in the property value:
>
> <form name="myLazyForm">
>     <field property="???????????"  depends="required">
>         <arg key="myLazyForm.?????????.displayname"/>
>     </field>
> </form>
>
> Andrew



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


Re: Using Struts Validator on Map-backed ActionForms

Posted by Andrew Waite <an...@gmail.com>.
Niall,

Thanks again for the reply. I am afraid this is not going to work for
me, however.  The problem is I don't see how I can "do nothing
different than normal validation".  Normal validation requires the
field names and validations to be declared in the validation.xml file.
 I do not know in advance what those values will be. :(

If I am missing something let me know but I am just not able to comply
with the validation.xml declaration requirement since I don't know
what to put in the property value:

<form name="myLazyForm">
    <field property="???????????"  depends="required">
        <arg key="myLazyForm.?????????.displayname"/>
    </field>
</form>

Andrew


On Sun, 13 Feb 2005 02:25:04 -0000, Niall Pemberton
<ni...@blueyonder.co.uk> wrote:
> There isn't anything different you need to do from normal validation.
> 
> http://struts.apache.org/userGuide/dev_validator.html
> 
> The only issue you might hit is if you want to validate according to the
> Action Mapping's path, rather than the form name. Then you would need a
> custom ActionForm - but thats very straight forward. Just extend either
> BeanValidatorForm or LazyValidatorForm and instantiate the LazyDynaMap in
> the constructor and fix the validation key (use setPathValidation(true)
> method) to use the mapping's path. Something like...
> 
> public class MyLazyForm extends LazyValidatorForm() {
>     public MyLazyForm() {
>         super(new LazyDynaMap());
>         setPathValidation(true);
>     }
> }
> 
> Some people don't like using the setPathValidation() because
> BeanValidatorForm automatically removes the leading "/" - if thats the case
> you can just override getValidationKey() method....
> 
>     public String getValidationKey(ActionMapping mapping,
>                                    HttpServletRequest request) {
>          return mapping.getPath();
>     }
> 
> Obviously in your struts-config you need to specify this new form....
> 
>  <form-bean name="mapForm" type="myPackage.MyLazyForm"/>
> 
> Niall
> 
> ----- Original Message -----
> From: "Andrew Waite" <an...@gmail.com>
> Sent: Saturday, February 12, 2005 10:50 PM
> 
> > Thanks for the response. This is looking promising - excellent work, btw.
> >
> > I have the Action and Struts communicating with this "form".  Do you
> > have any example of how to apply the Validaror against it?  Looking
> > for some samples but given how new this is it's hard to come by.
> >
> > Thanks,
> > Andrew
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

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


Re: Using Struts Validator on Map-backed ActionForms

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
There isn't anything different you need to do from normal validation.

http://struts.apache.org/userGuide/dev_validator.html

The only issue you might hit is if you want to validate according to the
Action Mapping's path, rather than the form name. Then you would need a
custom ActionForm - but thats very straight forward. Just extend either
BeanValidatorForm or LazyValidatorForm and instantiate the LazyDynaMap in
the constructor and fix the validation key (use setPathValidation(true)
method) to use the mapping's path. Something like...

public class MyLazyForm extends LazyValidatorForm() {
    public MyLazyForm() {
        super(new LazyDynaMap());
        setPathValidation(true);
    }
}

Some people don't like using the setPathValidation() because
BeanValidatorForm automatically removes the leading "/" - if thats the case
you can just override getValidationKey() method....

    public String getValidationKey(ActionMapping mapping,
                                   HttpServletRequest request) {
         return mapping.getPath();
    }

Obviously in your struts-config you need to specify this new form....

 <form-bean name="mapForm" type="myPackage.MyLazyForm"/>

Niall

----- Original Message ----- 
From: "Andrew Waite" <an...@gmail.com>
Sent: Saturday, February 12, 2005 10:50 PM

> Thanks for the response. This is looking promising - excellent work, btw.
>
> I have the Action and Struts communicating with this "form".  Do you
> have any example of how to apply the Validaror against it?  Looking
> for some samples but given how new this is it's hard to come by.
>
> Thanks,
> Andrew



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


Re: Using Struts Validator on Map-backed ActionForms

Posted by Andrew Waite <an...@gmail.com>.
Niall,

Thanks for the response. This is looking promising - excellent work, btw. 

I have the Action and Struts communicating with this "form".  Do you
have any example of how to apply the Validaror against it?  Looking
for some samples but given how new this is it's hard to come by.

Thanks,
Andrew


On Sat, 12 Feb 2005 19:32:41 -0000, Niall Pemberton
<ni...@blueyonder.co.uk> wrote:
> You could use a LazyDynaMap to do this (with Struts 1.2.4). LazyDynaMap is a
> "wrapper" for a Map. Because its not an ActionForm Struts will wrap it in a
> BeanValidatorForm, which you can use with Validator.
> 
> Just specify it in the struts-config.xml for your form.
> 
> <form-bean name="mapForm" type="org.apache.commons.beanutils.LazyDynaMap"/>
> 
> In your action you can get the actual Map in the following way...
> 
>     LazyDynaMap dynaMap = ((BeanValidatorForm)form).getInstance();
>     Map myMap = dynaMap.getMap();
> 
> http://jakarta.apache.org/commons/beanutils/apidocs/org/apache/commons/beanutils/package-summary.html#dynamic.lazy
> http://jakarta.apache.org/commons/beanutils/apidocs/org/apache/commons/beanutils/LazyDynaMap.html
> 
> Niall
> 
> ----- Original Message -----
> From: "Andrew Waite" <an...@gmail.com>
> Sent: Saturday, February 12, 2005 3:54 PM
> 
> > I have searched far and wide for an update to this topic but can not
> > seem to find an actual solution.
> >
> > Has anyone accomplished this? I know in one thread Ted Husted
> > mentioned it being possible but had questions about the use case, well
> > if you're listenening here's my use case.
> >
> > I am writing a client to a web-service that returns layout information
> > and field required/data types dynamically. I never know what the
> > schema will be but I do get the metadata in regards to  what the data
> > type is and whether the field is required for form submission.
> >
> > Hope that helps the creative juices out there.
> >
> > Thanks for any help that can be provided.
> >
> > Andrew
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

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


Re: LazyDynaMap

Posted by Vic <vi...@friendvu.com>.
Not in my case:
- I use this outside of Sturts :-P
- iBatis uses ArrayList ... not []

I am sure I can do something based on commons beans code for me, but it 
be nice to have it in the jar.

.V

Niall Pemberton wrote:

>Would specifying an array of LazyDynaMap in the struts-config.xml do what
>you want?
>
>  
>
>>It be nice to have a DynaList. It would be an indexed ArrayList of
>>ListDynaMaps.
>>
>>So from iBatis I can return an ArrayList of Maps as DTO and .... just
>>map it.
>>.V
>>
>>    
>>

-- 
Forums, Boards, Blogs and News in RiA <http://www.boardVU.com>


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


Re: LazyDynaMap

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
Would specifying an array of LazyDynaMap in the struts-config.xml do what
you want?

<form-bean type="org.apache.commons.beanutils.LazyDynaMap">
     <form-property name="xyz"
type="org.apache.commons.beanutils.LazyDynaMap[]"/>
</form-bean>

Niall

----- Original Message ----- 
From: "Vic" <vi...@friendvu.com>
To: <us...@struts.apache.org>
Sent: Sunday, February 13, 2005 12:28 AM
Subject: ot: LazyDynaMap


> This looks very nice! I plan to use it w/ JDNC.
>
> It be nice to have a DynaList. It would be an indexed ArrayList of
> ListDynaMaps.
>
> So from iBatis I can return an ArrayList of Maps as DTO and .... just
> map it.
> .V
>
> Niall Pemberton wrote:
>
> >You could use a LazyDynaMap to do this (with Struts 1.2.4). LazyDynaMap
is a
> >"wrapper" for a Map. Because its not an ActionForm Struts will wrap it in
a
> >BeanValidatorForm, which you can use with Validator.
> >
> >Just specify it in the struts-config.xml for your form.
> >
> ><form-bean name="mapForm"
type="org.apache.commons.beanutils.LazyDynaMap"/>
> >
> >In your action you can get the actual Map in the following way...
> >
> >    LazyDynaMap dynaMap = ((BeanValidatorForm)form).getInstance();
> >    Map myMap = dynaMap.getMap();



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


ot: LazyDynaMap

Posted by Vic <vi...@friendvu.com>.
This looks very nice! I plan to use it w/ JDNC.

It be nice to have a DynaList. It would be an indexed ArrayList of 
ListDynaMaps.

So from iBatis I can return an ArrayList of Maps as DTO and .... just 
map it.
.V

Niall Pemberton wrote:

>You could use a LazyDynaMap to do this (with Struts 1.2.4). LazyDynaMap is a
>"wrapper" for a Map. Because its not an ActionForm Struts will wrap it in a
>BeanValidatorForm, which you can use with Validator.
>
>Just specify it in the struts-config.xml for your form.
>
><form-bean name="mapForm" type="org.apache.commons.beanutils.LazyDynaMap"/>
>
>In your action you can get the actual Map in the following way...
>
>    LazyDynaMap dynaMap = ((BeanValidatorForm)form).getInstance();
>    Map myMap = dynaMap.getMap();
>
>  
>


-- 
Forums, Boards, Blogs and News in RiA <http://www.boardVU.com>


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


Re: Using Struts Validator on Map-backed ActionForms

Posted by Niall Pemberton <ni...@blueyonder.co.uk>.
You could use a LazyDynaMap to do this (with Struts 1.2.4). LazyDynaMap is a
"wrapper" for a Map. Because its not an ActionForm Struts will wrap it in a
BeanValidatorForm, which you can use with Validator.

Just specify it in the struts-config.xml for your form.

<form-bean name="mapForm" type="org.apache.commons.beanutils.LazyDynaMap"/>

In your action you can get the actual Map in the following way...

    LazyDynaMap dynaMap = ((BeanValidatorForm)form).getInstance();
    Map myMap = dynaMap.getMap();

http://jakarta.apache.org/commons/beanutils/apidocs/org/apache/commons/beanutils/package-summary.html#dynamic.lazy
http://jakarta.apache.org/commons/beanutils/apidocs/org/apache/commons/beanutils/LazyDynaMap.html

Niall

----- Original Message ----- 
From: "Andrew Waite" <an...@gmail.com>
Sent: Saturday, February 12, 2005 3:54 PM


> I have searched far and wide for an update to this topic but can not
> seem to find an actual solution.
>
> Has anyone accomplished this? I know in one thread Ted Husted
> mentioned it being possible but had questions about the use case, well
> if you're listenening here's my use case.
>
> I am writing a client to a web-service that returns layout information
> and field required/data types dynamically. I never know what the
> schema will be but I do get the metadata in regards to  what the data
> type is and whether the field is required for form submission.
>
> Hope that helps the creative juices out there.
>
> Thanks for any help that can be provided.
>
> Andrew



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