0

I'm using primefaces commandLink in p:datatable and when user clicks on link. It's supposed to navigate to another page including specific info of object that is chosen from table. I don't use any ajax tags. Problem is when first time clicks on link it doesn't invoke action actually nothing happens and on second click it works. Here is my code :

JSF with Datatable

<h:form>
        <h:outputText value="Nothing is found" rendered="#{searchView.citizenSearchList.rowCount==0}"/>

        <p:dataTable var="cust" value="#{searchView.citizenSearchList}" dynamic ="true" paginator="true" rows="5" paginatorAlwaysVisible="false" style="width: 700">
            <p:column>
                <f:facet name ="header">
                    <h:outputText value="name "/>
                </f:facet>
                <h:outputText value="#{cust.name}"/>
            </p:column>
            <p:column>
                <f:facet name ="header">
                    <h:outputText value="lastname "/>
                </f:facet>
                <h:outputText value="#{cust.citizenList.get(0).lastname}"/>
            </p:column>
            <p:column>
                <f:facet name ="header">
                    <h:outputText value="Id "/>
                </f:facet>
                <h:outputText value="#{cust.registernumber}"/>
            </p:column>
            <p:column>
                <f:facet name ="header">

                </f:facet>
                <p:commandLink value="See" action="#{customerView.prepareCitizenView()}"/>
            </p:column>
        </p:dataTable>

    </h:form>

ManagedBean: customerView's action method

@ManagedProperty(...)  
SearchView searchview;
public String prepareCitizenView(){
    this.customer = (Customer) searchview.citizenSearchResultList.getRowData();
    if(this.customer != null)
        return "citizeninfo";
    else
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "no data.", "no data"));
        return null;


}

ManagedBean: searchView

DataModel citizenSearchResultList;

public DataModel getCitizenSearchResultList() {
    return citizenSearchResultList;
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Odgiiv
  • 683
  • 1
  • 11
  • 32
  • PrimeFaces `p:commandLink` and `p:commandButton` use ajax by default. So the statement "I don't use any ajax tags" has no grounds. The question is, how exactly are you performing the actual search action which should show the results in that table? Also by a `p:commandButton`? – BalusC Jan 17 '13 at 15:06

3 Answers3

0

You can return redirect to same page. customerView.prepareCitizenView can retruns same page with redirect. like

return "citizeninfo.jsf?faces-redirect=true";

this "jsf" changes according to what you use

mehmet cinar
  • 160
  • 1
  • 7
0

As mehmet cinar stated, the solution is to use a redirect in your navigation outcome. I've had this problem myself.

return "citizeninfo.jsf?faces-redirect=true";

From what I was able to deduce, the reason is that the ajax submit will not contain a ViewState request parameter for the new page. Without the ViewState the first time, things break.

Once you perform a redirect, the redirect will correctly have a Viewstate parameter appended to the request, and buttons can be clicked the first time

mkienenb
  • 56
  • 3
0

If p:commandLink is included within two h:form then action will be invoked on second call. Check the outer tags of p:commandLink