0

I really need your help please. First of all, I want to let you know that I am a beginner in JSF.

I've got a form with several parameters. The flowtype field has 2 options : Sync and async. At the first launch, I am able to get the source value but When it pass to async I am doing a query to database so as to populate the source, datatype... by using ajax and it's working very well but I am not anymore able to retrieve the value of selectOneMenu. I got an error validation...

this is my form :

<h:form id="monitoring_form">
   <p:growl id="msgs" showDetail="true" />

       <p:panel header="Select a Location" style="margin-bottom:10px;">

       <p:outputLabel id="flowType_label" value="Flow Type : "/>
       <h:selectOneMenu id="flowType_select" value="#{monitoringBean.flowType}">
            <p:ajax listener="#{monitoringBean.onFlowTypeChange}" process="@this" update="source_select,:monitoring_form:dataType_select" />
            <f:selectItem itemLabel="Select a flow type" itemValue="" noSelectionOption="true" />
            <f:selectItem itemValue="async" itemLabel="ASYNC" />
            <f:selectItem itemValue="sync" itemLabel="SYNC" />
      </h:selectOneMenu>

      <p:outputLabel id="source_label" value="Source"/>
            <h:selectOneMenu id="source_select" value="#{monitoringBean.source}">
            <f:selectItem itemLabel="ALL" itemValue=""/>
            <f:selectItems value="#{monitoringBean.resultSource}"/>
      </h:selectOneMenu><br/>

      <p:outputLabel id="dataType_label" value="Datatype : "/>
            <h:selectOneMenu id="dataType_select" value="#{monitoringBean.dataType}">
            <f:selectItem itemLabel="ALL" itemValue="" noSelectionOption="true"/>
            <f:selectItems value="#{monitoringBean.resultDataType}"/>
            </h:selectOneMenu>

    <p:commandButton ajax="false" id="submit" actionListener="#{monitoringBean.buttonAction}" value="Submit" type="submit" icon="ui-icon-check" />
    <p:commandButton value="Reset" type="reset" icon="ui-icon-close"/>

    </p:panel>
</h:form>

this is my onFlowChangeValue :

public void onFlowTypeChange(AjaxBehaviorEvent event) throws SQLException {
    if (flowType != null && !flowType.equals("") && !flowType.equals("sync")) {
        addMessage("Welcome to Primefaces!!" + " source : " + source);
        selectSourceApplicationFromTable(); // -> add to resultSource list of selectItem..
        selectDataTypeFromTable(); // ->add to resultDataType list of selectItem..
    }
}

I check the flowTypeValue and I do a request to my database so as to populate the selectOneMenu.

This is my button submit action method :

public void buttonAction(ActionEvent actionEvent) {
    addMessage("Welcome to Primefaces!!" + " source : " + source);
    System.out.println("Source : " + source);
}

Firstly without using the form just pressing Submit I got : ""Welcome to Primefaces!!" + " source : " + null" fine. But when i change the flowtype value I got an error when submitting.

How can I get the selectOneMenu value ? Why it's not accessible by using my bean #{monitoringBean.source} ?

PS: I used this tutorial : http://www.primefaces.org/showcase/ui/ajax/dropdown.xhtml

Thanks.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
scamp
  • 381
  • 2
  • 5
  • 14
  • 1
    In most cases, problems like this occur from the scope of your bean. Usually changing to Sessionscope fixes the problem. Can you post a little more details about the validation error that you are getting? – stolen_leaves Feb 27 '15 at 11:28
  • I'll try to change my bean's scope. I got this error "monitoring_form:source_select : erreur de validation. La valeur est incorrecte."Basically it means validation error. the value is incorrect – scamp Feb 27 '15 at 13:00
  • I've changed my bean's scope to Session as you've suggested and it works fine. You really saved my day !! – scamp Feb 27 '15 at 13:03
  • What was your original scope? Requestscoped? Then maybe viewscoped or the codi ViewAccessScoped would be a better fit than SessionScoped. Putting everything in SessionScoped just because it works is not good – Kukeltje Feb 27 '15 at 23:19
  • When facing error messages you don't understand, try changing dev/run environment to English first so that you get the error message in the original English format. When copypasting the exact English error message into some search engine (Google or here), then it will yield MANY MORE successful hits in search results. – BalusC Feb 28 '15 at 14:19
  • The initial scope was requestscope. I need to learn more about scope. – scamp Mar 01 '15 at 00:52
  • I am sorry BalusC but I'll put the error message in english the next time – scamp Mar 01 '15 at 00:53

0 Answers0