0

I'm learning JSF/JPA by creating a virtual bank website. I have some Clients, who have many Accounts.

So I tried this:

<h:selectOneMenu>
     <f:ajax/>
     <f:selectItems value="#{loginMBean.client.accountsList}" 
            var="c"/>
</h:selectOneMenu>

<h:outputText value="${c.numAccount}" />

While this perfectly displays the list of accounts, it doesn't print the number of the account, even when I change the value of the select box. What am I doing wrong?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Rob
  • 15,732
  • 22
  • 69
  • 107
  • I added `[selectonemenu]` tag to the question. Put your mouse on top of it until a black box shows up. Click therein the *info* link. That's the tag wiki page. Work through it in order to lean how to properly use ``. Then please review/reframe your question so that the ajax update problem can better be answered without the need to write down a whole `/` tutorial as answer because you didn't bother to go through a real JSF book first. – BalusC Jan 26 '14 at 20:28

1 Answers1

0

The var "c" doesn't exist outside of <h:selectOneMenu> tags, that's why the account's numbers cannot be displayed there. If your question is to display the account's numbers the same as the current account displaying, then, you can specify the desired field in itemLabel's attribute to be displayed within <h:selectOneMenu>, something like this:

<h:selectOneMenu>
    <f:ajax/>
    <f:selectItems value="#{loginMBean.client.accountsList}" var="c" itemLabel="#{c.numAccount}"/>
</h:selectOneMenu>
Omar
  • 1,430
  • 1
  • 14
  • 31
  • you should probably specify the itemValue attribute as well if you want the selectItem to be saved. – elbuild Jan 26 '14 at 20:21
  • Well thanks for the explanation. What I want to do is to use the current selection of the select box outside of it. – Rob Jan 26 '14 at 20:24
  • Look at this good reply of M. @BalusC about this need : http://stackoverflow.com/a/6090675/2459449 – Omar Jan 26 '14 at 21:30