Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Validation with Model-Aware design.

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there,

We are building a system on struts 2.0.9 with model aware design but we cant figure how to setup the validation, I have blundered in struts wiki for quite some time now and even on xwork code but I havent figured it.

Anyone have any idea or can point were to look for such information?

Thank in advance,
Notivago.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is "model aware design" and how does it impact your use of validation. You mention the phrase in your subject line and message so it seems like it is important. I tried Google and did not find much (this page was the first hit).

- Brent
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Model-Aware is a Struts 2 specific term. Normally in Struts 2, the struts 1 concepts of an ActionForm and an Action are unified -- since you get a new Struts 2 action on every request you can have the instance variables, etc.

However, this still means you often end up doubling your get/setters once on the model object and once on the action. With the action simply proxing through. (ie the framework calls all the setters on the action, and then in your action you call someObject.setProperty(getProperty()) ).

This is seen as annoying/unclean.

Model-Driven/Model Aware refers to using your model object as a Struts 1 action form, effectively. So the get/setters do not exist on the action.

Now I haven't used model driven yet, mainly because until I get HDIV hooked up also , I don't like some of the security implications. However, to make validations work my impression is that
1) Move your validation from your action's setters to your model's setters
2) Set up a Visitor validator on the model object in the action
 
Leonardo Postacchini
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again,
Thanks for the reply, after reading Erich's reply I went about trying to configure the visitor to validate the model, but I was not able to do so.

I created an <Model Class Name>-validation.xml file next to the model class, with the validation for the model, in the action validation file I created a configuration for the model, I tried to use the field-name as the class name, as "model"(since the action property for the model is surprisingly model).

I tried to configure it without using prefix, using prefix as model. In none of my attempts the validation fired for the model properties. I was unable to find proper documentation on the usage of the visitor field, being the only one: http://struts.apache.org/2.x/docs/visitor-validator.html

But the documentation is lacking, for example it does not tell me if I have to have one visitor to each field or just one visitor to each model object regardless of the number of fields that must be validated against.

Anyone has pointers to were look for more info? Like books or a sample aplication that actually use visitor?

Thanks,
Notivago.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic