-
1. Re: No selected element from <h:selectOneListbox>
jmodadams Jan 11, 2008 12:26 PM (in response to haefti)I believe the problem here is that you have not specified a value attribute in the h:selectOneListbox tag, which is how you bind the selected value to your backing bean.
If you were to add a video property to your manager bean with a public setter method, you could then do the following:<h:selectOneListbox size="10" value="#{manager.video}"> <s:selectItems value="#{videos}" var="video" label="#{video.name}" /> <s:convertEntity /> </h:selectOneListbox> <h:commandButton type="submit" action="#{manager.editVideo()}" value="Change"></h:commandButton>
Also, make sure that the listbox and commandButton components are wrapped inside of an <h:form> tag or the values will not be posted to the server upon submission. -
2. Re: No selected element from <h:selectOneListbox>
haefti Jan 14, 2008 6:21 AM (in response to haefti)Hi!
First of all thanks for the answer!"jmodadams" wrote:
I believe the problem here is that you have not specified a value attribute in the h:selectOneListbox tag, which is how you bind the selected value to your backing bean.
If you were to add a video property to your manager bean with a public setter method, you could then do the following:
Okay, I thought I could inject it via @In or @DataModelSelection or something similar.
My managerAction now looks like this:@Stateless @Name("manager") public class ManagerAction implements Manager{ @Logger Log log; private Video selVideo; public Video getselVideo() { return selVideo; } public void setSelVideo(Video selVideo) { this.selVideo = selVideo; } public String editVideo () { log.info("selected video Id: " + selVideo.getVideoId()); return "edit"; } . . . }
the hello.xhtml contains this code:<h:form> <h:selectOneListbox size="10" value="#{manager.selVideo}"> <s:selectItems value="#{videos}" var="video" disabled="#{video.videoId < 25000 ? true : false}" label="(#{video.datum}) #{video.videoId} - #{video.thema}: #{video.headline}" /> <s:convertEntity /> </h:selectOneListbox> <h:commandButton type="submit" action="#{manager.editVideo()}" value="Ändern"></h:commandButton> </h:form>
and I added this to my pages.xml:<page view-id="/hello.xhtml"> <navigation from-action="#{manager.editVideo}"> <rule if-outcome="edit"> <redirect view-id="/edit.xhtml"/> </rule> </navigation> </page>
but if I choose an item from the list and press the button I still get back to the hello.xhtml and do not get the log output of the editVideo() method.
If I don't choose anything and press the button I get an (expected) NullPointerException from the method editVideo() because selVideo is null can not be logged.
Any idea?
Thanks!
Haefti -
3. Re: No selected element from <h:selectOneListbox>
nickarls Jan 14, 2008 6:26 AM (in response to haefti)drop the () from the editVideo() action in the button
-
4. Re: No selected element from <h:selectOneListbox>
haefti Jan 14, 2008 7:28 AM (in response to haefti)"nickarls" wrote:
drop the () from the editVideo() action in the button
Thanks but that does not change anything.
The log output after clicking the button is:13:19:40,096 INFO [STDOUT] Hibernate: select video0_.videoId as videoId123_, video0_.picturesId as picturesId123_, vide o0_.datum as datum123_, video0_.status as status123_, video0_.videocatId as videocatId123_, video0_.name as name123_, vi deo0_.thema as thema123_, video0_.headline as headline123_, video0_.teaser as teaser123_, video0_.modificationDate as mo dific10_123_, video0_.mediaId as mediaId123_, video0_.typ as typ123_, video0_.width as width123_, video0_.height as heig ht123_, video0_.credit as credit123_, video0_.flags as flags123_, video0_.videoDisplayCatId as videoDi17_123_, video0_.e xpireDate as expireDate123_ from SPC_VIDEO video0_ where video0_.datum>? 13:19:40,268 INFO [ManagerAction] showVideoList1 13:19:40,284 INFO [STDOUT] Hibernate: select video0_.videoId as videoId123_0_, video0_.picturesId as picturesId123_0_, video0_.datum as datum123_0_, video0_.status as status123_0_, video0_.videocatId as videocatId123_0_, video0_.name as na me123_0_, video0_.thema as thema123_0_, video0_.headline as headline123_0_, video0_.teaser as teaser123_0_, video0_.modi ficationDate as modific10_123_0_, video0_.mediaId as mediaId123_0_, video0_.typ as typ123_0_, video0_.width as width123_ 0_, video0_.height as height123_0_, video0_.credit as credit123_0_, video0_.flags as flags123_0_, video0_.videoDisplayCa tId as videoDi17_123_0_, video0_.expireDate as expireDate123_0_ from SPC_VIDEO video0_ where video0_.videoId=? 13:19:40,393 INFO [[/simple_video]] resource bundle messages could not be found
The first entry is the SQL which fills the select box.
The second one is a debug output from the corresponding method but the third entry could be the SQL I need as you can see in the end ("where video0_.videoId=?").
Unfortunately no further indication for the method call editVideo() is here.
Can the last entry with the missing resource bundle be my solution? -
5. Re: No selected element from <h:selectOneListbox>
nickarls Jan 14, 2008 7:38 AM (in response to haefti)Do you have a messages tag to see validation errors? (although you should see them in the log, too).
Tried putting a change listener on the select box?
The last sql is probably from the entityConverter... -
6. Re: No selected element from <h:selectOneListbox>
haefti Jan 14, 2008 7:58 PM (in response to haefti)"nickarls" wrote:
Do you have a messages tag to see validation errors? (although you should see them in the log, too).
I inserted a <h:messages /> and get a "validation failed" but I have no idea what kind of validation Seam is doing here.
Do I get it right that I can expect an object of the same type as the the collection for the select box contains of as selected element?
In this case I don't know why I get an validation error.Tried putting a change listener on the select box?
Is it necessary? I hope I can get the selected element without itThe last sql is probably from the entityConverter...
Okay. -
7. Re: No selected element from <h:selectOneListbox>
nickarls Jan 15, 2008 1:55 AM (in response to haefti)Nope, the listener would just have been from debug purposes.
Try overriding equals() and hashCode() on your entity. Seam gets upset when the entity is not in the options list (as determined by the said functions) -
8. Re: No selected element from <h:selectOneListbox>
haefti Jan 15, 2008 3:00 AM (in response to haefti)You made my morning! ;)
Thanks a lot!
Overriding the two methods solved the problem. I couldn't figure that out.
Be prepared for more newbie questions! ;) -
9. Re: No selected element from <h:selectOneListbox>
nickarls Jan 15, 2008 3:10 AM (in response to haefti)Heh, it's a case of "The blind leading the blind" here but glad I could help.
I've run into the same trap myself. It's really a JSF issue more than a Seam issue but it comes up often in the convertEntity case so it could be worth a note in the documentation under 29.1...