Google Answers Logo
View Question
 
Q: custom tags in JSP ( No Answer,   0 Comments )
Question  
Subject: custom tags in JSP
Category: Computers > Programming
Asked by: carbon-ga
List Price: $8.00
Posted: 28 Jun 2004 13:51 PDT
Expires: 12 Jul 2004 22:12 PDT
Question ID: 367423
I understand how to write and use custom tags. The problem is that the
HTML within the Java that implements the tag does not look nice (I
have to escape double-quotes, etc.) and the generated HTML doesn't
look nice (it is not properly indented, etc.).

One way of solving these problems might be to write my tag handler
classes in such a way that they include JSPs.  That way I could code
the HTML I want my tags to produce in an intuitive way. But the JSPs
would need to substitute values I specified in the tags.

That is, I write a JSP that uses custom tags. Maybe my tag handler
class's doStartTag somehow passes the values I specified in the custom
tag to a JSP. The JSP produces nice code.

Are people doing stuff like that? Or please make your own suggestion.

Request for Question Clarification by rhansenne-ga on 09 Jul 2004 15:47 PDT
How about using multiple nested tags, where child tags retrieve their
values from the enclosing parent tags. For example:

...
<myPrefix:myMainTag>
	<table>
	<myPrefix:nestedTag>
		<tr>	
			<td><myPrefix:printMyFirstValue /></td>
			<td><myPrefix:printMySecondValue /></td>
	  	</tr>
	</myPrefix:nestedTag>
	</table>
</myPrefix:myMainTag>
...

That way you don't need to write out any HTML from within Java code
(which usually is a bad practice anyway) and you tags only contain the
logic.

If the same html is used in multiple pages, it might indeed be more
interesting to use some sort of html template and insert values into
placeholders.

Another approach would be to use a Java api to generate HTML-tags in
stead of manually printing them. This would make your code cleaner.
Specific libraries exist for HTML, or you could use a DOM
implementation to create an XML tree, which can be printed out as
(X)HTML.

Sincerely,

rhansenne-ga.
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy