• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Custom Struts Tag

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply!

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

Thanks
Phani
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic