UndefinedReference
UndefinedReference

Reputation: 1253

Hiding JSF elements with Java

The java code returns a column from a SQL query and if the item isn't null, sets the title to "Available".

String sppAcronym = results.getString("ACRONYM");
if (sppAcronym != null) {
    sp.setFireStudyTitle("Available");
}

The JSF code makes a button labeled "Available" for all of the non-null items.

<h:column headerClass="columnHeader" footerClass="columnFooter" itemValue="0">
    <f:facet name="header">Link to FEIS Fire Studies</f:facet>
    <h:commandButton id="btnSearch" value="#{SPP.fireStudyTitle}"
        action="#{searchBean.doMagic(SPP.acronym)}"
        immediate="true" onchange="submit();" 
        style="font-weight:bold; font-size:small;"
        onclick="javascript:cursor_wait()" class="buttonsFEIS"/>&#160;&#160;
</h:column>

My problem is that JSF makes small, empty commandButtons even for the null items.

How can I make it so I can hide those empty commandButtons and display only the non-null items?

Upvotes: 0

Views: 45

Answers (1)

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

Use rendered attribute of the <h:commandButton> to control if the component must display or not in the generated HTML:

<h:commandButton id="btnSearch" value="#{SPP.fireStudyTitle}"
    action="#{searchBean.doMagic(SPP.acronym)}"
    immediate="true" onchange="submit();" 
    style="font-weight:bold; font-size:small;"
    onclick="javascript:cursor_wait()" class="buttonsFEIS"
    rendered="#{not empty SPP.acronym}" />

Upvotes: 2

Related Questions