简体   繁体   English

为什么 Primefaces commandButton 不重定向到页面?

[英]Why Primefaces commandButton does not redirect to the page?

I use primefaces version 6.2 in combination with jsf and trinidaad.我将 primefaces 6.2 版与 jsf 和 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. jsf 和 trindad commandLink 和 commandButton 可以完成这项工作,但 primefaces commandLink 和 command button 没有。

What I have already done:我已经做了什么:

  1. Changed the type of button to type="button"将按钮的类型更改为type="button"
  2. Added immediate="true"添加immediate="true"
  3. I used actionListener="#{coolingBean.view(row)}" instead of action="#{coolingBean.view}" .我使用actionListener="#{coolingBean.view(row)}"而不是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内部托管 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 commandButtonajax="false"添加到 commandButton
  • Appending ?faces-redirect=true to the url ( eg return "view?faces-redirect=true'; )?faces-redirect=true附加到 url (例如return "view?faces-redirect=true';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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