JSF 1.2 Custom Component From Jsp:include
Before I get started with my question, here are my unfortunate limitations: I'm using JSF 1.2, not 2; so no composite component. I'm using JSP for rendering instead of facelets;
Solution 1:
Create a JSP tag file.
/WEB-INF/tags/foo.tag
<%@ tag body-content="empty" %>
<%@ attribute name="countryRequired" required="false" type="java.lang.Boolean" %>
<%@ attribute name="showAddress" required="false" type="java.lang.Boolean" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<h:panelGrid columns="2">
<h:outputLabel for="country" value="Country" />
<h:inputText id="country" value="#{bean.country}" required="${countryRequired}" />
<c:if test="${showAddress}">
<h:outputLabel for="address" value="Address" />
<h:inputText id="address" value="#{bean.address}" />
</c:if>
</h:panelGrid>
Declare and use it as follows (no additional XML configuration necessary):
<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
...
<my:foo showAddress="true" />
Note that JSTL is also here a "view build time" tag like as in Facelets. Also note that you can't use #{}
to reference JSP tag attributes.
Post a Comment for "JSF 1.2 Custom Component From Jsp:include"