将项添加到Primefaces表中

时间:2017-06-28 09:36:20

标签: jsf primefaces jsf-2.2

我想在创建新项目时将项目添加到Primefaces表中。我设法创建了这段代码:

<h:form id="new_item_button">

    <p:commandButton id="ajax" value="New Sensor" styleClass="ui-priority-primary" onclick="PF('dlg').show();" type="button"/>

</h:form>

<h:form id="new_sensor">

    <p:dialog header="New Sensor" widgetVar="dlg" focus="name" modal="true" showEffect="fade">
        <h:panelGrid columns="2" cellpadding="5">
            <h:outputLabel for="name" value="Name" />
            <p:inputText id="name" label="name" value="#{newSensor.sensor.name}" />

            .............................
        </h:panelGrid>

        <f:facet name="footer">
            <p:commandButton id="ajax" value="Create Sensor" actionListener="#{newSensor.saveRecord()}" update=":new_sensor"/>
        </f:facet>
    </p:dialog>

</h:form>

<h:form id="form">
    <p:dataTable id="tbl" var="sensor" value="#{sensors.systemSensors}"
                 .......
                 paginator="true" rows="12"
                 rowKey="#{sensor.model}">

        <p:column headerText="Name" sortBy="#{sensor.name}" style="text-align: center">
            <h:outputText value="#{sensor.name}" />
        </p:column>

        ...................
        </p:column>
    </p:dataTable>

豆类:

@Named
@RequestScoped
public class Sensors implements Serializable
{
    private List<SensorObj> sensors;

    @PostConstruct
    public void init()
    {
        sensors = generateSensors();
    }

    public List<SensorObj> getSystemSensors()
    {
        return sensors;
    }

    private List<SensorObj> generateSensors()
    {
        List list = new ArrayList();
        SensorObj obj1 = new SensorObj("Sensor 1", "SBS0212", "Online", true, null);
        list.add(obj1);
        return list;
    }
}


@Named
@RequestScoped
public class NewSensor implements Serializable
{
    private SensorObj sensor = new SensorObj();

    public SensorObj getSensor()
    {
        return sensor;
    }

    public void setSensor(SensorObj sensor)
    {
        this.sensor = sensor;
    }

    public void saveRecord(){
        .....
    }

}

当我使用新传感器提交对话框时,我想更新表格。我该如何实现呢? 我应该使用一个托管bean来列出内容并添加新项目,还是因为它最好使用两个?

0 个答案:

没有答案