Skip to content Skip to sidebar Skip to footer

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:panelGridcolumns="2"><h:outputLabelfor="country"value="Country" /><h:inputTextid="country"value="#{bean.country}"required="${countryRequired}" /><c:iftest="${showAddress}"><h:outputLabelfor="address"value="Address" /><h:inputTextid="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"