3

ダイアログを開くアクションを含むprimefacesデータテーブルにコマンドリンクがあります。リンクをクリックすると、常に postconstruct が呼び出されます。

私の要件は、編集に必要な詳細を含むダイアログに更新することです。

部分的なコード スニペット:

<p:dataTable id="sampleMasterListDataTable" var="sampleEntry"
    value="#{sampleMgmtBean.sampleMasterList}" paginator="true" rows="5"
    paginatorAlwaysVisible="false"
    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} 
    {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
    rowsPerPage="5" style="width:600px;">   

     <p:column headerText="Invoice No">
         <h:outputText value="#{sampleEntry.invoiceNo}" />
     </p:column>
     <p:column headerText="Sales Date">
         <h:outputText value="#{sampleEntry.date}">
             <f:convertDateTime pattern="dd-MM-yyyy" />
         </h:outputText>
     </p:column>

     <p:column headerText="Update">
        <p:commandButton id="editSalesLink" value="Edit"
          action="#{sampleMgmtBean.pullSalesDetails(sampleEntry)}"
          update=":tabView:editDialog" process="@this" ajax="true"
          oncomplete="editSalesDialog.show();" />
     </p:column>
</p:dataTable>

ダイアログ コード:

  <p:dialog id="editDialog" header="Update Sales Dialog"
      widgetVar="editSalesDialog" resizable="false" height="500" modal="true">
   <h:form id="sampleMasterEditForm" prependId="false">
      <p:panelGrid columns="8" cellpadding="5" style="width: 650px">
          <h:outputLabel for="editInvoiceNo" value="Invoice:" />
          <p:inputText value="#{sampleMgmtBean.sampleMaster.invoiceNo}"
            id="editInvoiceNo" required="false" label="invoiceNo" />
        <h:outputLabel for="editSalesDate" value="Sales Date:" />
        <p:calendar id="editSalesDate" mode="popup" styleClass="calendar"
            navigator="true" readonly="readonly"
            value="#{sampleMgmtBean.sampleMaster.date}" yearRange="1900:2050"
            pattern="dd/MM/yyyy HH:mm:ss">
        </p:calendar>
     </p:panelGrid>
   </h:form>
 </p:dialog>

Java コード

 @ManagedBean(name="salesMgmtBean") 

 @ViewScoped 

 public class SalesMgmtBean implements Serializable {

      @PostConstruct
  public void init() {
    //new objects
  } 

 }
4

1 に答える 1

0

ボタンには、新しいビューをレンダリングするアクションがあります。jsf はおそらくアクションの結果を「新しいビュー」として解釈し、古いビューの会話がフラッシュされるため、これによりビュー スコープ Bean が再インスタンス化される可能性があります。Bean にはビュー スコープしかないため、新しいものがインスタンス化され、PostContruct インターセプターが実行されます。

ボタンでアクションを呼び出すのではなく、2 つの ActionListener を (次々に) 連鎖させるか、1 つをコントロールに関連付け、もう 1 つをコントロールの子として連鎖させてみてください (f:actionListener)。そうすれば、ビューの遷移が発生しません (これがアクションの原因です)。

アクションメソッドの結果が何であるかを示すために、他の Bean から十分な肉を追加すると、さらに役立ちます。

于 2014-11-04T22:13:41.010 に答える