2016-11-21 8 views
0

私はViewScopedであるマネージドBeanを持っています。このBeanでは、フォームを送信する必要があります(h:commandButtonを使用)。 これは、ドロップダウンメニューのエントリ(イベントを発生させてページを更新する)を変更する場合を除いて、正常に動作します。 ドロップダウンメニューの値を変更した後、フォームを送信すると、Beanが再作成されます(h:commandButtonに関連付けられたアクションはスキップされます)。ここでフォームアクションを呼び出す代わりにViewScoped Beanを再作成

は私のXMLです:

<rich:panel styleClass="panel_grid_center fifty_percent" 
     header="Bid matrix"> 

     <!-- display in case the user is not an admin --> 
     <h:panelGroup rendered="#{not loginBean.isAdmin}"> 

      <h:outputText 
       value="You do not have sufficient permission to view this page." /> 
      <br /> 
      <h:form> 
       <h:commandLink action="index.xhtml" 
        value="Click here to go back to login page/search page." /> 
      </h:form> 
     </h:panelGroup> 

     <!-- display if the user is an admin --> 
     <h:panelGroup rendered="#{loginBean.isAdmin}" id="bid_matrices_panel"> 
       <h:panelGrid columns="2"> 

        <!-- customer group panel --> 
        <rich:panel styleClass="contained_width fifty_percent" 
         header="Customer group"> 
         <h:form> 
          <h:selectOneMenu 
           valueChangeListener="#{adminBean.onCustomerGroupChangeListener}" 
           value="#{adminBean.customerGroupService.displayCustomerGroup.spendMinimum}"> 
           <f:selectItems 
            value="#{adminBean.customerGroupService.customerGroups}" 
            var="group" itemLabel="#{group.customerGroupLabel}" 
            itemValue="#{group.spendMinimum}" /> 
           <a4j:ajax event="valueChange" execute="@this" 
            render="bid_matrices_panel" /> 
          </h:selectOneMenu> 
         </h:form> 
        </rich:panel> 

        <!-- repeatables --> 
        <rich:panel styleClass="contained_width fifty_percent" 
         header="Repeatables"> 
        </rich:panel> 
       </h:panelGrid> 

       <h:form> 
        <!-- we loop on each different commoditization (or however that's spelled) --> 
        <a4j:repeat var="bidmatrix_by_commoditization" 
         value="#{adminBean.bidMatrices}"> 
         <rich:dataTable styleClass="contained_width" 
          value="#{bidmatrix_by_commoditization.bidMatricesByCoreStatus}" 
          var="matrix_by_core_status"> 


          <!-- Display core status --> 
          <rich:column> 
           <f:facet name="header"> 
            <h:outputText 
             value="#{bidmatrix_by_commoditization.commoditization}" /> 
           </f:facet> 
           <h:outputText value="#{matrix_by_core_status.coreStatus}" /> 
          </rich:column> 

          <!-- the percentages --> 
          <c:forEach var="index" begin="0" 
           end="#{adminBean.columnsNumber - 1}"> 
           <rich:column> 
            <f:facet name="header"> 
             <h:outputText value="#{adminBean.columnsHeaders[index]}" /> 
            </f:facet> 
            <h:inputText 
             value="#{matrix_by_core_status.bidMatrices[index].percentage}"> 
             <f:convertNumber type="percent" /> 
            </h:inputText> 
           </rich:column> 
          </c:forEach> 
         </rich:dataTable> 
        </a4j:repeat> 

        <br /> 

        <!-- update matrix button --> 
        <h:commandButton value="Update" action="#{adminBean.update}" /> 
       </h:form> 
     </h:panelGroup> 
    </rich:panel> 

マイ豆:私が正しくjavax.faces.bean.ViewScoped; からViewScopedをインポート

@ManagedBean(name = "adminBean") 
@ViewScoped 
public class AdminBean implements Serializable { 

    /** 
    * 
    */ 
    private static final long serialVersionUID = 5917562235108703019L; 

    private CustomerGroupService customerGroupService; 
    private BidMatrixDao bidMatrixDao; 
    private List<BidMatricesByCommoditization> bidMatrices; 

    @PostConstruct 
    public void init() { 
     customerGroupService = new CustomerGroupService(); 
     bidMatrixDao = new BidMatrixDaoImpl(); 
     bidMatrices = bidMatrixDao.getBidMatricesByCustomerGroup(customerGroupService.getDisplayCustomerGroup()); 
    } 

    public void onCustomerGroupChangeListener(ValueChangeEvent v) { 
     customerGroupService.setDisplayCustomerGroup((BigDecimal) v.getNewValue()); 
     bidMatrices = bidMatrixDao.getBidMatricesByCustomerGroup(customerGroupService.getDisplayCustomerGroup()); 
    } 

    public CustomerGroupService getCustomerGroupService() { 
     return customerGroupService; 
    } 

    /** 
    * @param customerGroupService 
    *   the customerGroupService to set 
    */ 
    public void setCustomerGroupService(CustomerGroupService customerGroupService) { 
     this.customerGroupService = customerGroupService; 
    } 

    /** 
    * @return the bidMatrices 
    */ 
    public List<BidMatricesByCommoditization> getBidMatrices() { 
     return bidMatrices; 
    } 

    /** 
    * @param bidMatrices 
    *   the bidMatrices to set 
    */ 
    public void setBidMatrices(List<BidMatricesByCommoditization> bidMatrices) { 
     this.bidMatrices = bidMatrices; 
    } 

    public int getColumnsNumber() { 
     return bidMatrices.get(0).getColumns(); 
    } 

    public List<String> getColumnsHeaders() { 
     return bidMatrixDao.getAlignments(); 
    } 

    public void update() { 
     bidMatrixDao.updateBidMatrices(bidMatrices); 
    } 
} 

注意私も豆からゲッター/セッターを削除しますが、彼らはそこにあります。 私が言ったように、フォームは、h:selectOneMenu値を変更せずに送信したときにうまく機能します。

ありがとうございました!

編集:私は、JSF 2.2(クロサギ科)を使用しています、私は私のAjaxのディレクティブで使用されるIDを移動することで、これを固定wildfly 10.1

+0

のJSFのimplとバージョンを忘れていた

かなり確信して? Richfacesバージョン? – Kukeltje

+0

JSF 2.2はAPI仕様であり、JSF実装およびバージョンではありません。 Wildfly 10.1が使用しますか? – Kukeltje

答えて

0

で、4.1 RichFacesの:

<a4j:ajax event="valueChange" execute="@this" render="bid_matrices_panel" /> 

私はもともと置きますこのような親panelGroup内のid、:

<h:panelGroup rendered="#{loginBean.isAdmin}" id="bid_matrices_panel"> 

豊富作成することにより:私は実際に再度レンダリングしたい部分の周りのパネルは、私の問題は修正されています

<h:form> 
    <rich:panel id="bid_matrices_panel"> 
     <! -- my data to render --> 

    </rich:panel> 

    <h:commandButton value="Update" action="#{adminBean.update}" /> 
</h:form> 

フォームの再レンダリングが問題の原因だったと思います。私が前にあることを試してみましたが、その時に私も...私のAdminBean上implements Serializable

関連する問題