This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Struts and the fly likes how to pass attribute from tag > action ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to pass attribute from tag > action ?" Watch "how to pass attribute from tag > action ?" New topic
Author

how to pass attribute from tag > action ?

John Summers
Ranch Hand

Joined: Oct 06, 2003
Posts: 125
Hi,
I am designing a custom tag. In the doStartTag method i set an attribute:
pageContext.setAttribute ("myCollection", collection, PageContext.SCOPE_SESSION);
This tag is used on a particular jsp page. Now, once the page is rendered (this works ok) there is a form on the page. When the form is submitted my Action class is called ok, but in the execute method it cannot get the attribute by doing:
Collection c = req.getSession().getAttribute("myCollection");
NB: Maybe a few typos here...
Why can't it access the session attribute? Is there a way I can get this to happen?:
1) jsp page loads, custom tag handler is called and creates a session attribute
2) jsp page submits a form, the Action defined by the ActionMappings can access this attribute.
thanks
john
Reid M. Pinchback
Ranch Hand

Joined: Jan 25, 2002
Posts: 775
Create a logging statement in the tag and in the execute method. Print out the session ids in both cases. If the id is different, that is the source of the problem. If the ids are different it'll be because the client browser has never been given a chance to accept the newly-created session. This was an issue at one point in Tomcat, doesn't seem to be a factor in recent releases. Don't know about other web containers.


Reid - SCJP2 (April 2002)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to pass attribute from tag > action ?
 
Similar Threads
Newbie question: dereference objects
How can we set a Collection object as attribute to be used by a custom tag?
Why is struts calling reset???
Can i use java class in action attribute in form tag of jsp page?
Multi List Box Problem in Struts 1.1