Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Struts Tag

 
Phanib Kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply!

I will try that..
 
Phanib Kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also could you paste some code, if possible?

Thanks
Phani
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic