jsf

Print   in empty table cell


I want to create JSF table with clickable rows. Example:

<h:column>
    <f:facet name="header">
        <h:commandLink value="User name" actionListener="#{bean.sort}" style="text-decoration:none;">
            <f:ajax render="@form" />
        </h:commandLink>
    </f:facet>
    <h:commandLink value="#{item.userName}" action="#{accounts.pageRedirect}" style="text-decoration:none;">
        <f:setPropertyActionListener target="#{accounts.sessionValue}" value="#{item.number}" />
    </h:commandLink>
</h:column>

But when I have empty cell the row is shrink. I tried this solution

 table { empty-cells: show; }

http://www.cs.tut.fi/~jkorpela/HTML/emptycells.html

But according to the article it's not working for IE. So I need to use &nbsp;

How I can implement some logic in h:commandLink value="#{item.userName}" to print &nbsp; if the value is empty?

P.S I need something like this I suppose:

value="#{item.number == null ? &nbsp; : item.number}"

Solution

  • You need to use the rendered attribute to conditionally display content:

    <h:column>
         <h:commandLink value="#{item.userName}" action="#{accounts.pageRedirect}" style="text-decoration:none;" rendered="#{item.number != null}">
              <f:setPropertyActionListener target="#{accounts.sessionValue}" value="#{item.number}" />
         </h:commandLink>
    
         <h:outputText value="&#160;" rendered="#{item.number == null}" />
    </h:column>
    

    See also the following links to understand why I replace &nbsp; by &#160;: