You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Paul Saumets | Merge <pa...@merge-solutions.com> on 2007/02/27 18:02:33 UTC

RE: [S2] Struts 2 Action Classes (HELP!)

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 <pa...@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


RE: Struts 2 Action Classes (HELP!)

Posted by cilquirm <aa...@gmail.com>.

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 <pa...@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


RE: Struts session scoped forms

Posted by "Chaudhary, Harsh" <HC...@amfam.com>.
I am setting the struts form I created into session.

I agree that this is all working fine without any problems. But there is
something "icky" about it but I can't put my finger on it.

One reason could be that this is generating a coupling of the struts
form to the java code, something which the struts-config file was meant
to do, I don't know.

Harsh.

-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net] 
Sent: Thursday, March 01, 2007 9:31 AM
To: Struts Users Mailing List
Subject: Re: Struts session scoped forms


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael and Chaudhary,

Michael Jouravlev wrote:
> On 2/28/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
>> I have page1.jsp which has a form which calls Page1Action which
forwards
>> to page2.jsp. Also, session scoped Page1Form and Page2Form.
>>
>> In Page1Action, I do:
>>
>> Page2Form frm = new Page2Form();
>> frm.setSomeVariable("Some Value");
>>
>> Then read this value in page2.jsp to display.

Why not add another <action> mapping in between Page1Action and page2?
Something like this:

page1.jsp -- submit --> Page1Action -- fwd --> PrepPage2 --> page2.jsp

Then, set the "name" for Page1Action to "Page1Form" and the "name" for
PrepPage2 to "Page2Form". Then, you can use the form that gets provided
by Struts directly in your execute method.

>> I feel the bad part is initializing the Page2Form myself. This works
>> correctly because I think Struts checks for the form being available
in
>> all scopes, finds it in session, and just uses that instead of
creating
>> a new one in the Page2Form constructor.

If you call the constructor for Page2Form, you /will/ get a new object.
Struts has nothing to do with this. You must be doing something else in
your action to put this object into session or request scope.

> Why would you create an ActionForm for pure output purposes? You can
> create a POJO or even access properties of your business object.

If page2.jsp contains a form, then it is perfectly natural to use an
ActionForm to shuttle data from the action to the page.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5vHA9CaO5/Lv0PARAk0GAKCoH/CG22PzE7M60O0IDm26PUd1qACgtKYn
FhkoBJ8OQ2oUIwvoikdlciM=
=JWjA
-----END PGP SIGNATURE-----

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

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


Re: [OT] Re: Struts session scoped forms

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
I think there's something to be said though for maintainability when
there's only a single well-known object a developer has to go to to
populate the screen, form data or not.  I personally prefer the ActionForm
be viewed as a VO between the view and control, and I don't figure the
values it passes only has to be user entry.

It's a fair point about more working populating the form from VOs...
either way, not something I'm religious about or anything, just another
perspective.

Frank


-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
 (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!

On Thu, March 1, 2007 11:40 am, Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dave,
>
> Dave Newton wrote:
>> --- Christopher Schultz wrote:
>>> If you have a form that needs to be populated,
>>> submitted, validated and possibly re-displayed, why
>>> not use an ActionForm to populate the form in
>>> the first place?
>>
>> If you're talking about only form data, sure. That's
>> why I explicitly stated I was referring to plain old
>> presentation data.
>
> Oh, okay. Yeah, I never use ActionForms merely for display. Mostly
> because it's not terribly convenient to copy data from a value object
> into an ActionForm just for display.
>
> Thanks for the clarification.
>
> - -chris
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFF5wII9CaO5/Lv0PARAncFAJ9/3V8DSpTVnWozxkgSYFbBYZ5wzACfZ1t6
> QTQl3awL3aBcg8n7N8iG1Y4=
> =3/Fh
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


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


Re: [OT] Re: Struts session scoped forms

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dave,

Dave Newton wrote:
> --- Christopher Schultz wrote:
>> If you have a form that needs to be populated,
>> submitted, validated and possibly re-displayed, why 
>> not use an ActionForm to populate the form in
>> the first place?
> 
> If you're talking about only form data, sure. That's
> why I explicitly stated I was referring to plain old
> presentation data.

Oh, okay. Yeah, I never use ActionForms merely for display. Mostly
because it's not terribly convenient to copy data from a value object
into an ActionForm just for display.

Thanks for the clarification.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5wII9CaO5/Lv0PARAncFAJ9/3V8DSpTVnWozxkgSYFbBYZ5wzACfZ1t6
QTQl3awL3aBcg8n7N8iG1Y4=
=3/Fh
-----END PGP SIGNATURE-----

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


[OT] Re: Struts session scoped forms

Posted by Dave Newton <ne...@yahoo.com>.
--- Christopher Schultz wrote:
> If you have a form that needs to be populated,
> submitted, validated and possibly re-displayed, why 
> not use an ActionForm to populate the form in
> the first place?

If you're talking about only form data, sure. That's
why I explicitly stated I was referring to plain old
presentation data.

d.



 
____________________________________________________________________________________
Food fight? Enjoy some healthy debate 
in the Yahoo! Answers Food & Drink Q&A.
http://answers.yahoo.com/dir/?link=list&sid=396545367

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


Re: Struts session scoped forms

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Dave,

Dave Newton wrote:
> --- Christopher Schultz wrote:
>> If page2.jsp contains a form, then it is perfectly
>> natural to use an ActionForm to shuttle data from
> the
>> action to the page.
> 
> That's actually debatable, and has been in the past.
> 
> Some people prefer to use ActionForms exclusively for
> form data and not Plain Old Presentation Data. I am of
> this camp.

If you have a form that needs to be populated, submitted, validated and
possibly re-displayed, why not use an ActionForm to populate the form in
the first place?

Otherwise, you have crazy code in the form just to pre-populate form
values -- checking both the POJO (or whatever) and the ActionForm.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5vca9CaO5/Lv0PARAqMMAJsETWtv28HaY1ivgKYKGrcgo+zv3gCfS424
nU2G8pwJP+kw3/1jLMaXh1k=
=8LTF
-----END PGP SIGNATURE-----

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


Re: Struts session scoped forms

Posted by Dave Newton <ne...@yahoo.com>.
--- Christopher Schultz wrote:
> If page2.jsp contains a form, then it is perfectly
> natural to use an ActionForm to shuttle data from
the
> action to the page.

That's actually debatable, and has been in the past.

Some people prefer to use ActionForms exclusively for
form data and not Plain Old Presentation Data. I am of
this camp.

d.



 
____________________________________________________________________________________
Want to start your own business?
Learn how on Yahoo! Small Business.
http://smallbusiness.yahoo.com/r-index

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


Re: Struts session scoped forms

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael and Chaudhary,

Michael Jouravlev wrote:
> On 2/28/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
>> I have page1.jsp which has a form which calls Page1Action which forwards
>> to page2.jsp. Also, session scoped Page1Form and Page2Form.
>>
>> In Page1Action, I do:
>>
>> Page2Form frm = new Page2Form();
>> frm.setSomeVariable("Some Value");
>>
>> Then read this value in page2.jsp to display.

Why not add another <action> mapping in between Page1Action and page2?
Something like this:

page1.jsp -- submit --> Page1Action -- fwd --> PrepPage2 --> page2.jsp

Then, set the "name" for Page1Action to "Page1Form" and the "name" for
PrepPage2 to "Page2Form". Then, you can use the form that gets provided
by Struts directly in your execute method.

>> I feel the bad part is initializing the Page2Form myself. This works
>> correctly because I think Struts checks for the form being available in
>> all scopes, finds it in session, and just uses that instead of creating
>> a new one in the Page2Form constructor.

If you call the constructor for Page2Form, you /will/ get a new object.
Struts has nothing to do with this. You must be doing something else in
your action to put this object into session or request scope.

> Why would you create an ActionForm for pure output purposes? You can
> create a POJO or even access properties of your business object.

If page2.jsp contains a form, then it is perfectly natural to use an
ActionForm to shuttle data from the action to the page.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF5vHA9CaO5/Lv0PARAk0GAKCoH/CG22PzE7M60O0IDm26PUd1qACgtKYn
FhkoBJ8OQ2oUIwvoikdlciM=
=JWjA
-----END PGP SIGNATURE-----

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


Re: Struts session scoped forms

Posted by Michael Jouravlev <jm...@gmail.com>.
On 2/28/07, Frank W. Zammetti <fz...@omnytex.com> wrote:
> I'm not sure what your proposing is bad per se... let's ask it this way:
> how else could you accomplish this without manually instantiating the
> form, because I agree, that's the one part that doesn't smell great to
> me either.
>
> One way to do it would be that the forward returned from Page1Action
> specifies not a JSP directly, but instead some "setup" action mapping
> for page2.  It would have the session-scoped form mapping, so Struts
> would create it if necessary, and the action could then do the necessary
> populating that page2.jsp requires.
>
> That's probably a somewhat cleaner approach, but it has the down side of
> invoking the whole request processing cycle again, so there is an
> overhead involved.  Bit of a trade-off.

Right. I forgot that the forms are session-scoped, so form data will
not be lost on redirect. Also, request parameters will be cleared on
redirect, so the second form will not be populated from data of the
first request.

See this page then for some ideas:
http://wiki.apache.org/struts/StrutsManualActionClasses

I prefer to submit HTML forms to the same action that renders a page,
this allows to cleaner separate actions.

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


Re: Struts session scoped forms

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
I'm not sure what your proposing is bad per se... let's ask it this way: 
how else could you accomplish this without manually instantiating the 
form, because I agree, that's the one part that doesn't smell great to 
me either.

One way to do it would be that the forward returned from Page1Action 
specifies not a JSP directly, but instead some "setup" action mapping 
for page2.  It would have the session-scoped form mapping, so Struts 
would create it if necessary, and the action could then do the necessary 
populating that page2.jsp requires.

That's probably a somewhat cleaner approach, but it has the down side of 
invoking the whole request processing cycle again, so there is an 
overhead involved.  Bit of a trade-off.

FYI, just for another opinion, I don't like the idea of using business 
objects directly in the view.  To me, an ActionForm has a very 
well-defined job: it is a DTO between the view and the control layer. 
It should deal with string only, since that's what you get with HTTP, 
type conversions should be handled downstream.  I DO think it should be 
used for both input and output.  I realize this leads to more code, more 
classes, but I think the original point of ActionForm was a good 
decision, to me it doesn't feel right that so many people are in favor 
of moving away from that (I'm not even sure I like the combined 
Action/ActionForm you get in S2... I'm still mulling that one over in my 
warped little mind).  It's just my opinion though.

Frank

Chaudhary, Harsh wrote:
> I am not doing things this way. I presented this as a hypothetical case
> and my question is why is this bad? I mean what problems can we run into
> using this technique.
> 
> Thanks for the write up but I would appreciate something that in more in
> detail.
> 
> Thanks,
> Harsh.
> 
> -----Original Message-----
> From: Michael Jouravlev [mailto:jmikus@gmail.com] 
> Sent: Wednesday, February 28, 2007 3:32 PM
> To: Struts Users Mailing List
> Subject: Re: Struts session scoped forms
> 
> 
> On 2/28/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
>> I have page1.jsp which has a form which calls Page1Action which
> forwards
>> to page2.jsp. Also, session scoped Page1Form and Page2Form.
>>
>> In Page1Action, I do:
>>
>> Page2Form frm = new Page2Form();
>> frm.setSomeVariable("Some Value");
>>
>> Then read this value in page2.jsp to display.
>>
>> I feel the bad part is initializing the Page2Form myself. This works
>> correctly because I think Struts checks for the form being available
> in
>> all scopes, finds it in session, and just uses that instead of
> creating
>> a new one in the Page2Form constructor.
>>
>> Is this way of doing things correct? If not why? Or am I zoned out too
>> much to make sense?
> 
> This is okay. Not great to my taste, but okay. You should use the same
> key as "name" attribute in the action mapping. I would recommend you
> another pattern, but I will not going to share my way of doing this
> until a new version of Struts1 that would allow to turn off automatic
> reset/populate of a form is released.
> 
> Why would you create an ActionForm for pure output purposes? You can
> create a POJO or even access properties of your business object.
> 
> On a side note, in Struts actions precede pages. An action receives a
> request and then displays a page. In your case, it obtains information
> from page1, but it renders page2. Even this is not true. An action
> does not obtain information from a page, it just receives a request
> and it does not care where the request comes from. So talking in terms
> "page1.jsp calls Page1Action" is not entirely correct to me. Therefore
> I would name your action as Page2Action, not Page1Action, that would
> be clearer for me.
> 
> Michael.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
  (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
  Supplying the wheel, so you don't have to reinvent it!

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


RE: Struts session scoped forms

Posted by "Chaudhary, Harsh" <HC...@amfam.com>.
I am not doing things this way. I presented this as a hypothetical case
and my question is why is this bad? I mean what problems can we run into
using this technique.

Thanks for the write up but I would appreciate something that in more in
detail.

Thanks,
Harsh.

-----Original Message-----
From: Michael Jouravlev [mailto:jmikus@gmail.com] 
Sent: Wednesday, February 28, 2007 3:32 PM
To: Struts Users Mailing List
Subject: Re: Struts session scoped forms


On 2/28/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
> I have page1.jsp which has a form which calls Page1Action which
forwards
> to page2.jsp. Also, session scoped Page1Form and Page2Form.
>
> In Page1Action, I do:
>
> Page2Form frm = new Page2Form();
> frm.setSomeVariable("Some Value");
>
> Then read this value in page2.jsp to display.
>
> I feel the bad part is initializing the Page2Form myself. This works
> correctly because I think Struts checks for the form being available
in
> all scopes, finds it in session, and just uses that instead of
creating
> a new one in the Page2Form constructor.
>
> Is this way of doing things correct? If not why? Or am I zoned out too
> much to make sense?

This is okay. Not great to my taste, but okay. You should use the same
key as "name" attribute in the action mapping. I would recommend you
another pattern, but I will not going to share my way of doing this
until a new version of Struts1 that would allow to turn off automatic
reset/populate of a form is released.

Why would you create an ActionForm for pure output purposes? You can
create a POJO or even access properties of your business object.

On a side note, in Struts actions precede pages. An action receives a
request and then displays a page. In your case, it obtains information
from page1, but it renders page2. Even this is not true. An action
does not obtain information from a page, it just receives a request
and it does not care where the request comes from. So talking in terms
"page1.jsp calls Page1Action" is not entirely correct to me. Therefore
I would name your action as Page2Action, not Page1Action, that would
be clearer for me.

Michael.

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

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


Re: Struts session scoped forms

Posted by Michael Jouravlev <jm...@gmail.com>.
On 2/28/07, Chaudhary, Harsh <HC...@amfam.com> wrote:
> I have page1.jsp which has a form which calls Page1Action which forwards
> to page2.jsp. Also, session scoped Page1Form and Page2Form.
>
> In Page1Action, I do:
>
> Page2Form frm = new Page2Form();
> frm.setSomeVariable("Some Value");
>
> Then read this value in page2.jsp to display.
>
> I feel the bad part is initializing the Page2Form myself. This works
> correctly because I think Struts checks for the form being available in
> all scopes, finds it in session, and just uses that instead of creating
> a new one in the Page2Form constructor.
>
> Is this way of doing things correct? If not why? Or am I zoned out too
> much to make sense?

This is okay. Not great to my taste, but okay. You should use the same
key as "name" attribute in the action mapping. I would recommend you
another pattern, but I will not going to share my way of doing this
until a new version of Struts1 that would allow to turn off automatic
reset/populate of a form is released.

Why would you create an ActionForm for pure output purposes? You can
create a POJO or even access properties of your business object.

On a side note, in Struts actions precede pages. An action receives a
request and then displays a page. In your case, it obtains information
from page1, but it renders page2. Even this is not true. An action
does not obtain information from a page, it just receives a request
and it does not care where the request comes from. So talking in terms
"page1.jsp calls Page1Action" is not entirely correct to me. Therefore
I would name your action as Page2Action, not Page1Action, that would
be clearer for me.

Michael.

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


Struts session scoped forms

Posted by "Chaudhary, Harsh" <HC...@amfam.com>.
I have page1.jsp which has a form which calls Page1Action which forwards
to page2.jsp. Also, session scoped Page1Form and Page2Form.

In Page1Action, I do:

Page2Form frm = new Page2Form();
frm.setSomeVariable("Some Value");

Then read this value in page2.jsp to display.

I feel the bad part is initializing the Page2Form myself. This works
correctly because I think Struts checks for the form being available in
all scopes, finds it in session, and just uses that instead of creating
a new one in the Page2Form constructor.

Is this way of doing things correct? If not why? Or am I zoned out too
much to make sense?

Rehards,
Harsh.

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


Re: Scriptlets in Struts tag

Posted by Laurie Harper <la...@holoweb.net>.
Yup, that's the way the spec says it should work :-) An attribute can be 
*either* a static String *or* a Runtime Expression. You can't mix both, 
so you have to make the any static text part of the RT as you showed.

L.

Frank W. Zammetti wrote:
> I don't think so... if that was true you'd expect it to work as you first
> wrote it... it seems to be the specific combination of static content in
> the attribute value PLUS a scriplet (actually, I guess that's an
> expression, I always forget the difference).  In any case, glad that
> worked :)  I know I burned almost an hour the other day until I took a
> wild guess and happened to be right.
> 
> Frank
> 
> 


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


RE: Scriptlets in Struts tag

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
I don't think so... if that was true you'd expect it to work as you first
wrote it... it seems to be the specific combination of static content in
the attribute value PLUS a scriplet (actually, I guess that's an
expression, I always forget the difference).  In any case, glad that
worked :)  I know I burned almost an hour the other day until I took a
wild guess and happened to be right.

Frank


-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
 (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!

On Tue, February 27, 2007 2:16 pm, Chaudhary, Harsh wrote:
> Works like a charm. Thanks a lot.
>
> My guess is that my problem could be due to the fact that anything
> within attributes like styleid etc. are just parsed as a string.
>
> Harsh.
>
> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
> Sent: Tuesday, February 27, 2007 12:50 PM
> To: Struts Users Mailing List
> Cc: Struts Users Mailing List
> Subject: RE: Scriptlets in Struts tag
>
>
> I believe your running into something I ran into the other day,
> something
> I didn't know... if you have an attribute:
>
> someAttribute="123<%=someVar%>"
>
> ...the value of someVar isn't inserted.  However, if you do:
>
> <% someVar = "123" + someVar %>
> someAttribute="<%=someVar%>"
>
> ...that works.  The combination of static text and a scriplet seems to
> not
> work.  Give it a shot, see if that does the trick for you...
>
> Frank
>
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM/Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Author of "Practical Ajax Projects With Java Technology"
>  (2006, Apress, ISBN 1-59059-695-1)
> Java Web Parts - http://javawebparts.sourceforge.net
>  Supplying the wheel, so you don't have to reinvent it!
>
> On Tue, February 27, 2007 1:40 pm, Chaudhary, Harsh wrote:
>> I tried that. But in the HTML rendered, the id attribute is rendered
> as:
>>
>> id='BLABLA<%=indexVal.intValue()%>'
>>
>> Harsh.
>>
>> -----Original Message-----
>> From: Nuwan Chandrasoma [mailto:mymailnot@gmail.com]
>> Sent: Tuesday, February 27, 2007 6:09 PM
>> To: Struts Users Mailing List
>> Subject: Re: Scriptlets in Struts tag
>>
>>
>> hi,
>>
>> try this code.
>>
>> <%=indexVal.intValue()%>
>>
>> Regards,
>>
>> Nuwan.
>>
>> ----- Original Message -----
>> From: "Chaudhary, Harsh" <HC...@amfam.com>
>> To: "Struts Users Mailing List" <us...@struts.apache.org>
>> Sent: Tuesday, February 27, 2007 6:22 PM
>> Subject: Scriptlets in Struts tag
>>
>>
>> My code:
>>
>> <logic:iterate name="FDA3Form" property="dependentsInfoAl"
> id="element"
>> indexId="indexVal">
>> <html:text name="element" property="dependentName" size="20"
>> maxlength="35" indexed="true" style="display:block;"
>> styleId='BLABLABLA----->>><%= indexVal %><<<-----'/>
>> </logic:iterate>
>>
>> The code within the ----->>> and <<<----- is not working. I think it
>> might be due to the way the tag is parsed in the JSP but does anyone
>> know of a way to do this.
>>
>> Basically, I would like to have id='BLA1', id='BLA2' ...... in the
>> rendered HTML.
>>
>> Harsh.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


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


RE: Scriptlets in Struts tag

Posted by "Chaudhary, Harsh" <HC...@amfam.com>.
Works like a charm. Thanks a lot.

My guess is that my problem could be due to the fact that anything
within attributes like styleid etc. are just parsed as a string.

Harsh.

-----Original Message-----
From: Frank W. Zammetti [mailto:fzlists@omnytex.com] 
Sent: Tuesday, February 27, 2007 12:50 PM
To: Struts Users Mailing List
Cc: Struts Users Mailing List
Subject: RE: Scriptlets in Struts tag


I believe your running into something I ran into the other day,
something
I didn't know... if you have an attribute:

someAttribute="123<%=someVar%>"

...the value of someVar isn't inserted.  However, if you do:

<% someVar = "123" + someVar %>
someAttribute="<%=someVar%>"

...that works.  The combination of static text and a scriplet seems to
not
work.  Give it a shot, see if that does the trick for you...

Frank


-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
 (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!

On Tue, February 27, 2007 1:40 pm, Chaudhary, Harsh wrote:
> I tried that. But in the HTML rendered, the id attribute is rendered
as:
>
> id='BLABLA<%=indexVal.intValue()%>'
>
> Harsh.
>
> -----Original Message-----
> From: Nuwan Chandrasoma [mailto:mymailnot@gmail.com]
> Sent: Tuesday, February 27, 2007 6:09 PM
> To: Struts Users Mailing List
> Subject: Re: Scriptlets in Struts tag
>
>
> hi,
>
> try this code.
>
> <%=indexVal.intValue()%>
>
> Regards,
>
> Nuwan.
>
> ----- Original Message -----
> From: "Chaudhary, Harsh" <HC...@amfam.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Tuesday, February 27, 2007 6:22 PM
> Subject: Scriptlets in Struts tag
>
>
> My code:
>
> <logic:iterate name="FDA3Form" property="dependentsInfoAl"
id="element"
> indexId="indexVal">
> <html:text name="element" property="dependentName" size="20"
> maxlength="35" indexed="true" style="display:block;"
> styleId='BLABLABLA----->>><%= indexVal %><<<-----'/>
> </logic:iterate>
>
> The code within the ----->>> and <<<----- is not working. I think it
> might be due to the way the tag is parsed in the JSP but does anyone
> know of a way to do this.
>
> Basically, I would like to have id='BLA1', id='BLA2' ...... in the
> rendered HTML.
>
> Harsh.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


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

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


RE: Scriptlets in Struts tag

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
I believe your running into something I ran into the other day, something
I didn't know... if you have an attribute:

someAttribute="123<%=someVar%>"

...the value of someVar isn't inserted.  However, if you do:

<% someVar = "123" + someVar %>
someAttribute="<%=someVar%>"

...that works.  The combination of static text and a scriplet seems to not
work.  Give it a shot, see if that does the trick for you...

Frank


-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM/Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Author of "Practical Ajax Projects With Java Technology"
 (2006, Apress, ISBN 1-59059-695-1)
Java Web Parts - http://javawebparts.sourceforge.net
 Supplying the wheel, so you don't have to reinvent it!

On Tue, February 27, 2007 1:40 pm, Chaudhary, Harsh wrote:
> I tried that. But in the HTML rendered, the id attribute is rendered as:
>
> id='BLABLA<%=indexVal.intValue()%>'
>
> Harsh.
>
> -----Original Message-----
> From: Nuwan Chandrasoma [mailto:mymailnot@gmail.com]
> Sent: Tuesday, February 27, 2007 6:09 PM
> To: Struts Users Mailing List
> Subject: Re: Scriptlets in Struts tag
>
>
> hi,
>
> try this code.
>
> <%=indexVal.intValue()%>
>
> Regards,
>
> Nuwan.
>
> ----- Original Message -----
> From: "Chaudhary, Harsh" <HC...@amfam.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Tuesday, February 27, 2007 6:22 PM
> Subject: Scriptlets in Struts tag
>
>
> My code:
>
> <logic:iterate name="FDA3Form" property="dependentsInfoAl" id="element"
> indexId="indexVal">
> <html:text name="element" property="dependentName" size="20"
> maxlength="35" indexed="true" style="display:block;"
> styleId='BLABLABLA----->>><%= indexVal %><<<-----'/>
> </logic:iterate>
>
> The code within the ----->>> and <<<----- is not working. I think it
> might be due to the way the tag is parsed in the JSP but does anyone
> know of a way to do this.
>
> Basically, I would like to have id='BLA1', id='BLA2' ...... in the
> rendered HTML.
>
> Harsh.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


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


RE: Scriptlets in Struts tag

Posted by "Chaudhary, Harsh" <HC...@amfam.com>.
I tried that. But in the HTML rendered, the id attribute is rendered as:

id='BLABLA<%=indexVal.intValue()%>'

Harsh.

-----Original Message-----
From: Nuwan Chandrasoma [mailto:mymailnot@gmail.com] 
Sent: Tuesday, February 27, 2007 6:09 PM
To: Struts Users Mailing List
Subject: Re: Scriptlets in Struts tag


hi,

try this code.

<%=indexVal.intValue()%>

Regards,

Nuwan.

----- Original Message ----- 
From: "Chaudhary, Harsh" <HC...@amfam.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, February 27, 2007 6:22 PM
Subject: Scriptlets in Struts tag


My code:

<logic:iterate name="FDA3Form" property="dependentsInfoAl" id="element"
indexId="indexVal"> 
<html:text name="element" property="dependentName" size="20"
maxlength="35" indexed="true" style="display:block;"
styleId='BLABLABLA----->>><%= indexVal %><<<-----'/>
</logic:iterate> 

The code within the ----->>> and <<<----- is not working. I think it
might be due to the way the tag is parsed in the JSP but does anyone
know of a way to do this.

Basically, I would like to have id='BLA1', id='BLA2' ...... in the
rendered HTML.

Harsh.

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


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

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


Re: Scriptlets in Struts tag

Posted by Nuwan Chandrasoma <my...@gmail.com>.
hi,

try this code.

<%=indexVal.intValue()%>

Regards,

Nuwan.

----- Original Message ----- 
From: "Chaudhary, Harsh" <HC...@amfam.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Tuesday, February 27, 2007 6:22 PM
Subject: Scriptlets in Struts tag


My code:

<logic:iterate name="FDA3Form" property="dependentsInfoAl" id="element"
indexId="indexVal"> 
<html:text name="element" property="dependentName" size="20"
maxlength="35" indexed="true" style="display:block;"
styleId='BLABLABLA----->>><%= indexVal %><<<-----'/>
</logic:iterate> 

The code within the ----->>> and <<<----- is not working. I think it
might be due to the way the tag is parsed in the JSP but does anyone
know of a way to do this.

Basically, I would like to have id='BLA1', id='BLA2' ...... in the
rendered HTML.

Harsh.

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


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


Scriptlets in Struts tag

Posted by "Chaudhary, Harsh" <HC...@amfam.com>.
My code:

<logic:iterate name="FDA3Form" property="dependentsInfoAl" id="element"
indexId="indexVal">	
<html:text name="element" property="dependentName" size="20"
maxlength="35" indexed="true" style="display:block;"
styleId='BLABLABLA----->>><%= indexVal %><<<-----'/>
</logic:iterate>	

The code within the ----->>> and <<<----- is not working. I think it
might be due to the way the tag is parsed in the JSP but does anyone
know of a way to do this.

Basically, I would like to have id='BLA1', id='BLA2' ...... in the
rendered HTML.

Harsh.

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