0

I'm trying to set an object in p:selectOneMenu and show that object in a p:dialog.

Menu:

<p:form id="form1">
<p:selectOneMenu value="#{bean.entity}" immediate="true">
    <f:selectItems value="#{bean.entities}" var="ent" itemLabel="#{ent.name}" itemValue="#{ent}" />
</p:selectOneMenu>
<p:commandButton value="Submit" oncomplete="PF('dlg').show();" update=":form2" />
</p:form>

Dialog:

<p:dialog header="Title" widgetVar="dlg" modal="true">
    <p:form id="form2">
        <p:outputLabel id="component" value="#{bean.entity.name}" />                        
    </p:form>
</p:dialog> 

But unfortunately the dialog remains empty, so the entity has not been set after clicking the button. I don't get any errors.


When I set the entity directly in the bean, it appears in the dialog.

Class: Bean

// getter & setter

entity = entities.get(1);
Selaron
  • 6,105
  • 4
  • 31
  • 39
Evgenij Reznik
  • 17,916
  • 39
  • 104
  • 181
  • Is this problem appears just after accessing your page and clicking the Submit button, or even after making some changes in the selectOneMenu component ? – Ahmed HENTETI Nov 22 '19 at 12:34
  • ·@A.Henteti: I selected a value in the `selectOneMenu` and clicked the commandButton. The Dialog appears but without the just selected value in the `selectOneMenu`. – Evgenij Reznik Nov 22 '19 at 23:10
  • And if you run your application in development mode, you don't get any errors? And it works without a dialog? – Kukeltje Nov 23 '19 at 16:45
  • Does this answer your question? [How to populate options of h:selectOneMenu from database?](https://stackoverflow.com/questions/6848970/how-to-populate-options-of-hselectonemenu-from-database) – Kukeltje Nov 23 '19 at 16:47
  • And please always try to create a [mcve]... it helps you narrow things down and us finding a cause. Sometimes it even helps you finding a cause or a 'duplicate' answer – Kukeltje Nov 23 '19 at 17:55

1 Answers1

0

As you are using custom class in your selectOneMenu and not simple String, you need custom converter.

Check out this tutorial which explains how to achieve that.

Ahmed HENTETI
  • 1,108
  • 8
  • 18
  • Like here: https://stackoverflow.com/questions/6848970/how-to-populate-options-of-hselectonemenu-from-database – Kukeltje Nov 23 '19 at 16:47