Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Struts 2 Action Classes (HELP!)

Paul Saumets | Merge

2007-02-27

Replies:

I'm having some difficulty passing along params from my action forms with Struts 2. I have a basic jsp form declared as follows:

<s:form id="loginForm" action="executeLogin" validate="true" nomespace="/">
<s:textfield id="c_username" name="userName" required="true" />
<s:password id="c_password" name="userPassword" required="true"/>
<s:submit name="login" key="button.login" />
</s:form>

executeLogin is correctly mapped to my LoginAction action class which looks something like the following:

public class LoginAction extends ActionSupport {

       private UserService service;
       private String userName;
       private String userPassword;

       // service injected via Spring

       public LoginAction(UserService service) {
               this.service = service;
       }

       public void setUserName(String userName) {
               this.userName = userName;
       }

       /* remaining setters & getters below */

       public String execute() {

               Boolean ret = service.validateUser(getUserName(), getUserPassword());

               /// more follow up code here
       }
}


My understanding of the Struts 2 framework is that when my action is called the setters on the Action class will be called as well storing my passed along form vars? Am I wrong on this? What exactly am I doing wrong? Should I implementing sessionAware and then having to access the request object?

From reading the Mailreader example I see setters in for username and password in the MailreaderSupport base class so I don't see why the above isn't working.

Would be great to get some feedback!

Regards,
Paul
©2008 junlu.com - Jax Systems, LLC, U.S.A.