Tag library and java beans
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   dibakar_ray
Posted On:   Thursday, January 1, 2004 03:12 AM

I am in the process of designing an application. In the application I am planning to use a bean to store some key value pairs. For example Name ->character Address-> character, age ->integer etc. I need to render them at run time.In order to render them properly I need all the Key value pairs, so that I can format them properly. I thought of using some custom tags to render the content of the bean. But as I was going through the tag library tutorial, I found that attributes passed to the tag library can only be of type string. Moreover as I dont know the number of key value pairs in advance and they can be quite a few, passing them as an attribute will be difficult. So my question is-    More>>

I am in the process of designing an application.


In the application I am planning to use a bean to store
some key value pairs. For example Name ->character
Address-> character, age ->integer etc. I need to render them at run time.In order to render them properly I need all the Key value pairs, so that I can format them properly.
I thought of using some custom tags to render the content of the bean.
But as I was going through the tag library tutorial, I found that attributes passed to the tag library can only be of type string.
Moreover as I dont know the number of key value pairs in advance and they can be quite a few, passing them as an attribute will be difficult.
So my question is-


How to pass a set of Key value pair to custom tag libray in JSP.


Thanks
Dibakar

   <<Less

Re: Tag library and java beans

Posted By:   Anin_Mathen  
Posted On:   Friday, January 2, 2004 09:19 AM

Dibakar,

Here is a rough solution for you... but you can readup on the TagExtraInfo class and the tag library documents to get better insight.

Designate an object name that you will use for passing values to and from your tag library and assign the name to the id just like we do it with the useBean tag.





Then Create a TagExtraInfo class(dont forget to register it in your tld) which will either create a new instance of that object 'myCustomObject' by setting the third parameter as true. Or if you already have the object existing in the scope you set it to false.

This object now is available for use within your tag methods


public class MenuTagExtraInfo extends TagExtraInfo {

public VariableInfo[] getVariableInfo(TagData tagdata) {
return (
new VariableInfo[] {
new VariableInfo(
tagdata.getId(),
"com.x.webui.MenuRenderer",
true,
VariableInfo.NESTED)});
}
}


Hope this helps. Let me know if you need more info.

Thanks,
Anin
About | Sitemap | Contact