default selected value in h:selectOneMenu - jsf

<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.

Related

How to Restrict User to enter only numbers in the editable p:selectonemenu dropdown

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>

Reseting p:ajax drop down after un-selecting option

I am using prime faces in my project. I am generating a pull down by using p:ajax and its working fine for me. But i have notice a problem that is if i select ---select one-- my pull down which i have generated by p:ajax is not resetting to default .
My code is:
<p:selectOneMenu id="propExam" value="#{rollNoBean.examination}"
converter="omnifaces.SelectItemsConverter" editable="false"
required="true" label="Examination Applied For" styleClass="dropdownWidth">
<f:selectItem itemLabel="---Select One---" itemValue="0" />
<f:selectItems value="#{rollNoBean.testExamNames}" var="test" itemLabel="#{test.name}" itemValue="#{test}" noSelectionOption="true" />
<p:ajax listener="#{rollNoBean.readFilterByExamination(rollNoBean.examination.id)}"
update="degreeList centerId" />
</p:selectOneMenu>
<h:outputText value="Select Filter Category :" />
<p:selectOneMenu id="degreeList"
value="#{rollNoBean.filter}" editable="false"
converter="omnifaces.SelectItemsConverter" required="true"
label="Please Select degree" styleClass="dropdownWidth">
<f:selectItem itemValue="" itemLabel="---Select One---" />
<f:selectItems value="#{rollNoBean.degreeNames}"
var="degree" itemLabel="#{degree.name}" itemValue="#{degree}" />
</p:selectOneMenu>
and my bean code is:
public List<Filter> readFilterByExamination(int id)
{
if(id!=0)
{
return degreeNames=examinationDetailsService.readFilterByExamination(id);
}
return degreeNames=new ArrayList<Filter>();
}
Please give suggetion

Cannot click on selected Item when the value is null primefaces

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" />

jsf update drop down menu

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.

disabled value getting null in bean for p:selectOneMenu

I want to disabled department field based on employeeno.But,I want department value in bean.When,I using disabled value getting null in bean but without using disabled no problem...
<h:outputText value="Employee No"/>
<p:selectOneMenu value="#{salarypromotionBean.salarypromotiondto.employeeNo}" id="emp" style="width:163px;">
<f:selectItem itemLabel="select" itemValue="0" />
<f:selectItems value="#{salarypromotionBean.empid}"/>
<p:ajax event="change" listener="#{salarypromotionBean.currentSalaryAmount}" update="salaryIncrement,empN,empDoj,basic,da,empNewDesig,commonSalaryIncrement"/>
</p:selectOneMenu>
<h:outputText value="Department" />
<p:selectOneMenu value="#{salarypromotionBean.salarypromotiondto.department}" id="empDept" disabled="#{salarypromotionBean.designationDiaspleValue}"
style="width:163px;">
<f:selectItems value="#{salarypromotionBean.deptname}" />
</p:selectOneMenu>
You can do this.
<p:selectOneMenu value="#{salarypromotionBean.salarypromotiondto.department}" id="empDept" rendered="#{!salarypromotionBean.designationDiaspleValue}"
style="width:163px;">
<f:selectItems value="#{salarypromotionBean.deptname}" />
</p:selectOneMenu>
<p:inputText value="#{salarypromotionBean.salarypromotiondto.department}" readonly="true" rendered="#{salarypromotionBean.designationDiaspleValue}"/>

Resources