aspose file tools*
The moose likes Struts and the fly likes Validation with Model-Aware design. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation with Model-Aware design." Watch "Validation with Model-Aware design." New topic
Author

Validation with Model-Aware design.

Leonardo Postacchini
Greenhorn

Joined: Mar 30, 2004
Posts: 6
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.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
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
Eric Nielsen
Ranch Hand

Joined: Dec 14, 2004
Posts: 194
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

Joined: Mar 30, 2004
Posts: 6
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.
 
jQuery in Action, 2nd edition
 
subject: Validation with Model-Aware design.