You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by co...@studiointeractive.com on 2002/02/10 16:11:29 UTC

Setting a Bean in an Action and Getting it on a Page


Can someone help me with this?

1.  In an Action, I populate the value of a Bean.
2. Then, in the Action, I put the Bean in the session like this:

      session.setAttribute("theUserList",userList);

3.  On a JSP page, when I use tags to try to get at the Bean, however, I
think
     I am only creating new Beans. I am having some success because
     my log4j statements show that I get into the Bean on the JSP page,
     but I never get the value set by the Action, so I must be only
creating
     a new Bean everytime.

So I guess the question is,

what is the synax for accessing a bean which should already be in the
session.  I have been using something akin to the following without
success:

<jsp:useBean id="theUserList" scope="request" class
="com.magneta.model.UserList"/>
<jsp:getProperty name="theUserList" property="testString"/>


Thanks,

Cody


----------------------------------------------------------------
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material.  Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipient is prohibited.   If you received
this in error, please contact the sender and delete the material from any
computer.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Setting a Bean in an Action and Getting it on a Page

Posted by Gloria Williams <rj...@compuserve.com>.
You are putting the bean in the session context (session.setAttribute...)
and looking for it in the request context (jsp:bean...scope="request"...).
Be consistent.

bob
----- Original Message -----
From: <co...@studiointeractive.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Sunday, February 10, 2002 9:11 AM
Subject: Setting a Bean in an Action and Getting it on a Page


>
>
>
> Can someone help me with this?
>
> 1.  In an Action, I populate the value of a Bean.
> 2. Then, in the Action, I put the Bean in the session like this:
>
>       session.setAttribute("theUserList",userList);
>
> 3.  On a JSP page, when I use tags to try to get at the Bean, however, I
> think
>      I am only creating new Beans. I am having some success because
>      my log4j statements show that I get into the Bean on the JSP page,
>      but I never get the value set by the Action, so I must be only
> creating
>      a new Bean everytime.
>
> So I guess the question is,
>
> what is the synax for accessing a bean which should already be in the
> session.  I have been using something akin to the following without
> success:
>
> <jsp:useBean id="theUserList" scope="request" class
> ="com.magneta.model.UserList"/>
> <jsp:getProperty name="theUserList" property="testString"/>
>
>
> Thanks,
>
> Cody
>
>
> ----------------------------------------------------------------
> The information transmitted is intended only for the person or entity to
> which it is addressed and may contain confidential and/or privileged
> material.  Any review, retransmission, dissemination or other use of, or
> taking of any action in reliance upon, this information by persons or
> entities other than the intended recipient is prohibited.   If you
received
> this in error, please contact the sender and delete the material from any
> computer.
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Setting a Bean in an Action and Getting it on a Page

Posted by Ted Husted <hu...@apache.org>.
You might find the Struts bean tags easier to use that the standard JSP
actions, since there is not as much red tape involved. 

For example, to simply write your test string 

<bean:write name="theUserList" property="testString"/>

is all that is needed. The tag will figure out the rest =:o)

http://jakarta.apache.org/struts/struts-bean.html

http://jakarta.apache.org/struts/api-1.0/org/apache/struts/taglib/bean/package-summary.html#package_description

If you need to expose testString as scripting variable, see the
bean:define tag.

-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Java Web Development with Struts.
-- Tel +1 585 737-3463.
-- Web http://www.husted.com/struts/



cody.burleson@studiointeractive.com wrote:
> 
> Can someone help me with this?
> 
> 1.  In an Action, I populate the value of a Bean.
> 2. Then, in the Action, I put the Bean in the session like this:
> 
>       session.setAttribute("theUserList",userList);
> 
> 3.  On a JSP page, when I use tags to try to get at the Bean, however, I
> think
>      I am only creating new Beans. I am having some success because
>      my log4j statements show that I get into the Bean on the JSP page,
>      but I never get the value set by the Action, so I must be only
> creating
>      a new Bean everytime.
> 
> So I guess the question is,
> 
> what is the synax for accessing a bean which should already be in the
> session.  I have been using something akin to the following without
> success:
> 
> <jsp:useBean id="theUserList" scope="request" class
> ="com.magneta.model.UserList"/>
> <jsp:getProperty name="theUserList" property="testString"/>
> 
> Thanks,
> 
> Cody
> 
> ----------------------------------------------------------------
> The information transmitted is intended only for the person or entity to
> which it is addressed and may contain confidential and/or privileged
> material.  Any review, retransmission, dissemination or other use of, or
> taking of any action in reliance upon, this information by persons or
> entities other than the intended recipient is prohibited.   If you received
> this in error, please contact the sender and delete the material from any
> computer.
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>