具有动态列的p:dataTable不会呈现任何内容

时间:2019-04-28 15:44:07

标签: jsf primefaces

我正在使用PrimceFaces,并且想要呈现一个表,该表的列数是动态确定的。我在这里找到一个例子:

https://www.primefaces.org/showcase/ui/data/datatable/columns.xhtml

,我认为我正确实现了该表,但是未呈现该表。实际上,什么都没有渲染。我调试了程序并确定:

test = schedule.scheduleJob({second: 3, hour: dataA[0].off_h , minute: dataA[0].off_m, dayOfWeek: timerSD.day}, function() {
                console.log(now+': Timer automatic OFF - SD: '+x+ "timer ID."+dataA[0].ID);
                db.setStatus(x, 0);
            });
test.reschedule(true);

被调用,但是方法

CinemaSeatViewBean.getSeatsForShowList()

根本没有被调用。

在我的代码下面:

1。)托管Bean:

CinemaSeatViewBean.getDataTableColumns()

2。)方面:

@ManagedBean
@ViewScoped
public class CinemaSeatViewBean implements Serializable {

    private static final long serialVersionUID = 1L;


    private List<SeatForShow> seatsForShowList = new ArrayList<SeatForShow>();
    private List<DataTableColumn> dataTableColumns = new ArrayList<DataTableColumn>();

    @PostConstruct
    public void init() {
        // add SeatForShows
        ExternalContext extContext = FacesContext.getCurrentInstance()
                .getExternalContext();

        Flash flash = extContext.getFlash();
        FilmShow selectedFilmShow = (FilmShow)flash.get(FilmAndCinemaChooserBean.SELECTED_FILM_SHOW);

        int noOfColumns = selectedFilmShow.getNumberOfColumns();

        for (int i = 0; i < noOfColumns; i ++){
            // prepare dynamic columns
            dataTableColumns.add(new DataTableColumn("Seat " + (i+1), "seatNo"));
        }

        for ( SeatForShow seatForShow: selectedFilmShow.getSeatsForShow()){
            seatsForShowList.add(seatForShow);
        }
    }

    public void setDataTableColumns(List<DataTableColumn> dataTableColumns) {
        this.dataTableColumns = dataTableColumns;
    }

    public List<DataTableColumn> getDataTableColumns() {
        return dataTableColumns;
    }

    public List<SeatForShow> getSeatsForShowList() {
        return seatsForShowList;
    }


    public void setSeatsForShowList(List<SeatForShow> seatsForShowList) {
        this.seatsForShowList = seatsForShowList;
    }
}

3。)DataTableColumn类:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
</h:head>
<h:body>
    <h:form id="seatsFormId">
        <p:dataTable id="seatsTableId" value="#{cinemaSeatViewBean.seatsForShowList}" var="seatForShow">
            <p:columns value="#{dataTableView.dataTableColumns}" var="column" sortBy="#{seatForShow[column.property]}">
                 <f:facet name="header">
                     <h:outputText value="#{column.header}" />
                 </f:facet>
                 <h:outputText value="#{seatForShow[column.property]}" />                      
            </p:columns>
        </p:dataTable>
    </h:form>
</h:body>
</html>

4。)我希望我正确地启用了DEVELOPMENT_MODE:

public class DataTableColumn implements Serializable{

    private static final long serialVersionUID = 1L;

    private String header;
    private String property;

    public DataTableColumn(String header, String property) {
        this.header = header;
        this.property = property;
    }

    public String getHeader() {
        return header;
    }

    public String getProperty() {
        return property;
    }
}

1 个答案:

答案 0 :(得分:2)

除非有错字,

<p:columns value="#{dataTableView.dataTableColumns}" var="column" sortBy="#{seatForShow[column.property]}">

应该是

<p:columns value="#{cinemaSeatViewBean.dataTableColumns}" var="column" sortBy="#{seatForShow[column.property]}">

但是您的IDE应该为此警告您,并且我也期望运行时错误(除非bean实际上存在于您的项目中并且在getter中不做任何事情)。