tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Lea <ja...@kumachan.net.nz>
Subject Re: ignoring whitespaces inside a tag
Date Sun, 29 Aug 2004 21:11:46 GMT
If you are using Tomcat 5 or compiling JSPs using Tomcat 5 you can do 
this here
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jasper-howto.html#Configuration

When tomcar compiles the JSP it can have 'trimSpaces' turned on which 
will remove the whitespace between tags.  I can think of other options 
like wrapping the tag in a string replacement tag like 
http://jakarta.apache.org/taglibs/doc/string-doc/index.html#replace

Or else you can write your tag like this:

string 1
<lib:tag attr="a"><lib:inside_tag attr2="b" /><lib:inside_tag attr2="c" /><lib:inside_tag
attr2="d" /></lib:tag>
string 2

which is ugly, or this

string 1
<lib:tag attr="a"
	 ><lib:inside_tag attr2="b"
	/><lib:inside_tag attr2="c"
	/><lib:inside_tag attr2="d"
/></lib:tag>
string 


Which is still a bit ugly, but more readable.  The white space and 
newline is inside the tag so it won't appear in the output.

luca wrote:

>Hallo, I hope this is the right group to ask TAG-lib related
>questions. Unfortunately, generic Java forums tend to be way too bad
>at answering this kind of questions.
>
>I am implementing a tag-lib. One of the tags requires (or better allows)
>nested internal tags to better define the meaning of the top tag.
>
>string 1
><lib:tag attr="a">
>   <lib:inside_tag attr2="b" />
>   <lib:inside_tag attr2="c" />
>   <lib:inside_tag attr2="d" />
></lib:tag>
>string 2
>
>I have implemented this and it works. My only problem is that there are
>a bunch of carriage returns and white spaces in the output that I would
>like to avoid. In practice, I am getting this
>
>--------------------------------------------------
>string 1
>
>
>
>
>tag output
>string2
>--------------------------------------------------
>while what I really want is:
>
>--------------------------------------------------
>string 1
>tag output
>string2
>--------------------------------------------------
>
>since the internal tags only add info to the main tag and have no output
>per se.
>
>Right now I am using
>
>return(EVAL_BODY_INCLUDE);
>
>at the end of the onStartTag() method....
>
>Is there a way to tell the JSP engine to parse the tags but
>discard the output?
>
>thank you
>
>Luca
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>
>
>  
>


-- 
Jason Lea



---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org


Mime
View raw message