aspose file tools*
The moose likes Struts and the fly likes Query on struts congfiguration in a 'form' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Query on struts congfiguration in a Watch "Query on struts congfiguration in a New topic
Author

Query on struts congfiguration in a 'form'

Pavan Kumar Dittakavi
Ranch Hand

Joined: Feb 12, 2011
Posts: 104

Hi All,

I am new to struts and I have a query on it. We have Interceptors, Actions classes and view classes in struts applications right. And we make sure that the URL is tied to an action class and an action class is tied to a jsp view page [ of course depends on the output it returns ].

Now, if I have a jsp/html file and I have a form, then I should be mentioning the action class that is going to take up the form processing right? Something like,



Now, we are now configuring the action class in the html/jsp itself instead of the usual struts.xml configuration file. [I am on struts2 by the way.] Is this in any way a bad design..or a violation of MVC? Since view is tied to the action class.

Like I mentioned, I am very new to struts...so please let me know if I did miss anything.

Thanks,
Pavan.
Saif Asif
Ranch Hand

Joined: Aug 11, 2011
Posts: 440

we are now configuring the action class in the html/jsp itself instead of the usual struts.xml configuration file


If by this , you mean to say that you are writing java code inside the JSPs , then yes, it is considered a bad MVC design . Its preferred to write your code in separate action classes. The JSPs should only be used for view purposes with some jsp scriptlets. But putting in whole java code inside the jsp is bad practice.


Muhammad Saif Asif Mirza
OCJA(5/6) OCJP(6) OCJWCD(6)
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8873
    
    8

Pavan Kumar Dittakavi wrote: Now, if I have a jsp/html file and I have a form, then I should be mentioning the action class that is going to take up the form processing right? Something like,


If I understand what you are saying, what you put in the action parameter of the form tag is the name of the action as configured in struts.xml. The name of the action in struts.xml can certainly be the same as the action class name. This may or may not be good design. It depends on other choices you make.
For example, I tend to put CRUD methods for a particular data element in the same action. This means I will have several actions in struts.xml that point to the same class like so:

So the forms that create and edit X data will refer to the name (createX) and not the action class(XAction).


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Pavan Kumar Dittakavi
Ranch Hand

Joined: Feb 12, 2011
Posts: 104

Thank you so much guys. Joe, your explanation clarified my doubt. I thought that the "action" attribute refers to the concrete class itself and so I wondered if that was a good programming practice. But since it can point to the action name, we should be fine even if the underlying class name changes [ for instance..eventhough it might not be likely].

Thanks for your time

-Pavan.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Query on struts congfiguration in a 'form'