jsp - Custom JSTL tags with body -


We are going to use JSTL and custom JSTL tags for some type of template engine in our JSP / Spring-project Are there.

Is there a way to create such a tag that looks like this:

  & lt; Div id = "site" & gt; & Lt; Div id = "header" & gt; Some titles & lt; / Div & gt; & Lt; Div id = "navigation" & gt; Some dynamic content here & lt; / Div & gt; & Lt; Div id = "content" & gt; $ {Content} & lt; / Div & gt; & Lt; Div id = "footer" & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

And use it like this:

  & lt; Mytags: template> & Lt; H1 & gt; Title & lt; / H1> & Lt; P & gt; my content! & Lt; / P & gt; & Lt; / Mytags: Templates & gt;  

i.e. Use body-ingredients inside custom JSTL-tags ...

This works:

  & lt; Mytags: Template Content = "Some Content ... No HTML" />  

But not very useful in our case.

The answer to the same McDowell is, but with more flexibility, declare a feature that is a piece is.

For example, //foo.tag tag file

  & lt;% @ attribute name = "greeting" fragment = "true"%> & Lt;% @ attribute name = "body" fragment = "true"%> & Lt; H1 & gt; & Lt; Jsp: invitation piece = "greeting" gt gt; & Lt; / H1> & Lt; P & gt; Body: & lt; Em> & Lt; Jsp: iwak fragment = "body" /> gt; & Lt; / Em> & Lt; / P & gt;  

jsp file

  & lt; X: foo & gt; & Lt; Jsp: attribute name = "greeting" & gt; & Lt; B & gt; A fancy & lt; / B & gt; Hello & lt; / Jsp: attribute & gt; & Lt; Jsp: attribute name = "body" & gt; & Lt; Pre & gt; More fancy body & lt; / Pre & gt; & Lt; / Jsp: attribute & gt; & Lt; / X: foo & gt;  

This will produce this markup:

  & lt; H1 & gt; & Lt; B & gt; A fancy & lt; / B & gt; Hello & lt; / H1> & Lt; P & gt; Body: & lt; Em> & Lt; Pre & gt; More fancy body & lt; / Pre & gt; & Lt; / Em> & Lt; / P & gt; & Lt; / Body & gt;  

The main advantage is to be able to do two pieces instead of just one tag.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -