jQuery in Action, 3rd edition
The moose likes Struts and the fly likes Custom Struts Tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Custom Struts Tag" Watch "Custom Struts Tag" New topic

Custom Struts Tag

Phanib Kumar

Joined: Mar 22, 2005
Posts: 3
Hello All!

I have prepared a custom tag library (a tld) to display a datagrid. The input to the datagrid is a custom object. The tag looks like the following:

<prefix atagrid input="<%=customObject%>" />

The customObject is filled in the Action class that forwards the request to this page. Currently I am putting the customObject into HttpServletRequest object in the Action class:

(Action class): request.setAttribute("customObject",customObject);

and retrieving the same in the JSP page.

Now, I want this to be done automatically like any struts object(textbox, check box etc).I want to put the customObject inside the form bean and the TLD should be able to retrieve it based on the property by using the getters and setters of the form bean. Could anyone please enlighten me how to do it.

sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
hi phani

Ofcourse u can do this .u need not place this in the form bean rather set it in the same request as an attribute and pass the attribute name as an attribute to the custom tag

for ex : <print atagrid name="attributeName"/>

and inside the tag use RequestUtils.lookUp to get the stored and object and do what ever u like

hope u got what i am saying ?? and is this what u wanted right??
Phanib Kumar

Joined: Mar 22, 2005
Posts: 3
Thanks for the reply!

I will try that..
Phanib Kumar

Joined: Mar 22, 2005
Posts: 3
Also could you paste some code, if possible?

Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

RequestUtil's lookup() is deprecated.

Fortunately, TagUtils has a similar method that isn't deprecated and you can pass it your pageContext from the tag class.

TagUtils.getInstance().lookup(pageContext, "myFormBean", "request");

or you could do
but where's the fun in that?

Then you'll cast your ActionForm, run a null check, and call any getters you want.

A good workman is known by his tools.
I agree. Here's the link: http://aspose.com/file-tools
subject: Custom Struts Tag
jQuery in Action, 3rd edition