• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to dynamically evaluate a tag within a java file

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I call a taglib from a JSP with the usual syntax <prefix:tag1>, and I want this tag outputs something like the following <prefix:tag2> or <prefix:tag3>, depends on the attribute value of tag1. But the problem is, the <prefix:tag2> will end up written to the browser.

So my question is, how to dynamically evaluate a tag within a java file?
 
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot write actions (custom tags, JSTL tags, or JSP tags) to the output stream when the JSP is executing. The tags are evaluated at the time that the JSP is translated to a servlet, long before your tag handlers are called.

Factor the processing code from your tags into classes that can be called as part of tag handling. That way, you can call the processing instructions of tag2 and tag3 from the handler code of tag1.
[ May 21, 2005: Message edited by: Bear Bibeault ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Try setting <rtexprvalue> to true for the attribute, which will allow you to take runtime values.

Regards,
Guru
 
Bear Bibeault
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <rtexprvalue> setting has no bearing on this question.
 
Lu Jin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to develop a "propertyTable" tag, its input is the object's class name. Based on the attibutes of the class, this tag will display a table and let user to key in the attribute value for the object. That means, in the jsp file, if we write:
<prefix: propertyTable objectSchemaId="customer"/>
then the following table will be displayed:

________________________________________________________
| Customer Name(String): | Input box (text and number) |
| Is Member(Boolean): | Check box (true or false) |
| Total Amount(Double): | Input box (number only) |
________________________________________________________

In the doStartTag() method of PropertyTableTag, I will retrieve all the attributes of object "customer" based on the objectSchemaId. And based on the data type of those attributes, I will dynamically display the different types of input box to the user. For example, if the totalAmount is "Double", then a number only text box will be displayed in the table, and if the isMember attribute is "Boolean", then a check box will be displayed.

In the doStartTag() method of PropertyTableTag, I wrote:

if(attributeSpec.getDataType().equalsIgnoreCase("Doube"))
{
htmlCode.append("<prefix:myInput name='xxx' dataType='Double'/>");
}

But instead of displaying <input type="text"...>,
<prefix:myInput name='xxx' dataType='Double'/> will be directly displayed to the client.

So,my question is, in a java file (not jsp), how to dynamically evaluate the "myInput" tag and get its plain html code? "myInput" tag can also be a nested tag.
 
Bear Bibeault
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you read my first response?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!