1

I have 2 command buttons and one select one menu. I need to call a bean method depending on the buttons selected and the currently selected item in the menu.

<h:form id="form1">
    <h:outputLabel value="menu:" /> 
    <h:commandButton  value ="en" action="#{bean.exec}" >
        <f:setPropertyActionListener target="#{bean.menu}" value='en' />
    </h:commandButton>
    <h:commandButton value ="fr" action="#{bean.exec}" >
        <f:setPropertyActionListener target="#{bean.menu}" value='fr' />
    </h:commandButton>      

    <h:outputLabel value="id:" />
    <h:selectOneMenu value="#{bean.id}">
        <f:selectItems value="#{bean.idlist}" />
        <f:ajax listener="#{bean.exec}" render ="form1" />
    </h:selectOneMenu>
</h:form>

However, although the first button updates my properties and calls the action method, the second button gives me the following message

WARNING: FacesMessage(s) have been enqueued, but may not have been displayed

and the view doesn't get updated on the fist click. However, immediately on the second click, the properties get updated and so does the view.

How is this caused and how can I solve it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user489152
  • 907
  • 1
  • 23
  • 42
  • Add a `` or read the server log to see those undisplayed messages. They contain the answer to your problem. – BalusC Feb 06 '13 at 16:33
  • I did see the log, however I dont understand the error: this is what it shows: form1:j_idt124: Validation Error: Value is not valid What value and where? What is j_idt?? – user489152 Feb 06 '13 at 16:44
  • If you don't understand something, you should not ignore it, but ask it us. – BalusC Feb 06 '13 at 16:45

1 Answers1

0

I did see the log, however I dont understand the error: this is what it shows: form1:j_idt124: Validation Error: Value is not valid What value and where?

It's easier to identify the value if you give all input components an ID and attach a <h:message> to them as follows:

<h:outputLabel for="id" value="id:" />
<h:selectOneMenu id="id" value="#{bean.id}">
    <f:selectItems value="#{bean.idlist}" />
    <f:ajax listener="#{bean.exec}" render ="form1" />
</h:selectOneMenu>
<h:message for="id" />

This way you will get form1:id as label instead of form1:j_idt124. Alternatively, you can also specify the label of the input component:

<h:selectOneMenu label="id" ... />

As to the "Value is not valid" error, you will get this error when the selected value does not match any one of the available values during processing the form submit. This can in turn happen when the property behind #{bean.idlist} has incompatibly changed during processing the form submit. This can in turn happen when the bean is request scoped. Putting the bean in the view scope should fix it.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555