每次下载页面时如何更新Primefaces数据表? [英] How to update Primefaces datatable every time when page is downloaded?

查看:104
本文介绍了每次下载页面时如何更新Primefaces数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只有< p:dataTable /> 。当我在另一页的该表中添加新行时,该表未刷新。 RmaBean是ManagedBean范围的会话。有任何想法吗?

I just have <p:dataTable/>. When I add a new row to that table in another page, the table is not refreshed. RmaBean is managedBean scoped session. Any ideas?

<h:form id="mainMenuForm">        

            <p:dataTable id="dataTable" 
                         var="case" 
                         value="#{RmaBean.rmaModel}" 
                         widgetVar="rmaTable" 
                         editable="true" 

                         rows="10" paginator="TRUE" emptyMessage="No items found with given criteria.">

...

...

<p:column></p:column>
        <p:column></p:column>
        <p:column><p:commandButton action="#{MainController.talletaUusiRma}" value="#{bundle.newRma_tallenna}" immediate="true"  ajax="false" style="width: 220px;"/></p:column>
    </p:row>

当我向该表中添加新对象时,我只是更新了 rmaModel 每次,我甚至检查列表是否比以前更长,并且有新对象。 dataTable仍然显示没有新对象的旧数据,为什么?

When I add a new object to that table, I just update the rmaModel every time and I even check that the list is one longer than before and there is that new object. The dataTable shows still the old data without the new object, why?

--------创建新的RMA ---------- ---

--------CREATING NEW RMA-------------

public String prepareNewRma() {
    current = new Rma();
    current.setUser("");
    return "newRma";
}

--------通过串行将数据获取到新RMA NUMBER ------

--------FETCHING DATA TO THE NEW RMA WITH SERIAL NUMBER------

public String haeTiedotSarjanrolla() {
    log.info("sarjanro=" + current.getSarjanro());
    System.out.println("---------------->sarjanro=" + current.getSarjanro());

    Sarjanumerot s = helper.getSerialInfo(current.getSarjanro());

    if (s != null) {
        current.setAn8(s.getAn8());
        current.setDsc1(s.getDsc1());
        current.setDsc2(s.getDsc2());
        current.setSarjanro(s.getId().getLotn());
        current.setTuotenro(s.getId().getLitm());
    }
    return "newRma";
}

--------保存新的RMA ----- ----------

--------SAVING NEW RMA---------------

public String talletaUusiRma() {

    current.setCreated(new Timestamp(System.currentTimeMillis()));
    helper.tallennaRma(current);
    rmaNumbers = null;

   RmaBean papu = (RmaBean) JsfUtil.findBean("rmapapu");

   papu.updateTable();
    return "mainMenu";
}

帮助:

 public void tallennaRma(Rma current) {
        try {
            Session session = HibernateUtil.getAsekorjausSessionFactory().getCurrentSession();
            session.beginTransaction();
            session.saveOrUpdate(current);
            session.getTransaction().commit();
        } catch (Exception e) {
            log.debug(e.getMessage());
                        JsfUtil.addErrorMessage(ResourceBundle.getBundle("resources/Bundle").getString("editRma_err_updateError"));
        }

---------更新RmaBean中的模型和表----------

---------UPDATING MODEL AND TABLE in RmaBean-----------

public void updateTable(){

    System.out.println("updateTableupdateTableupdateTable");
    rmaModel.setWrappedData(rmaModel.getUpdatedList());
    System.out.println("1111111..........");
    List<Rma> rmat = rmaModel.getUpdatedList();
    System.out.println("22222222.......");
    Iterator iter = rmat.iterator();
    System.out.println("------------------------>PITUUS: " +rmat.size());
    while (iter.hasNext()) {
        Rma t = (Rma) iter.next();
        System.out.println("t.getRma()NUMERO------->" +t.getRma());


    }

    RmaDataModel newRMAModel = new RmaDataModel(rmat); 
    rmaModel = newRMAModel;
}

萨米人

推荐答案

dataTable的值属性在会话范围内,因此,仅在此会话中的第一个请求时才会呈现数据表(如果不手动更新此视图)。

value-attribute of you dataTable is in session scope, so your datatable will only be rendered on you first request in this session (if you do not update this view manually).

使用视图作用域bean作为视图。如果有必要将此列表放在会话范围内,则只需将列表从任何会话范围的bean注入到视图范围的bean中即可。

Use view scoped bean for your views. If it's necessary that this list is in session scope, just inject the list from any session scoped bean to your view scoped bean.

这篇关于每次下载页面时如何更新Primefaces数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆