• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Query on struts congfiguration in a 'form'

 
Ranch Hand
Posts: 112
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 440
Hibernate Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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).
 
Pavan Kumar Dittakavi
Ranch Hand
Posts: 112
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic