Facelet自定义组件-防止在自定义组件中呈现ui:insert内容 [英] Facelet Custom Component - prevent rendering ui:insert content in custom component

查看:153
本文介绍了Facelet自定义组件-防止在自定义组件中呈现ui:insert内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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.

推荐答案

我的猜测是您的<c:if>不能按预期工作,因为在组件树构建阶段对它们进行了评估,然后不再使用.看看此页面.

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.

我个人避免在facelets中使用JSTL标记,因为这些警告使它们与直觉背道而驰.您可以使用标签的"cendered"属性代替<c:if><h:panelGroup>标签.

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.

这篇关于Facelet自定义组件-防止在自定义组件中呈现ui:insert内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆