struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cilquirm <aadi.deshpa...@gmail.com>
Subject RE: Struts 2 Action Classes (HELP!)
Date Tue, 27 Feb 2007 18:26:48 GMT


That example is using the null property handling feature of the XW
type-conversion system :

http://struts.apache.org/2.x/docs/type-conversion.html

Basically, when xw/ognl  sees ( evaluates )  person.firstName, it calls
getPerson() , which returns null.
XW goes to work and creates an empty Person object and places it on that
action.
and then sets firstname on that newly created person object.

(n.b. the exact ordering may be slightly off, it might set first name first
before setting person object, but the end result is the same, in this case )

I'm not sure how your spring configuration is set up, but that would be
helpful  to see.
Myself, I don't use the constructor injection mechanism, i use
autowire-by-type, so my Action doesn't have a specifically declared
constructor, just a 

setUserService(UserService us) { this.userService = us }

-a


Paul Saumets | Merge wrote:
> 
> Could we explain this good example then?
> 
> http://cwiki.apache.org/S2WIKI/struts-2-spring-2-jpa-ajax.html
> 
> Here we can see there is a form (index.jsp) calling the save() action on
> the PersonAction class.
> 
> The first call on the save action is the service.save(person).
> 
> Where does the Person person object inside PersonAction get set?
> Somehow the Person setters are being called and I'm not understanding how
> those setters are automatically called yet my LoginAction setters where
> userName and userPassword are passed from the form are not?!
> 
> Could anyone explain please? ;)
> 
> -----Original Message-----
> From: Gabe Hamilton [mailto:gabehamilton@gmail.com]
> Sent: Tuesday, February 27, 2007 11:44 AM
> To: Struts Users Mailing List
> Subject: Re: Struts 2 Action Classes (HELP!)
> 
> I believe the Parameters Interceptor will call your setUserName() method. 
> I
> would check that that interceptor is in the stack used for LoginAction.
> 
> -Gabe
> 
> On 2/27/07, Paul Saumets | Merge <paul.saumets@merge-solutions.com> wrote:
>>
>> 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
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Struts-2-Action-Classes-%28HELP%21%29-tf3301377.html#a9188636
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message