dimanche 26 juillet 2015

Why does ui:fragment not work in custom tag file?

I created the following custom tag for my JSF application:

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

The following is the key part of the custom tag file:

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

Due to an issue with PrimeFaces p:password, I can not set match="" so I need to test password_match and only include match if password_match is not empty. After first, I tried to use the ui:fragment as shown below:

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

The result was that when I set password_match = "" the p:password was not rendered at all. In other words, neither test returned true. My only theory is that ui:fragment doesn't work in the custom tag files.

I then changed my code to the following and it worked as expected.

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

Aucun commentaire:

Enregistrer un commentaire