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毎回更新するだけで、リストが以前よりも 1 つ長くなり、その新しいオブジェクトがあることも確認します。dataTable には、新しいオブジェクトがなくても古いデータが表示されます。なぜですか?

--------新しい 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

dataTable の value-attribute はセッション スコープ内にあるため、datatable はこのセッションの最初のリクエストでのみレンダリングされます (このビューを手動で更新しない場合)。

ビューにはビュー スコープ Bean を使用します。このリストをセッション スコープにする必要がある場合は、セッション スコープの Bean からビュー スコープの Bean にリストを挿入するだけです。

于 2012-11-06T14:23:10.177 に答える
0

他の方法では収まらなかったので、本当のバブルガム ソリューションを作成しました。Bean をセッションに再度書き込むだけなので、「rmapapu」という名前の古いものを上書きします。いいえ、動作しています。結果はありますか、それともこれは本当に悪い考えですか?

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

みんな助けてくれてありがとう。それについてのBalusCチュートリアルをまだ読んでいます.

サーミ語

于 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 に答える