1

I have a JSF application in which I have a combo box.

<h:selectOneMenu id="collectorType"
                           value="#{activityDataSource.object.type}"
                           rendered="#{empty activityDataSource.object.id}"
                           disabled="#{!sp:hasRight(facesContext, 'ManageApplication')}"
                           readonly="#{!sp:hasRight(facesContext, 'ManageApplication')}"
                           onchange="$('editForm:selectTypeButton').click();">
             <f:ajax event="change" 
                    execute="@this" 
                    render="dsTransformationRule dsCorrelationRule"
                    listener="#{activityDataSource.handleCollectorTypeChange}" />
            <f:selectItem itemValue="" itemLabel="#{msgs.select_collector_type}"/>
            <f:selectItems value="#{activityDataSource.collectorTypes}"/>
          </h:selectOneMenu>

And I am getting selected value of that combo box in bean class like:

public void setSelectedTransformationRule(String transformationRule)
        throws GeneralException {
    String collectorType = (String) getRequestParam().get("editForm:collectorType");
}

And I am successful in doing so. I am calling this method through ajax onchage event of combobox.

But if I try to get same combo box value in a different method i get null value.

public void handleCollectorTypeChange() throws GeneralException {
    String collectorType = (String) getRequestParam().get("editForm:collectorType");
}

Any help !

2 Answers 2

3

Because Process Events happens before Update Model Values you can retrieve the value from the component, from the UIViewRoot like this:

HtmlSelectOneMenu collectorTypeSelectMenu = (HtmlSelectOneMenu) FacesContext.getCurrentInstance().getViewRoot().findComponent("editForm:collectorType");
String collectorType = (String) collectorTypeSelectMenu.getValue();
Sign up to request clarification or add additional context in comments.

Comments

1

try put the attributes process and partialSubmit in your ajax call with the values you need process like this:

<f:ajax event="change" 
   execute="@this" 
   render="dsTransformationRule dsCorrelationRule"
   process="@this, collectorType"
   partialSubmit="true"
   listener="#{activityDataSource.handleCollectorTypeChange}" />

In the process atrribute you can put all ids you need to process with the updated values (like you see in the screen.

1 Comment

There's no process and partialSubmit attributes on <f:ajax .../>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.