disabled value getting null in bean for p:selectOneMenu - jsf

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

Related

f:ajax doesn't update component

I have a select and I want that when the user doesn't select anything it prints an error. So I use validator and my xhtml code is:
<p:selectOneMenu id="students"
value="#{studentsBean.selectedStudent}"
converter="studentsConverter" effect="fold">
<f:selectItem itemLabel="Select..." itemValue="" />
<f:selectItems value="#{studentsBean.studentsList}"
var="student" itemValue="#{student}"
itemLabel="#{student.name}" />
<p:ajax event="change" update="students" process="#this" />
<f:validator validatorId="studentNotNull" />
<f:ajax execute="#this" render="studentPanel"/>
</p:selectOneMenu>
<h:panelGroup id="studentPane">
<h:message for="students" style="color:red" />
</h:panelGroup>
The problem is that if I don't select anythin it print me "The students is not selected" while I choice an student the label it doesn't disappear.
the validatior works and I don't think I must write the code.
Anyone can help?
Can you try this
<p:selectOneMenu id="students"
value="#{studentsBean.selectedStudent}"
converter="studentsConverter" effect="fold"
required="true" requiredMessage="Student is required">
<f:selectItem itemLabel="Select..." noSelectionOption="true"/>
<f:selectItems value="#{studentsBean.studentsList}"
var="student"
itemValue="#{student}"
itemLabel="#{student.name}" />
</p:selectOneMenu>
Add in your form
<p:growl id="msgs" showDetail="true" life="3000"/>
and of course, update msgs in form submit

The listener for p:selectOneMenu working only partially

I have a simple JSF form which has three dropdowns,
here is the code:
<h:form>
<p:panel header="Select country" style="margin-bottom:10px;">
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="country" value="Country: " />
<p:selectOneMenu id="country" value="#{phaseOneController.country}" style="width:150px">
<p:ajax listener="#{phaseOneController.onCountryChange}" update="province" />
<f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{phaseOneController.countries}" />
</p:selectOneMenu>
<p:outputLabel for="province" value="Province: " />
<p:selectOneMenu id="province" value="#{phaseOneController.province}" style="width:150px">
<p:ajax listener="#{phaseOneController.onProvinceChange}" update="city" />
<f:selectItem itemLabel="Select Province" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{phaseOneController.provinces}" />
</p:selectOneMenu>
<p:outputLabel for="city" value="City: " />
<p:selectOneMenu id="city" value="#{phaseOneController.city}" style="width:150px">
<f:selectItem itemLabel="Select City" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{phaseOneController.cities}" />
</p:selectOneMenu>
</h:panelGrid>
<p:separator />
<p:commandButton value="Select" actionListener="#{phaseOneController.submit}" icon="ui-icon-check">
</p:commandButton>
</p:panel>
</h:form>
Now when I select a country, the onCountryChange gets called but when I update the province, the onProvinceChange doesn't get called at all!! It is surprising how one would work and other wouldn't
Here is the piece of code from the controller:
public void onCountryChange() {
System.out.println("On country change called");
}
public void onProvinceChange() {
System.out.println("On province change called");
}
For shortening the question I have replaced the code in the listener methods.
Answer: For anyone who faces this issue, using HashMap to populate the dropdown solved the issue. I am not sure why list is giving so much trouble.
Try to add event="change"...
<p:selectOneMenu id="country" value="#{phaseOneController.country}" style="width:150px">
<p:ajax event="change" listener="#{phaseOneController.onCountryChange}" update="subCategory" />
<f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{phaseOneController.countries}" />
</p:selectOneMenu>
<p:selectOneMenu id="province" value="#{phaseOneController.province}" style="width:150px">
<p:ajax event="change" listener="#{phaseOneController.onProvinceChange}" update="city" />
<f:selectItem itemLabel="Select Province" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{phaseOneController.provinces}" />
</p:selectOneMenu>
Placing the bean in the view scope by #ViewScoped and Custom Converters to each f:selectItems should solve this problem.
Please See:
Cascading p:selectOneMenu model value not set

Display/hide h:panelGrid on the base of value selected in h:selectOneMenu

I want to display and hide a <h:panelGrid> on the basis of the value selected in <h:selectOneMenu>.
The code is:
<p:dialog id="logClassDlg" header="Log Class Teached" widgetVar="logClass" modal="true" >
<h:form>
<p:growl id="growl" showDetail="true" />
<h:panelGrid id="logClassPanelGrd1" columns="2">
<h:outputLabel for="class" value="Class: " />
<h:selectOneMenu id="class" value="#{logClassBean.classLog.classTitle}">
<f:selectItem itemValue="Reading" itemLabel="Reading" />
<f:selectItem itemValue="Memorization" itemLabel="Memorization" />
<f:selectItem itemValue="Translation" itemLabel="Translation" />
<f:selectItem itemValue="Language" itemLabel="Language" />
<f:selectItem itemValue="Grammer" itemLabel="Grammer" />
<f:ajax render="logClassPanelGrdBook" />
</h:selectOneMenu>
</h:panelGrid>
<h:panelGrid id="logClassPanelGrdBook" columns="2" rendered="#{(logClassBean.classLog.classTitle ne 'Language') and (logClassBean.classLog.classTitle ne 'Grammar')}">
<p:outputLabel value="Book" />
<h:selectOneMenu id="book" value="#{logClassBean.classLog.classStatus}">
<f:selectItem itemValue="first" itemLabel="first" />
<f:selectItem itemValue="second" itemLabel="second" />
<f:selectItem itemValue="third" itemLabel="third" />
<f:selectItem itemValue="fourth" itemLabel="fourth" />
<f:selectItem itemValue="fifth" itemLabel="fifth" />
</h:selectOneMenu>
</h:panelGrid>
As you can see I want to display the panel grid logClassPanelGrdBook only on when the selected values are not Language and Grammar i.e
rendered="#{(logClassBean.classLog.classTitle ne 'Language') and (logClassBean.classLog.classTitle ne 'Grammar')}"
But the panel grid is displayed irrespective of the values selected, it should hide when the other values (Reading, Memorization and Translation) are selected.
Any help/pointers would be appreciated. Thank you.
The part <f:ajax render="logClassPanelGrdBook" /> won't update and recheck the rendered function of the panelGrid this way. You will need to update its parent element instead.
For example, you can wrap it with <h:panelGroup>:
<h:panelGrid id="logClassPanelGrd1" columns="2">
<h:outputLabel for="class" value="Class: " />
<h:selectOneMenu id="class" value="#{logClassBean.classLog.classTitle}">
<f:selectItem itemValue="Reading" itemLabel="Reading" />
<f:selectItem itemValue="Memorization" itemLabel="Memorization" />
<f:selectItem itemValue="Translation" itemLabel="Translation" />
<f:selectItem itemValue="Language" itemLabel="Language" />
<f:selectItem itemValue="Grammar" itemLabel="Grammar" />
<f:ajax render="logClassPanelGrdBook" />
</h:selectOneMenu>
</h:panelGrid>
<h:panelGroup id="logClassPanelGrdBook">
<h:panelGrid columns="2" rendered="#{(logClassBean.classLog.classTitle ne 'Language') and (logClassBean.classLog.classTitle ne 'Grammar')}">
<p:outputLabel value="Book" />
<h:selectOneMenu id="book" value="#{logClassBean.classLog.classStatus}">
<f:selectItem itemValue="first" itemLabel="first" />
<f:selectItem itemValue="second" itemLabel="second" />
<f:selectItem itemValue="third" itemLabel="third" />
<f:selectItem itemValue="fourth" itemLabel="fourth" />
<f:selectItem itemValue="fifth" itemLabel="fifth" />
</h:selectOneMenu>
</h:panelGrid>
<h:panelGroup>
I also changed select item value from Grammer to Grammar because it didn't match the value in rendered attribute.
If this doesn't work, you should also check if bean value is properly set when you click <h: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

Primefaces selectonemenu requiredmessage

I am creating a selectonemenu using Primefaces and JSF.
I want to appear a message saying "Choose one of the options". How can I do that?
This is the code:
<!--Gender-->
<p:selectOneMenu id="gender" value="#{users.gender}" required="true"
requiredMessage="Choose one of the options">
<f:selectItem itemLabel="Choose gender" itemValue="#{null}" />
<f:selectItem itemLabel="Male" itemValue="Male" />
<f:selectItem itemLabel="Female" itemValue="Female" />
</p:selectOneMenu>
Thanks
adding below on the submit button will work fine as well.
ajax="false"
*********************edited**********
As you requested, please find below block of codes that works fine for me ::
<h:form>
<p:panelGrid style="margin-top:5px;width:730px;">
<f:facet name="header">
<p:row >
<p:column colspan="20">Select Company</p:column>
</p:row>
</f:facet>
<p:row>
<p:column>
<p:selectOneMenu id="companyMenu" value="#{clientList.clientCode}"
style="width:550px;margin:5px;text-color:black" required="true"
requiredMessage="Please select a company !">
<f:selectItem itemLabel="Select a Company" noSelectionOption="true"
itemValue="#{null}" />
<f:selectItems value="#{clientList.clients.entrySet()}" var="entry"
itemValue="#{entry.key}" itemLabel="#{entry.value}" >
</f:selectItems>
</p:selectOneMenu>
</p:column>
<p:column>
<p:commandButton value="Submit" style="margin:5px;" action="#
{viewPayment.companyDetails(clientList.clientCode)}" ajax="false"/>
</p:column>
</p:row>
</p:panelGrid>
</h:form>
You can use :
if (users.getGender()==null) {
FacesContext.getCurrentInstance().addMessage(
null,
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Choose one of the options",
"Choose one of the options"));
}
SOLVED.I forgot to add the line <p:message for="gender" /> to the code. Thanks.

Resources