Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Struts2 -- A Query with setters and getters in the Action class. 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 "Struts2 -- A Query with setters and getters in the Action class." Watch "Struts2 -- A Query with setters and getters in the Action class." New topic
Author

Struts2 -- A Query with setters and getters in the Action class.

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234


Hi

I have something like this in my JSP Page of Struts2 based application .

<s:property value="testing" />

Is it necessary for me to have Setters and Getters for this property testing in the Action class .

I mean why can't it be like this :



(The username is passed from the UI to the Action class )
<h1><s:property value="testing" /></h1>

Save India From Corruption - Anna Hazare.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Because it won't work.

You *may* use a public property, but it's best to follow standard Java coding practices and provide accessors. This also helps "future-proof" your class in case at some point the property needs further processing.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thanks David .

Can you please clarify my below new query here :

If my requirement is to transfer the username property (the data submitted by the user ) to an sessionBean .


(I am not asking about the @EJB or jndi lookups inside Action class , my question is with respect to DTO as in struts2 there are no ActionForms )

How can i do this ?

Please tell me this
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Implement SessionAware.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thank you i will go through SessionAware Topics.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 -- A Query with setters and getters in the Action class.