1

这是我的自定义组件定义:

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

4

1 回答 1

1

我的猜测是您<c:if>没有按预期工作,因为它们在组件树构建阶段进行了评估,然后不再存在。看看这个页面

我个人避免在 facelets 中使用 JSTL 标记,因为这些警告使它们违反直觉。您可以使用而不是<c:if>标签<ui:fragment><h:panelGroup>使用它们的“渲染”属性。

于 2009-10-02T09:42:24.587 回答