p:commandLink with lazyload p:datagrid可能不起作用

时间:2014-09-14 14:21:05

标签: jsf-2 primefaces datagrid lazy-loading

我有p:datagrid包含一些优惠

p:datagrid内有一个p:commandLink会传递优惠并重定向到其他页面

这是我的xhtml

<p:dataGrid lazy="true" var="offer" paginatorPosition="bottom" value="#{listCategoriesBean.OfferByCategory()}" columns="1"
        rows="5" paginator="true" id="OffersList" styleClass="listPage"
        paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  emptyMessage="#{msg['offersEmpty']}"    widgetVar="dtWv">

    <p:commandLink  styleClass="clickAll" action="#{navigationBean.ToMore()}"> 
        <f:setPropertyActionListener value="#{offer}" target="#{listCategoriesBean.offer}" />
        <i class="fa fa-plus"></i>
    </p:commandLink>
</p:dataGrid>

这是我的豆子

@SessionScoped
public class NavigationBean implements Serializable {
  public String ToMore() {
    return "/more.xhtml?faces-redirect=true";
  }
}

问题是当点击commandLink时它只刷新页面

2 个答案:

答案 0 :(得分:0)

(复制自答案,所以(c)@naifsami)

我通过在表外使用p:remotecommand解决了workarround想法的问题,并从表中调用了remotecommand

<p:remoteCommand name="remoteCommandFunctionName"  action="#{listCategoriesBean.ToMore()}" />

    <p:dataGrid lazy="true" var="offer" paginatorPosition="bottom" value="#{listCategoriesBean.OfferByCategory()}" columns="1"
        rows="5" paginator="true" id="OffersList" styleClass="listPage"
        paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  emptyMessage="#{msg['offersEmpty']}"    >
 <p:commandLink  styleClass="clickAll"  type="button" onclick="remoteCommandFunctionName([{name:'n', value:'#{offer.id}'}])" > 
                            <i class="fa fa-plus"></i>
                        </p:commandLink>
</p:dataGrid>

我的豆子

public String ToMore() {
        String offerid="";
        FacesContext context = FacesContext.getCurrentInstance();
        Map map = context.getExternalContext().getRequestParameterMap();
        offerid=(String) map.get("n");
        offer1= newOfferServices.OfferByNumber(Integer.parseInt(offerid));
        setOffer(offer1);
        return "/more.xhtml?faces-redirect=true";
    }

答案 1 :(得分:-2)

您应该通过导航结果属性获得所需的结果。

&#13;
&#13;
<p:commandLink styleClass="clickAll" action="more.xhtml?faces-redirect=true">
  <f:setPropertyActionListener value="#{offer}" target="#{listCategoriesBean.offer}" />
  <i class="fa fa-plus"></i>
</p:commandLink>
&#13;
&#13;
&#13;