user1806077
user1806077

Reputation: 21

<h:commandLink> not working inside a <h:dataTable>

I will try to explain myself:

I'm working on a JSF project using java, JSF 2.0 and RichFaces 4.2.1.

When I access my jsf it just loads a search filter and a commandLink. The commandLink will launch a method in my backingBean to load data that it will be displayed in a dataTable.

<h:commandLink id="btnRecords">
    <f:ajax render="myCompAjax" event="click" listener="#{myBean.loadRecords}" />
    <h:graphicImage value="img/ico_new.gif" alt="#{bundle['button.search']}" />
</h:commandLink>

The datatable is not visible at first, but once you click on the commandLink a flag in the backingBean will change and the table displays with data I just loaded.

<a4j:outputPanel ajaxRendered="true" id="myCompAjax">
    <h:dataTable id="recordsTable" value="#{myBean.records}"                   
     var="item" rendered="#{myBean.flagShowTable}">
        <h:column headerClass="thPijama" >
            <f:facet name="header">
                <table><tr class="thPijama"><td></td></tr></table>
            </f:facet>
            <h:commandLink action="#{myBean.goNextPage}">
                <h:outputText value="Go Next Page" />
                <h:inputHidden value="#{item}" />   
            </h:commandLink>                                                     
        </h:column>                   
    </h:dataTable>
</a4j:outputPanel>

Problem is the commandLink action inside of the dataTable isn't working at all. I just want to navigate to another jsf. In fact, what it does is hiding the dataTable and leaving the filter unchanged. The action method remains unreachable.

Of course, it works if I set the same commandLink outside the dataTable.

I cannot use Session Scope Beans because the people I work for don't approve it.

Can anyone help me?

Thanks for the hint.

Upvotes: 2

Views: 2829

Answers (1)

BalusC
BalusC

Reputation: 1108782

I cannot use Session Scope Beans because the people I work for don't approve it.

Are you implying that placing the bean in the session scope instead of the request scope actually solved the problem? If so, then just put the bean in the view scope.

@ManagedBean
@ViewScoped
public class MyBean implements Serializable {
    // ...
}

This way the bean will live as long as you're interacting with the same view by ajax requests. The bean is not been shared in other browser tabs/windows in the same session (which is among the architects indeed the major reason to forbid its use in case of simple views).

See also:

Upvotes: 3

Related Questions