File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Custom Struts Tag

Phanib Kumar
Greenhorn

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.
(JSP):
request.getAttribute("customObject");


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.

Thanks,
Phani
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
Greenhorn

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

I will try that..
Phanib Kumar
Greenhorn

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

Thanks
Phani
Marc Peabody
pie sneak
Sheriff

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
request.getAttribute("myFormBean");
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Custom Struts Tag