0

I have a selectOneListbox that, when clicked, should pass an additional parameter (id) to the server. As it is now, the user sees a list of names and when they select one I can get the name. But, each name also has a unique id associated with it that I don't want the user to see - how can I pass the unique id of the selected name to the backing bean without the user ever seeing it? Is it possible? I was trying to figure out how to use the f:param but I don't see how that will work here.

                <h:selectOneListbox id="listBox" value="#{ScheduleMB.clients}" size="5"  
                rendered="#{ScheduleMB.showClients}" >
                    <f:selectItems value="#{ScheduleMB.clientList}" var="c"
                        itemLabel="#{c.lastName} #{', '} #{c.firstName}" itemValue="#{c.lastName}" />
                    <f:ajax event="click" listener="#{ScheduleMB.clickListener}"  
                        render="group" />
                </h:selectOneListbox>
Dave
  • 545
  • 3
  • 14
  • 29
  • Is there any reason you are not setting the value to the ID associated with the name? Or do you want the ID to not be anywhere on the page(even hidden in the source of the HTML)? – Lipongo Sep 07 '12 at 17:43
  • There is a possibility that last name + first name might not be unique so I prefer the id. I don't want the id seen because 1) the user might fool with it 2) I think it's unsightly. Therefore I want to use the id but I'm not sure of the best way to send it back using jsf. – Dave Sep 07 '12 at 21:43

1 Answers1

1

The <f:param> serves a different purpose. Even if the <f:param> was possible, it would still end up being visible in the generated HTML output. The enduser would just do rightclick and View Source and then see the IDs being definied as option values.

Your best bet is to retrieve the ID from the DB based on a different unique identifier, perhaps the unique combination of firstname+lastname.

It does by the way not make any sense to me why you would like to hide the ID from the output. It'd be so much easier if you used that as option value, even more if you used a converter so that you can just pass the whole #{c} as option value. The enduser can't spoof/change it in any way. JSF will revalidate the submitted value against the list of available options (which are definied in server side anyway).

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks for replying. Unfortunately, the firstname+lastname might not be unique so I want to use the numeric id associated with each client, and is in the #{c} object. Not sure I entirely understand the last part of your answer - I'm still a jsf newbie. Passing the entire #{c} object would be good, but how would I do that and still show the list of clients? – Dave Sep 07 '12 at 21:31
  • You can do that using a `Converter`. See also example #2 from this answer: http://stackoverflow.com/questions/6848970/how-to-prepopulate-a-hselectonemenu-from-a-db/6850681#6850681 – BalusC Sep 07 '12 at 22:34
  • BalusC, that seems to be it. Thanks. – Dave Sep 08 '12 at 16:49
  • Note that you still end up with the ID being visible in the generated HTML output. I'm not sure if that is what you want. If you rather mean that you don't want it to show up in the UI, but that you don't care if it's in the HTML source, then just go ahead (and in the future, be careful how you state this restriction in the question). – BalusC Sep 08 '12 at 16:58
  • I don't want the ID to be visible but, if I'm not mistaken, I can avoid that by using converter if I use it correctly. – Dave Sep 08 '12 at 18:37