Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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>
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Implement SessionAware.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you i will go through SessionAware Topics.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic