Question

I have this method on a bean:

public boolean isLinkInDescriptionForCheckbox(final Service service) {
    logger.info("Testing if there is a link for {}", service);
    return Service.UK_ADDRESS_CORRECTION == service;
}

...and this in my JSP:

<c:if test="#{serviceUiDescriptions.isLinkInDescriptionForCheckbox(service)}">

My log tells me this:

c.n.c.s.c.ServiceUiDescriptions - Testing if there is a link for null

And YET this works fine:

<label for="checkbox_#{service.name()}"> #{serviceUiDescriptions.getDescriptionForCheckbox(service)}</label>

...which is the line just before the c:if tag

So: In the line just before, service is not null, but in the test for the c:if line service is null.

Here's the whole fragment

<ui:repeat var="service" value="#{servicesBean.getAvailableServicesOfGroup(servicePresentationGroup)}">
    <div class="servicePresentation" title="#{serviceUiDescriptions.getLongDescription(service)}">
        <span class="checkboxSpan"> 
            <input type="checkbox” name="checkbox_#{service.name()}" value="true" checked="checked"
                                    id="checkbox_#{service.name()}" />
        </span>
            <h2>
                <label for="checkbox_#{service.name()}"> #{serviceUiDescriptions.getDescriptionForCheckbox(service)}</label>
                <c:if test="#{serviceUiDescriptions.isLinkInDescriptionForCheckbox(service)}">
                    <span class="smallText">
                        <h:outputLink value="#{serviceUiDescriptions.getLinkInDescriptionForCheckbox(service)}" >
                        #{serviceUiDescriptions.getLinkDescriptionInDescriptionForCheckbox(service)}
                        </h:outputLink>
                    </span>
                </c:if>
            </h2>
        </div>
</ui:repeat>

This is what I get - look no link:

look no link

Was it helpful?

Solution

Both statements may be one line after another but they are not executed at the same time. <c:if> is a JSTL-Tag which is executed during view build time. The other expression will be wrapped in a <h:outputText> which will be executed during view render time. And I guess the service will be created in between.

To solve your problem you could replace the <c:if> with

<ui:fragment rendered="#{serviceUiDescriptions.isLinkInDescriptionForCheckbox(service)}">

or replace the <span> element with

<h:panelGroup styleClass="smallText" rendered="#{serviceUiDescriptions.isLinkInDescriptionForCheckbox(service)}">

(without the <c:if>).

See also:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top