I´m trying to send a <select>
value to a JSF managed bean but I don´t know how to make it.
My code is:
<select id="cb-frentes" required="required" jsf:value="#{checkstyleBean.frente}">
<option value=""/>
<ui:repeat var="frente" value="#{appBean.frentes}">
<option value="#{frente}" label="#{frente}"/>
</ui:repeat>
</select>
It does not work. The value of frente
attribute is always null
, when I invoke my action method.
How can I make this bind?
Looks like JSF converts
select
element toh:selectOneListbox
but it doesn't properly convertoption
tags. You should then useh:selectItem
orh:selectItems
, like this:I needed to add size="0" attribute to render the options as drop-down menu. This is because JSF converts select element to h:selectOneListbox which is rendered as a list.
Alternatively, to use HTML5 attributes on JSF element you don't need to convert them to HTML5 tags (pass-through elements). You can use pass-through attributes:
In case of both solutions instead of using
f:selectItem
you can also usef:selectItems
so that you don't needui:repeat
.The
<option>
element is by default not recognized as a passthrough element. It's not listed in table 8.4 of Java EE tutorial chapter 8.9 'HTML5-Friendly Markup'.You'd need to explicitly tell the underlying JSF component. You can do that using the
jsfc
attribute, which is surprisingly not mentioned in the Java EE 7 tutorial (perhaps because it's part of Facelets, the view technology, and not of JSF).Note that I fixed the value of the 1st option to be explicitly
#{null}
, and that I fixed the incorrect way of setting the option label. Further I also addedsize="1"
to the<select>
, otherwise it's by default rendered as a listbox instead of a dropdown.This solution worked for me:
I've used the code above to solve my problem.
SupportedLanguages.java
If the appBean.frentes is list of POJO's you need to use converter in selectOneMenu tag.