File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to pass attribute from tag > action ?" Watch "how to pass attribute from tag > action ?" New topic

how to pass attribute from tag > action ?

John Summers
Ranch Hand

Joined: Oct 06, 2003
Posts: 125
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.
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:
subject: how to pass attribute from tag > action ?
It's not a secret anymore!