0

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

<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每次都更新,我什至检查列表是否比以前长一个,并且有那个新对象。数据表仍然显示没有新对象的旧数据,为什么?

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

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

--------使用序列号将数据提取到新的 RMA-----

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----------------

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 中更新模型和表格-----------

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;
}

萨米人

4

3 回答 3

1

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).

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.

于 2012-11-06T14:23:10.177 回答
0

I made a real bubblegum solution because I couldn't fit it otherwise. I just write bean again to session, so it goes over the old one with name "rmapapu". No it is working. Is there any consequences or is this really bad idea?

    rmaModel = null;
    RmaDataModel rmaModel = new RmaDataModel(rmat);
    //rmaModel = newRMAModel;
    this.setRmaModel(rmaModel);

    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    HttpSession httpSession = request.getSession(false);
    httpSession.setAttribute("rmapapu", this);

Thanks for everybody helping me. I still will read BalusC tutorial about that, because it would be nice to know how you should do that :)

Sami

于 2012-11-06T19:34:17.873 回答
0

如果我很好地理解了您的问题,您希望在另一页中完成操作时更新一个页面,这不是通过 ajax 更新自动完成的。必须通过推送来完成。您在 primefaces 展示中有几个例子:

http://www.primefaces.org/showcase/push/index.jsf

从第一个例子:

<h:form id="form">  
    <h:outputText id="out" value="#{globalCounter.count}" styleClass="ui-widget display" />  

    <br />  

    <p:commandButton value="Click" actionListener="#{globalCounter.increment}" />  
</h:form>  

  <p:socket onMessage="handleMessage" channel="/counter" /> 

bb

   public synchronized void increment() {  
        count++;  

        PushContext pushContext = PushContextFactory.getDefault();  
        pushContext.push("/counter", String.valueOf(count));  
    }  
于 2012-11-06T15:34:31.197 回答