File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets 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.
 
jQuery in Action, 2nd edition
 
subject: Struts2 -- A Query with setters and getters in the Action class.
 
Similar Threads
pass value from struts2 form to javascript
annotation struts2 Json
validation in struts2
Handling multiple form data in struts2
Struts2 Helloworld Problem