I have a selectOneMenu, in my xhtml page, when i want to click in a selectItem with the itemValue is null, there is no effect, it shows the default selection
<p:selectOneMenu id="cout" style="width: 120px;" value="#{serviceManagedBean.selectedService.coutSmsCalc}">
<f:selectItem itemLabel="Sélectionnez une" itemValue="" />
<f:selectItem itemLabel="oui" itemValue="oui" />
<f:selectItem itemLabel="non" itemValue="" />
</p:selectOneMenu>
So, when i click in the itemLabel "non", it remains on "Sélectionnez une"
The selectOneMenu use itemValue to change the displayed value. So if your value is null like the default one, the action changeListener is not called. Try to change the itemValue by empty or other key.
Try this if the item value is a String
<f:selectItem itemLabel="Sélectionnez une" itemValue="{null}" />
<f:selectItem itemLabel="oui" itemValue="oui" />
<f:selectItem itemLabel="non" itemValue="non" />
Or try this if the item value is boolean
<f:selectItem itemLabel="Sélectionnez une" itemValue="{null}" />
<f:selectItem itemLabel="oui" itemValue="true" />
<f:selectItem itemLabel="non" itemValue="false" />
Related
In the below editable drop down how to restrict the user to enter only numbers.
<p:selectOneMenu editable="true">
<f:selectItem itemLabel="0" itemValue="0" />
<f:selectItem itemLabel="5" itemValue="5"/>
<f:selectItem itemLabel="10" itemValue="10" />
<f:selectItem itemLabel="20" itemValue="20"/>
</p:selectOneMenu>
<h:selectOneMenu id="customerSelection" required="true" requiredMessage="Enter/Select a customer"
value="#{engagement.selectedDropdownCustValue}" validator="#{engagement.validateCustomer}">
<f:selectItem itemLabel="Select Customer" itemValue="#{null}" noSelectionOption="true" itemDisabled="true" />
<f:selectItems var="c" id="customer" itemLabel="#{c.name}" itemValue="#{c.name}" value="#{dashboard.customers}" />
<f:selectItem itemLabel="Other" itemValue="#{null}" />
<p:ajax update="engagementCustomer" />
</h:selectOneMenu>
<p:inputText id="engagementCustomer" value="#{engagement.selectedEngagement.customer.name}"
maxlength="30" disabled="#{engagement.selectedDropdownCustValue!=null}" validator="#{engagement.validateCustomer}" />
I want to have 'Select Customer' to be displayed in dropdown after page load, but Other is displayed by default in dropdown. Purpose of this code is to display already existing customers while creating new engagement, but if other value is selected from dropdown then input filed should be enabled and user should be allowed to enter new customer value.
When I run my application, "Single User" should be selected automatically.
<h:selectOneRadio onchange="showEmailDiv(this.id);" value="" id="emailValue" required="true">
<f:selectItem itemValue="Single" itemLabel="Single User" />
<f:selectItem itemValue="Multiple" itemLabel="Multiple User"/>
</h:selectOneRadio>
How can I preselect one radio button defaultly?
Set default value like this
<h:selectOneRadio onchange="showEmailDiv(this.id);" value="Single" id="emailValue" required="true">
<f:selectItem itemValue="Single" itemLabel="Single User" />
<f:selectItem itemValue="Multiple" itemLabel="Multiple User"/>
</h:selectOneRadio>
Note: you aren't binding this component with bean, not sure how would you use it
#ManagedBean
public class YourBean {
private String value = "Single User";
// getter & setter
}
And in your page
<h:selectOneRadio onchange="showEmailDiv(this.id);" value="#{yourBean.value}" id="emailValue" required="true">
<f:selectItem itemValue="Single" itemLabel="Single User" />
<f:selectItem itemValue="Multiple" itemLabel="Multiple User"/>
</h:selectOneRadio>
I have following selectOneMenu
<p:selectOneMenu value="#{bean.value}">
<f:selectItem value="#{bean.item1}"/>
<f:selectItem value="#{bean.item2}"/>
<f:selectItem value="#{bean.item3}"/>
<p:ajax listener="#{bean.item3AjaxEvent}" update="fieldToUpdate"></p:ajax>
</p:selectOneMenu>
Now I want to do some AJAX action only when item3 is selected from selectOneMenu. Not for all the items. Is there any way of doing that?
Putting ajax tag will fire the event for all the select items. I don't want to generate unwanted ajax requests to server.
I would do it in this way.
xhtml
<p:selectOneMenu widgetVar="selectOneMenuWV"
onchange="checkItem()">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItem itemLabel="Option 1" itemValue="1" />
<f:selectItem itemLabel="Option 2" itemValue="2" />
<f:selectItem itemLabel="Option 3" itemValue="3" />
</p:selectOneMenu>
<p:remoteCommand name="myRemoteCommand"
actionListener="#{bean.item3AjaxEvent()}"
update="fieldToUpdate"/>
<script>
function checkItem() {
if(selectOneMenuWV.getSelectedValue() == 3) {
myRemoteCommand();
}
}
</script>
Hope this helps.
I have two drop down menus, and the content of the second depends on the choice in the first one. Now, the content changes but only after I hit "refresh". It needs to change automatically on selection of the first menu.
<h:outputLabel value="Country: " />
<h:selectOneMenu value="#{bean.country}">
<f:selectItem itemValue="#{null}" itemLabel="-- select country --" />
<f:selectItem itemValue="Spain" itemLabel="Spain" />
(...)
<f:ajax listener="#{bean.findCity}" />
</h:selectOneMenu>
<h:outputLabel value="City: " />
<h:selectOneMenu value="#{bean.city}">
<f:selectItem itemValue="#{null}" itemLabel="-- select city --" />
<f:selectItems value="#{bean.citiesFound}" var="city"
itemLabel="#{city.cityNameFull}" itemValue="#{schedule.cityName}" />
</h:selectOneMenu>
Again, the function findCity works fine, because the result is correct when I refresh the page, but I want the second menu to refresh automatically.