You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Umesh Awasthi <um...@gmail.com> on 2013/10/15 11:38:52 UTC

Strange issue with Model driven and Bean validation

Hi All,

I am facing a strange issue while trying to validate a bean using bean
validation.I am using model driven interface to pass form field values to
Action and here is the  action code

public class ModelDriven extends ActionSupport implements
com.opensymphony.xwork2.ModelDriven<ProfileDTO>{


 @Valid
    public ProfileDTOgetModel()
    {
         return new ProfileDTO();
    }
}

Though bean validator is validating fields but skipping few of them an di
am clueless why it is dong this, when i am using simple process without
Model driven every validation is working as expected.

There is no difference in code and only line of code different is in action
for model driven.

Not sure how relevant question is , but do we need to take care any
specific issue while using model driven approach?

-- 
With Regards
Umesh Awasthi
http://www.travellingrants.com/

Re: Strange issue with Model driven and Bean validation

Posted by Christoph Nenning <Ch...@lex-com.net>.
> Just to add more information by changing code to
> 
> ProfileDTOgetModel md=new ProfileDTOgetModel();
> @Valid
>     public ProfileDTOgetModel()
>     {
>          return md;
>     }
> }
> 
> Bean Validation is working fine, so i am confused which is right way to 
use
> Model driven.
> I took reference from
> 
> http://struts.apache.org/release/2.3.x/docs/model-driven.html
> 
> 


In our applications we do this:


    @Validations(
        visitorFields = {
            @VisitorFieldValidator(fieldName = "model", appendPrefix = 
true)
        }
    )
    public String execute() throws Exception {


Not sure what the differences are.



Regards,
Christoph

This Email was scanned by Sophos Anti Virus

Re: Strange issue with Model driven and Bean validation

Posted by Umesh Awasthi <um...@gmail.com>.
Just to add more information by changing code to

ProfileDTOgetModel md=new ProfileDTOgetModel();
@Valid
    public ProfileDTOgetModel()
    {
         return md;
    }
}

Bean Validation is working fine, so i am confused which is right way to use
Model driven.
I took reference from

http://struts.apache.org/release/2.3.x/docs/model-driven.html


On Tue, Oct 15, 2013 at 3:30 PM, Umesh Awasthi <um...@gmail.com>wrote:

> No, my issue is something different..
> some how underlying Valitor API is not validating all fields and its
> happening only when i am using Model driven, for rest cased everything is
> working fine for same bean object and for same validations.
>
>
> On Tue, Oct 15, 2013 at 3:15 PM, Christoph Nenning <
> Christoph.Nenning@lex-com.net> wrote:
>
>> > Hi All,
>> >
>> > I am facing a strange issue while trying to validate a bean using bean
>> > validation.I am using model driven interface to pass form field values
>> to
>> > Action and here is the  action code
>> >
>> > public class ModelDriven extends ActionSupport implements
>> > com.opensymphony.xwork2.ModelDriven<ProfileDTO>{
>> >
>> >
>> >  @Valid
>> >     public ProfileDTOgetModel()
>> >     {
>> >          return new ProfileDTO();
>> >     }
>> > }
>> >
>> > Though bean validator is validating fields but skipping few of them an
>> di
>> > am clueless why it is dong this, when i am using simple process without
>> > Model driven every validation is working as expected.
>> >
>> > There is no difference in code and only line of code different is in
>> action
>> > for model driven.
>> >
>> > Not sure how relevant question is , but do we need to take care any
>> > specific issue while using model driven approach?
>> >
>>
>> Do you use a custom TextProvider?
>> There is an open Jira issue with ModelDriven, Validation and custom
>> TextProviders:
>>
>> https://issues.apache.org/jira/browse/WW-4202
>>
>>
>> Regards,
>> Christoph
>>
>> This Email was scanned by Sophos Anti Virus
>>
>
>
>
> --
> With Regards
> Umesh Awasthi
> http://www.travellingrants.com/
>
>
>



-- 
With Regards
Umesh Awasthi
http://www.travellingrants.com/

Re: Strange issue with Model driven and Bean validation

Posted by Umesh Awasthi <um...@gmail.com>.
No, my issue is something different..
some how underlying Valitor API is not validating all fields and its
happening only when i am using Model driven, for rest cased everything is
working fine for same bean object and for same validations.


On Tue, Oct 15, 2013 at 3:15 PM, Christoph Nenning <
Christoph.Nenning@lex-com.net> wrote:

> > Hi All,
> >
> > I am facing a strange issue while trying to validate a bean using bean
> > validation.I am using model driven interface to pass form field values
> to
> > Action and here is the  action code
> >
> > public class ModelDriven extends ActionSupport implements
> > com.opensymphony.xwork2.ModelDriven<ProfileDTO>{
> >
> >
> >  @Valid
> >     public ProfileDTOgetModel()
> >     {
> >          return new ProfileDTO();
> >     }
> > }
> >
> > Though bean validator is validating fields but skipping few of them an
> di
> > am clueless why it is dong this, when i am using simple process without
> > Model driven every validation is working as expected.
> >
> > There is no difference in code and only line of code different is in
> action
> > for model driven.
> >
> > Not sure how relevant question is , but do we need to take care any
> > specific issue while using model driven approach?
> >
>
> Do you use a custom TextProvider?
> There is an open Jira issue with ModelDriven, Validation and custom
> TextProviders:
>
> https://issues.apache.org/jira/browse/WW-4202
>
>
> Regards,
> Christoph
>
> This Email was scanned by Sophos Anti Virus
>



-- 
With Regards
Umesh Awasthi
http://www.travellingrants.com/

Antwort: Strange issue with Model driven and Bean validation

Posted by Christoph Nenning <Ch...@lex-com.net>.
> Hi All,
> 
> I am facing a strange issue while trying to validate a bean using bean
> validation.I am using model driven interface to pass form field values 
to
> Action and here is the  action code
> 
> public class ModelDriven extends ActionSupport implements
> com.opensymphony.xwork2.ModelDriven<ProfileDTO>{
> 
> 
>  @Valid
>     public ProfileDTOgetModel()
>     {
>          return new ProfileDTO();
>     }
> }
> 
> Though bean validator is validating fields but skipping few of them an 
di
> am clueless why it is dong this, when i am using simple process without
> Model driven every validation is working as expected.
> 
> There is no difference in code and only line of code different is in 
action
> for model driven.
> 
> Not sure how relevant question is , but do we need to take care any
> specific issue while using model driven approach?
> 

Do you use a custom TextProvider?
There is an open Jira issue with ModelDriven, Validation and custom 
TextProviders:

https://issues.apache.org/jira/browse/WW-4202


Regards,
Christoph

This Email was scanned by Sophos Anti Virus

Re: Strange issue with Model driven and Bean validation

Posted by Umesh Awasthi <um...@gmail.com>.
Dave,

i am agree with you, i just followed doc and than it started giving me some
strange issues in validations.
I tried to debug underlying API but with no success.

On doing some more Googling i came across create new instance outside
getModel() and it started working as expected.

Thanks
Umesh


On Tue, Oct 15, 2013 at 7:01 PM, Dave Newton <da...@gmail.com> wrote:

> Wouldn't this return a new ProfileDTO every single time getModel() is
> called?
>
> This, in turn, would mean that if you were validating model.foo and
> model.bar that it'd be called twice.
>
> I have not verified this, perhaps there's some magic (e.g., spooky) caching
> happening somewhere, but to my mind, without some very clear documentation,
> instantiating the model object in the getter would probably be wrong.
>
> Dave
>
>
>
> On Tue, Oct 15, 2013 at 5:38 AM, Umesh Awasthi <umeshawasthi@gmail.com
> >wrote:
>
> > Hi All,
> >
> > I am facing a strange issue while trying to validate a bean using bean
> > validation.I am using model driven interface to pass form field values to
> > Action and here is the  action code
> >
> > public class ModelDriven extends ActionSupport implements
> > com.opensymphony.xwork2.ModelDriven<ProfileDTO>{
> >
> >
> >  @Valid
> >     public ProfileDTOgetModel()
> >     {
> >          return new ProfileDTO();
> >     }
> > }
> >
> > Though bean validator is validating fields but skipping few of them an di
> > am clueless why it is dong this, when i am using simple process without
> > Model driven every validation is working as expected.
> >
> > There is no difference in code and only line of code different is in
> action
> > for model driven.
> >
> > Not sure how relevant question is , but do we need to take care any
> > specific issue while using model driven approach?
> >
> > --
> > With Regards
> > Umesh Awasthi
> > http://www.travellingrants.com/
> >
>
>
>
> --
> e: davelnewton@gmail.com
> m: 908-380-8699
> s: davelnewton_skype
> t: @dave_newton <https://twitter.com/dave_newton>
> b: Bucky Bits <http://buckybits.blogspot.com/>
> g: davelnewton <https://github.com/davelnewton>
> so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
>



-- 
With Regards
Umesh Awasthi
http://www.travellingrants.com/

Re: Strange issue with Model driven and Bean validation

Posted by Dave Newton <da...@gmail.com>.
Wouldn't this return a new ProfileDTO every single time getModel() is
called?

This, in turn, would mean that if you were validating model.foo and
model.bar that it'd be called twice.

I have not verified this, perhaps there's some magic (e.g., spooky) caching
happening somewhere, but to my mind, without some very clear documentation,
instantiating the model object in the getter would probably be wrong.

Dave



On Tue, Oct 15, 2013 at 5:38 AM, Umesh Awasthi <um...@gmail.com>wrote:

> Hi All,
>
> I am facing a strange issue while trying to validate a bean using bean
> validation.I am using model driven interface to pass form field values to
> Action and here is the  action code
>
> public class ModelDriven extends ActionSupport implements
> com.opensymphony.xwork2.ModelDriven<ProfileDTO>{
>
>
>  @Valid
>     public ProfileDTOgetModel()
>     {
>          return new ProfileDTO();
>     }
> }
>
> Though bean validator is validating fields but skipping few of them an di
> am clueless why it is dong this, when i am using simple process without
> Model driven every validation is working as expected.
>
> There is no difference in code and only line of code different is in action
> for model driven.
>
> Not sure how relevant question is , but do we need to take care any
> specific issue while using model driven approach?
>
> --
> With Regards
> Umesh Awasthi
> http://www.travellingrants.com/
>



-- 
e: davelnewton@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton <https://twitter.com/dave_newton>
b: Bucky Bits <http://buckybits.blogspot.com/>
g: davelnewton <https://github.com/davelnewton>
so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>