• 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

Reder controls dynamically

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Anirudha Joshi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic