简体   繁体   中英

Why Primefaces commandButton does not redirect to the page?

I use primefaces version 6.2 in combination with jsf and trinidaad. In the project I have a table with each row containing a button to redirect this page to another page based on selected row. jsf and trindad commandLink and commandButton does the job but primefaces commandLink and command button doesn't.

What I have already done:

  1. Changed the type of button to type="button"
  2. Added immediate="true"
  3. I used actionListener="#{coolingBean.view(row)}" instead of action="#{coolingBean.view}" .

Anyone know why and what should I change?

<p:column id="viewButtonColumn" exportable="false" style="text-align: center" >
            <tr:commandLink textAndAccessKey="&amp;view " id="viewButton" action="#{coolingBean.view}" styleClass="commandLinkMediumSmallFont" onclick="PF('bui').show()">
                <tr:image source="/imgs/view.png" styleClass="commandLinkImageWithText"/>
                <f:setPropertyActionListener value="#{row.number}" target="#{coolingBean.criteria.number}"/>
                <f:setPropertyActionListener value="#{row.id}" target="#{searchBean.selectedId}"/>
            </tr:commandLink>
</p:column>

<p:column id="viewButtonColumn1" exportable="false" style="text-align: center" >
            <h:commandLink  textAndAccessKey="&amp;view " id="viewButton1" action="#{coolingBean.view}" styleClass="ui-priority-primary" onclick="PF('bui').show()">
                <i class="fa fa-search" ></i>
                <f:setPropertyActionListener value="#{row.number}" target="#{coolingBean.criteria.number}"/>
                <f:setPropertyActionListener value="#{row.id}" target="#{searchBean.selectedId}"/>
            </h:commandLink>
</p:column>

<p:column id="viewButtonColumn2" exportable="false" style="text-align: center" >
            <p:commandLink value="View" id="commandLinkView" action="#{coolingBean.view}" styleClass="ui-priority-primary" onclick="PF('bui').show()">
                <i class="fa fa-search" ></i>
                <f:setPropertyActionListener value="#{row.number}" target="#{coolingBean.criteria.number}"/>
                <f:setPropertyActionListener value="#{row.id}" target="#{searchBean.selectedId}"/>
            </p:commandLink>
</p:column>

<p:column id="viewButtonColumn3" exportable="false" style="text-align: center" >
            <p:commandButton id="viewButton2" value="View" action="#{coolingBean.view}" icon="fa fa-search" immediate="true" type="button" onclick="PF('bui').show()">
               <f:setPropertyActionListener value="#{row.number}" target="#{coolingBean.criteria.number}"/>
               <f:setPropertyActionListener value="#{row.id}" target="#{searchBean.selectedId}"/>
            </p:commandButton>
</p:column>

Inside managed Bean

public String view(Row selectedRow) {
    if(criteria == null)
      criteria = new criteriaBean();

    criteria.setNummer(selectedRow.getNummber());
    searchBean.selectedId = selectedRow.getId();


 //FacesContext.getCurrentInstance().getExternalContext().dispatch("view.jsp");
    return view();
  }

  public String view(){

    return"view';
  }

This one actually helped me.

Basically adding one of the following did the trick for me:

  • Adding ajax="false" into the commandButton
  • Appending ?faces-redirect=true to the url ( eg return "view?faces-redirect=true'; )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM