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

时间:2019-01-21 10:18:46

标签: java jsf primefaces managed-bean trinidad

我将6.2版的primefaces与jsf和trinidaad结合使用。 在项目中,我有一个表格,每行包含一个按钮,用于根据选定的行将页面重定向到另一页。 jsf和trindad commandLink和commandButton可以完成这项工作,但primefaces commandLink和Command按钮却不能。

我已经做过的事情:

  1. 将按钮的类型更改为type="button"
  2. 添加了immediate="true"
  3. 我使用actionListener="#{coolingBean.view(row)}"代替了action="#{coolingBean.view}"

任何人都知道为什么以及应该更改什么?

<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>

内部托管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';
  }

1 个答案:

答案 0 :(得分:-1)

This one实际上帮助了我。

基本上添加以下内容之一对我有用:

  • ajax="false"添加到命令按钮
  • 在网址上附加?faces-redirect=true(例如return "view?faces-redirect=true';
相关问题