2
votes

I was just implementing a crude functionality using jsf+richfaces and came across this situation, so putting this to the open forum for some answers.

I have a text field and rich:dataTable inside a form. When value changes in textField, table data is populated and table is supposed to be reRendered with latest data.

Now the point in question : What if I have rendered condition on dataTable saying render this table if list of values is not-null/non-empty? So for the 1st time when screen appears, list is null/empty and hence table is not rendered, as and when I modify textField, values are populated and reRender on table is fired but as a whole table does not exist.

Is there a way to solve this behaviour? If I reload the page, yes table definitely appears :)

Here is the sample code for this :

    <h:form id="userSearchForm" prependId="false">
        <h:inputText value="#{ldapSearch.searchString}">
            <a4j:support event="onkeyup" ignoreDupResponses="true" ajaxSingle="true" reRender="usersTable"
            requestDelay="50" actionListener="#{ldapSearch.searchUser}"/>
        </h:inputText>
            <rich:dataTable id="usersTable"
                rendered="#{not empty ldapSearch.users}"
                value="#{ldapSearch.users}" var="user">
                <rich:column sortable="false" label="Name">
                    <f:facet name="header">
                        <h:outputText value="Name"/>
                    </f:facet>
                    <h:outputText title="#{user.displayName}" value="#{user.displayName}"/>
                </rich:column>
            </rich:dataTable>
    </h:form>
2

2 Answers

4
votes

I solve this issue by surrounding the dataTable with some component that is always rendered, and then reRendering that component instead. For example:

<h:form id="userSearchForm" prependId="false">
    <h:inputText value="#{ldapSearch.searchString}">
        <a4j:support event="onkeyup" ignoreDupResponses="true" ajaxSingle="true" reRender="divUsersTable"
        requestDelay="50" actionListener="#{ldapSearch.searchUser}"/>
    </h:inputText>
    <s:div id="divUsersTable">
        <rich:dataTable id="usersTable"
            rendered="#{not empty ldapSearch.users}"
            value="#{ldapSearch.users}" var="user">
            <rich:column sortable="false" label="Name">
                <f:facet name="header">
                    <h:outputText value="Name"/>
                </f:facet>
                <h:outputText title="#{user.displayName}" value="#{user.displayName}"/>
            </rich:column>
        </rich:dataTable>
    </s:div>
</h:form>
0
votes

The problem is that you can't rerender something that has not been rendered in the first time. My solution is to play with the display attribute of the component style.

<rich:dataTable id="usersTable"
    style="display:#{not empty ldapSearch.users? 'inline' : 'none'}"    
    value="#{ldapSearch.users}" var="user">
<!-- your columns -->
</rich:dataTable>

In that way, I can rerender the table with no problems :).