views:

749

answers:

1

Hi, this is my custom component definition:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jstl/core"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions"&gt;
<c:if test="${empty required}">
 <c:set var="required" value="false" />
</c:if>
<c:if test="${empty disabled}">
 <c:set var="disabled" value="false" />
</c:if>
<c:if test="${not disabled}">
<div id="#{id}DIV">
 <label for="#{id}" class="portlet-form-label">${label}</label>
 <ui:insert name="field" />
 <c:if test="${required}">*</c:if>
 <strong class="portlet-msg-error" style="display: none;"><h:message for="#{id}" /></strong>
</div>
</c:if>
</ui:composition>

this is how I use it:

<my:editLineInsert id="itSIN" label="#{label['label.stocks.income']}" tip="#{label['message.default.tooltip']}" disabled="#{engine.disabled['itSIN']}" required="#{engine.required['itSIN']}" >
 <ui:define name="field">
 <h:inputText id="itSIN"  value="#{order.income}" disabled="#{engine.disabled['itSIN']}" required="#{engine.required['itSIN']}" >
<f:converter converterId="javax.faces.BigDecimal" />
<f:validator validatorId="V12DGS6DECS" />
</h:inputText>
 </ui:define>
</my:editLineInsert>

I have trouble with <ui:insert name="field" />. It renders ALWAYS. If disabled=true I got just <input type="text" disabled="disabled" value="" name="itSIN" id="itSIN"/> element at the top of view. NOTE: I use ui:insert to pass jsf component because I have no clue how to pass validators to an h:inputText inside custom component.

+1  A: 

My guess is that your <c:if> are not working as you expect, because they are evaluated during the component tree building phase and then cease to be. Take a look at this page.

I personally avoid using JSTL tags in facelets, because of these kind of caveats which make them counter-intuitive. You can use instead of <c:if> the tags <ui:fragment> or <h:panelGroup> using their "rendered" attribute.

ckarmann