0
votes

I have a JSF composite component which includes as a root an h:form. The form has many components among of which are selectOneMenu and a h:inputFile. When I set enctype="multipart/form-data" on the form, the valuechangelistener of the selectOneMenu is invoked ONLY for two value-changing events. Later, however I interact with the menu, the value change listener is not invoked at all. However, if I remove the enctype="multipart/form-data" every thing works fine. I have to keep enctype="multipart/form-data" because I have a file upload component.

Here is my Bean :

@Model
@ViewScoped
public class TransactionBean implements Serializable {
   private Part inReceiptFilePart;
   /*setter and getter*/ 


   private TransactionType transactionType;
   /*setter and getter*/    

      private final TransactionType transTypeList[] = {
  TransactionType.COMPLETE,TransactionType.TECHNICAL,TransactionType.SUBMUNICIPALITY_TECHNICAL, TransactionType.COMPLAINT,        TransactionType.FOLLOWUP_COUNCIL,                TransactionType.FOLLOWUP_MANAGEMENT
};
   public TransactionType[] getTransTypeList() {
    return transTypeList;
}

  public void transactionTypeChanged(ValueChangeEvent event) {
    ... /// some code
}
}

And here is the JSF composite component :

 <h:form id="entryForm" enctype="multipart/form-data"> 
     <p:selectOneMenu id="transType" value="#{transactionBean.transactionType}" style="direction: ltr"  valueChangeListener="#{transactionBean.transactionTypeChanged}">
                        <f:ajax execute="transType"  render="@form" > </f:ajax>                            
                        <f:selectItems value="#{transactionBean.transTypeList}" var="tt" itemLabel="#{tt.arName}">

                        </f:selectItems>                            
                    </p:selectOneMenu>
        <h:inputFile value="#{transactionBean.inReceiptFilePart}" > </h:inputFile>
        <p:commandButton id="insertTrans" value="أدخل المعاملة" action="#{transactionBean.insertTransaction}" ajax="false">
        </p:commandButton>      
 </h:form>

The environment is JSF 2.2, Glassfish 4.0 and primefaces 3.5.

Please help me. I am stuck for three days on this problem.

Thanks

1

1 Answers

0
votes

This is very strange behavior!

Try changing valueChangeListener event to an AJAX call.

 <p:selectOneMenu id="transType" value="#{transactionBean.transactionType}" style="direction: ltr" >
       <p:ajax event="change" partialSubmit="true" update="@form" listener="#{transactionBean.transactionTypeChanged}"/>               

        <f:selectItems value="#{transactionBean.transTypeList}" var="tt" itemLabel="#{tt.arName}" />                           
 </p:selectOneMenu>

Primefaces's AJAX component is behavior component that extends JSF AJAX. It adds and manages new events (e.g. valueChange); it also reattach javascript events to DOM element automatically.

Your case is that jsf's ajax does not rebind the valueChange Listener to "transType" selectOneMenu when the form is mutipart! (It's very strange, because the behavior should be the same of those ajax event, weather the form is mutipart or www-form-encoded!