wood burning stoves 2.0*
The moose likes Struts and the fly likes Reder controls dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Reder controls dynamically" Watch "Reder controls dynamically" New topic
Author

Reder controls dynamically

Anirudha Joshi
Greenhorn

Joined: Apr 08, 2005
Posts: 22
Hello,

We have a requirement where input controls of the screens are customizable. For each screen label, there is a entry in the database which decides what type of control(input box, radio, textarea, listbox etc.) would be displayed for the label. To avoid writing if else blocks in the JSP and to reuse the code, I have created a java bean method which returns HTML code based on the display type passed. Something like this

public String getControl(string displayType,String id)
{
if(displayType.equals("TEXT"))
return "<html:text property=id>";
else if(displayType.equals("TEXTAREA"))
return "<html:textarea property=id>";
and so on.......
}

in the jsp......I do
out.println(bean.getControl(displayType,id));

Issue is HTML code returned by bean is treated as normal string and struts HTML tags are not executed by the server. When the page is displayed, it does not show any input controls....if I do "View Source" I can see <html:text property=id> is a part of HTML.

How do I force JSP engine to resolve these tags? Any other solution to achieve such requirement? Please advice.

- Anirudha
Mishra Anshu
Ranch Hand

Joined: Sep 16, 2003
Posts: 224
Hi,

Put your logic (which you have already in your bean), in a custom tag, and then use that.
Or you may also, override the Struts html tag to incorporte your logic.


"Ignorance is bliss"
Anirudha Joshi
Greenhorn

Joined: Apr 08, 2005
Posts: 22
Thanks for the reply...But issue is still not resolved.....Just to give it a try I wrote following in my tag handler's doEndTag method...

pageContext.getOut().write("<html:text property=\"name\">");

<html> tag written by tag handler is treated as string and does not gets evaluated.

- Anirudha
Mishra Anshu
Ranch Hand

Joined: Sep 16, 2003
Posts: 224
If you are writing your own custom tag, then you should add

pageContext.getOut().write("<input type='text' value='xxx'> like that, because , if you put struts tag in between it doesn't get dynamically transormed to normal html.

Try to override the Struts Tag.
You may add your own properties to the existing Struts tag and then just change the Struts tld file to use your extended class as the implementation.
Anirudha Joshi
Greenhorn

Joined: Apr 08, 2005
Posts: 22
Is there any way to transform struts HTML tags into normal HTML? I want to use struts HTML tags becuase of lot of things(like data retaining)is automatically taken care of.

- Anirudha
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reder controls dynamically