I am using Bootsfaces 1.0.2. The code below, of course, is inside a form. Notice the first selectItem has an itemValue=#{null}. When the page loads, the inputText field with id='test' shows as blank. I then change the dropdown to any other value and the value displays correctly. When I go back to the first option in the drop down with null value, the inputText field displays "-- Seleccione --". What I would expect to see is blank (NULL), right? Or am I missing something here?
<b:selectOneMenu value="#{wCPVMController.wcpvm.tipo_v}"
id="categoriaVehiculo" label="CategorĂa de VehĂculo"
required="true" process="#this" update="containerRiesgos test"
onchange="ajax:wCPVMController.getRiesgosOpcionales()">
<f:selectItem itemLabel="-- Seleccione --" itemValue="#{null}" />
<f:selectItem itemLabel="Liviano" itemValue="L" />
<f:selectItem itemLabel="Pesado" itemValue="P" />
<f:selectItem itemLabel="Autobus" itemValue="A" />
<f:selectItem itemLabel="Motocicleta" itemValue="M" />
<f:selectItem itemLabel="Otro" itemValue="O" />
</b:selectOneMenu>
<b:inputText id="test" value="#{wCPVMController.wcpvm.tipo_v}"></b:inputText>
Write instead itemValue=""
See example here:
https://showcase.bootsfaces.net/forms/selectOneMenu.jsf
Related
I use selectize search on jsf, firstly i chose a value from the dropdown and then when I clear it from the writing area, the selected value remains the same. But i want to set the selected value null after clear value on the text search field. This is the code down below:
Note: I tried itemValue="#{null}" and hideNoSelectionOption on selectOneMenu
<h:selectOneMenu id="nameID" styleClass="select form-control chosen-select search selectize-search" value="#{bean.name}" required="false" requiredMessage="Please choose one">
<f:selectItem itemValue="" itemLabel="None" itemDisabled="false" noSelectionOption="true"/>
<f:selectItems value="#{bean.nameList}" />
</h:selectOneMenu>
I need to display No Jurisdiction to add in the Jurisdiction dropdown when the given condition satisfies.[condition:When there is no Jurisdiction available,it should display the above text in dropdown.If there are jurisdictions available,the above text should not be displayed].And I dont want to make it disabled.
The problem i am facing is whether it does or does not displays No Jurisdiction to add irrespective of the condition provided.
<p:selectOneMenu id="JurisdictionName"
value="#{ApplicationManagedBean62.saveRequestMap['Jurisdiction']}"
<f:selectItem itemLabel="Select" itemValue="" />
<c:if test="#{empty ApplicationManagedBean62.knowledgeValueMap['Object::AddJurisdictionStatelist']}">
<f:selectItem itemLabel="No Jurisdiction to add" itemValue="" />
</c:if>
<f:selectItems
value="#{ApplicationManagedBean62.knowledgeValueMap['Object::AddJurisdictionStatelist']}"
var="Jurisdiction"
itemLabel="#{Jurisdiction['StateRegionCode']}"
itemValue="#{Jurisdiction['StateRegionCode']}" />
</p:selectOneMenu>
I also tried,
<ui:fragment rendered="#{empty ApplicationManagedBean62.knowledgeValueMap['Object::AddJurisdictionStatelist']}">
<f:selectItem itemLabel="No Jurisdiction to add" itemValue="No Jurisdiction to add" />
</ui:fragment>
Kindly help me out.
You can't do it like that you have 2 choices.
Use itemDisabled="true" or noSelectionOption="true" on items you don't want selectable and they will be greyed out. See: https://javaee.github.io/glassfish/doc/5.0/vdldoc/f/selectItem.html
Generate your selectItems server side and filter out the ones you know should not be there like this...
<f:selectItems value="#{myBean.jurisdictions}" var="type" itemLabel="#{type.displayText}" itemValue="#{type}" />
I have a selectOneMenu and the issue with it is that it updates the value twice!! first time with the value I chose, immediately after that it updates the value with the number it previously had!
<p:selectOneMenu id="qupdate" value="#{object.pquantity}">
<f:selectItem styleClass="form-control"
itemLabel="-- SELECT QUANTITY -- " itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{selectonemenu.quantoptions}" var="f"
itemLabel="#{f}" itemValue="#{f}" />
<p:ajax execute="qupdate" event="change"
listener="#{Bean.quantitychange(object.pquantity, object.id)}" />
</p:selectOneMenu>
is there anyway to have this working, I have tried to trace and it actually calls the setter twice!
#Holger is correct in the comments. p:selectOneMenu does not require a listener to actually process the value change. One should use a listener only to actually make other kind of interactions in the bean.
In this case, the fixed code should look like this:
<p:selectOneMenu id="qupdate" value="#{object.pquantity}">
<f:selectItem styleClass="form-control"
itemLabel="-- SELECT QUANTITY -- "
itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{selectonemenu.quantoptions}"
var="f"
itemLabel="#{f}"
itemValue="#{f}" />
</p:selectOneMenu>
For more information about how the ajax listener is supposed to be used, please refer to to this question.
I have a select menu like this :
<h:selectOneMenu value="#{serverMB.selectedServerType}" >
<f:converter binding="#{serverTypeConverter}"/>
<f:selectItems value="#{serverMB.serverTypesList}" var="servertypes"
itemLabel="#{servertypes.server_type_name}" />
<f:ajax listener="#{serverMB.changeSelectedOneMenuServerType}" render="selectservertype"/>
</h:selectOneMenu>
I want the default value of the select menu to be the value of one object that has been filled before, something like this:
<h:selectOneMenu value="#{serverMB.selectedServerType}" default="serverMB.server.servertype"> // <- default
or like this:
<h:selectOneMenu value="#{serverMB.selectedServerType}">
<f:converter binding="#{serverTypeConverter}"/>
<f:selectItem value"serverMB.server.servertype"/> <- but this item was the first one and has been selected
<f:selectItems value="#{serverMB.serverTypesList}" var="servertypes"
itemLabel="#{servertypes.server_type_name}" />
</h:selectOneMenu>
You can do something like this if your object is already populated when you call the page, if it is not, it will show the <f:selectItem/> message:
<h:selectOneMenu value="#{serverMB.server.servertype}">
<f:converter binding="#{serverTypeConverter}"/>
<f:selectItem itemLabel="Select a Server..." />
<f:selectItems value="#{serverMB.serverTypesList}" var="servertypes"
itemLabel="#{servertypes.server_type_name}"/>
<f:ajax listener="#{serverMB.changeSelectedOneMenuServerType}"
render="selectservertype"/>
</h:selectOneMenu>
You can also use the OmniFaces converter.
Here is my example. It works fine for me. (Note: Year is a object. Make sure, you have equals implemented. Year is name and id only.)
<h:selectOneMenu value="#{bean.user.year}"
converter="omnifaces.SelectItemsConverter">
<f:selectItem itemLabel="Please select a year." itemValue="#{null}"
noSelectionOption="true" />
<f:selectItems value="#{bean.allyears}" var="year"
itemValue="#{year}" itemLabel="#{year.name}" />
</h:selectOneMenu>
I am new to JSF and i am stuck at one place. I have one dropdown list which contains two items.
Bank
Cash
Now, if I select bank the other dropdown should populate items related to bank and if I select cash, cash items should be shown in 2nd dropdown.
How to do it in JSF? Where I have to make changes?
Any help will be highly appreciated.Thanks
Well you can use primefaces to improve jsf development
<p:selectOneMenu id="cboCountries" value="#{beanCountries.ValueSelected}" effect="fade">
<f:selectItem itemLabel="Select Country" itemValue="-1" /> //a default value
<f:selectItems value="#{beanCountries.listOfCountries}" var="countries" itemLabel="#{countries.name}" itemValue="#{countries.id}"/>
<p:ajax event="change" update="cboCities" listener="beanCountries.listCities()"/> //notice "update" refresh an especific DOM Element of an especific ID
</p:selectOneMenu>
<p:selectOneMenu id="cboCities" value="#{beanCities.ValueSelected}" effect="fade">
<f:selectItem itemLabel="Select City" itemValue="-1" /> //a default value
<f:selectItems value="#{beanCities.listOfCities}" var="cities" itemLabel="#{cities.name}" itemValue="#{cities.id}"/> //this is when you want to put elements from DB or from an Array
</p:selectOneMenu>
" is a special mark from primefaces, the event = "change" will invoke the you select an element from the first "ComboBox" then the property update will refresh the second comboBox, and the property "listener" will do the logical action of what you want to do, in this case the method "listCities()" will fill "listOfCities" with values from DB o Arrays.
So in jsf without primefaces will be like this:
<h:form>
<h:selectOneMenu value="#{beanCountries.ValueSelected}">
<f:selectItem itemLabel="Select Country" itemValue="-1" /> //a default value
<f:selectItems value="#{beanCountries.listOfCountries}" var="countries" itemLabel="#{countries.name}" itemValue="#{countries.id}"/>
</h:selectOneMenu>
<h:selectOneMenu id="cboCities" value="#{beanCities.ValueSelected}">
<f:selectItem itemLabel="Select City" itemValue="-1" /> //a default value
<f:selectItems value="#{beanCities.listOfCities}" var="cities" itemLabel="#{cities.name}" itemValue="#{cities.id}"/> //this is when you want to put elements from DB or from an Array
</h:selectOneMenu>
<h:commandButton value="Submit" action="beanCountries.listCities()"/>
</h:form>
this way is with a button (in jsf) and the action property will execute a java Method and then refresh the page. also this could be made by "ValueChangeListener" property of the selectOneMenu component