为什么ui:fragment在自定义标记文件中不起作用?

时间:2015-07-27 05:53:43

标签: jsf primefaces facelets tagfile conditional-rendering

我为我的JSF 2.2应用程序创建了以下自定义标记:

<et:gridRowLabelPasswordMessage
    label_name="Password"
    password_id="password"
    password_value="#{myAuthenticator.password}"
    password_required="true"
    password_match=""
    password_binding="#{pw}" />

以下是自定义标记文件的关键部分:

<p:password
    id="#{password_id}"
    value="#{password_value}"
    placeholder="#{label_name}"
    binding="#{password_binding}"
    required="#{password_required}"
    requiredMessage="#{label_name} is required."
    match="#{password_match}" />

由于PrimeFaces p:password存在问题,我无法设置match =“”所以我需要测试password_match,如果password_match不为空,则只包括匹配。首先,我尝试使用ui:fragment,如下所示:

<ui:fragment rendered="#{empty password_match}">
    <p:password
        id="#{password_id}"
        value="#{password_value}"
        placeholder="#{label_name}"
        binding="#{password_binding}"
        required="#{password_required}"
        requiredMessage="#{label_name} is requred." />
</ui:fragment>
<ui:fragment rendered="#{not empty password_match}">
    <p:password
        id="#{password_id}"
        value="#{password_value}"
        placeholder="#{label_name}"
        binding="#{password_binding}"
        required="#{password_required}"
        requiredMessage="#{label_name} is requred."
        match="#{password_match}" />
</ui:fragment>

结果是当我设置password_match =“”时,p:密码根本没有呈现。换句话说,两个测试都没有返回true。我唯一的理论是ui:fragment在自定义标记文件中不起作用。

然后我将代码更改为以下内容,并按预期工作。

<c:choose>
    <c:when test="#{empty password_match}">
        <p:password
            id="#{password_id}"
            value="#{password_value}"
            placeholder="#{label_name}"
            binding="#{password_binding}"
            required="#{password_required}"
            requiredMessage="#{label_name} is required." />
    </c:when>
    <c:otherwise>
        <p:password
            id="#{password_id}"
            value="#{password_value}"
            placeholder="#{label_name}"
            binding="#{password_binding}"
            required="#{password_required}"
            requiredMessage="#{label_name} is required."
            match="#{password_match}" />
    </c:otherwise>
</c:choose>

0 个答案:

没有答案