Skip to content

Instantly share code, notes, and snippets.

@agentgt
Created July 26, 2011 12:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agentgt/1106650 to your computer and use it in GitHub Desktop.
Save agentgt/1106650 to your computer and use it in GitHub Desktop.
Conditionally set attribute in JSPX element.
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<jsp:output omit-xml-declaration="yes"/>
<jsp:directive.attribute name="name" type="java.lang.String" required="true" rtexprvalue="true" description="Name"/>
<jsp:directive.attribute name="value" type="java.lang.String" required="true" rtexprvalue="true" description="Value"/>
<jsp:scriptlet>
//<![CDATA[
String name = (String) jspContext.getAttribute("name");
String value = (String) jspContext.getAttribute("value");
out.write(" " + name + "=" + "\"" + value + "\"");
//]]>
</jsp:scriptlet>
</jsp:root>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:spring="http://www.springframework.org/tags"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<jsp:output omit-xml-declaration="yes"/>
<jsp:directive.attribute name="name" type="java.lang.String" required="true" rtexprvalue="true" description="Name"/>
<jsp:scriptlet>
//<![CDATA[
String name = (String) jspContext.getAttribute("name");
if (name != null) {
out.write("</" + name + ">");
}
//]]>
</jsp:scriptlet>
</jsp:root>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<jsp:output omit-xml-declaration="yes"/>
<jsp:directive.attribute name="name" type="java.lang.String" required="true" rtexprvalue="true" description="Name"/>
<jsp:scriptlet>
//<![CDATA[
String name = (String) jspContext.getAttribute("name");
out.write("<" + name);
//]]>
</jsp:scriptlet>
<jsp:doBody />
<jsp:scriptlet>
//<![CDATA[
out.write(">");
//]]>
</jsp:scriptlet>
</jsp:root>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:help="urn:jsptagdir:/WEB-INF/tags/help">
<jsp:output omit-xml-declaration="yes"/>
<spring:url var="baseUrl" value="/" />
<help:element-start name="div">
<c:if test="${device.html5 }">
<help:attribute name="data-position" value="fixed" />
</c:if>
<help:attribute name="data-role" value="header" />
</help:element-start>
Some stuff here and tags here...
<help:element-end name="div" />
@agentgt
Copy link
Author

agentgt commented Jul 26, 2011

Stick all the tagx files into the /WEB-INF/tags/help directory.

Then see example.jspx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment