2009-09-30 77 views
1

內容,這是我的自定義組件定義:的facelet自定義組件 - 防止渲染UI:插入自定義組件

<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"> 
<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> 

這是我如何使用它:

<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> 

我有<ui:insert name="field" />麻煩。它總是呈現。如果disabled = true,我只在視圖的頂部有<input type="text" disabled="disabled" value="" name="itSIN" id="itSIN"/>元素。注意:我使用ui:insert傳遞jsf組件,因爲我不知道如何將驗證器傳遞給定製組件內的h:inputText。

回答

1

我的猜測是你的<c:if>不像你期望的那樣工作,因爲它們在組件樹構建階段被評估,然後停止。看看this page

我個人避免在facelets中使用JSTL標籤,因爲這些注意事項使它們不符合直覺。您可以使用它們的「呈現」屬性代替<c:if>代碼<ui:fragment><h:panelGroup>