首页 > 解决方案 > p:datagrid 不会从视图中加载数据

问题描述

我正在使用 JAVA 10、WildFly 14、Primefaces 6.2

我正在做一个礼品店,这是 xhtml 文件中网格的代码:

<p:dataGrid var="car" value="#{giftList.lgif}" columns="3" layout="grid"
    rows="12" paginator="true" id="gifts"
    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
    rowsPerPageTemplate="6,12,16">
    <f:facet name="header">
        REGALOS
    </f:facet>
    <p:panel header="#{giftList.number}" style="text-align:center">
        <h:panelGrid columns="1" style="width:100%">
            <p:graphicImage name="car.gif"/> 
                    <h:outputText id="out" value="#{giftList.text}" />
            <h:outputText value="#{giftList.number}" />

            <p:commandLink update=":form:carDetail" oncomplete="PF('carDialog').show()" title="View Detail">
                <h:outputText styleClass="ui-icon ui-icon-search" style="margin:0 auto;" />
                <f:setPropertyActionListener value="#{gifts}" target="#{giftList.lgif}" />
            </p:commandLink>
        </h:panelGrid>
    </p:panel>

</p:dataGrid>

我希望网格显示礼物列表,我有两个类,一个是带有名称和价格的命名礼物,另一个是构建所有礼物的命名礼物列表:

礼物:

package org.primefaces.showcase.view.ajax;

public class gifts {

public String name;
public int price;
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public int getPrice() {
    return price;
}
public void setPrice(int price) {
    this.price = price;
}}

礼品清单:

package org.primefaces.showcase.view.ajax;
import java.util.List;

import javax.annotation.PostConstruct;
import org.primefaces.showcase.view.ajax.gifts;

public class giftList {
private List<gifts> lgif;
private int numero =1;
private String text;

public String getText() {
    return text;
}
public void setText(String text) {
    this.text = text;
}
    gifts gf = new gifts();
@PostConstruct
public void init() {
    gf.setName("OSITO");
    gf.setPrice(40);
    lgif.add(gf);
}

 public int getGifts() {
        return lgif.size();
    }
public gifts getcurrentgift() {
     return lgif.get(0);
}   }

首先,我希望数据网格中的 value="" 等于 #{giftList.lgif} 包含礼物的对象,由于某种原因它不会采用我输入的值,它只会在值为“1”时显示一些东西“或者更多,我做错了什么?

标签: primefaceswildfly

解决方案


推荐阅读