我想在bean中获取selectOneMenu值但是值没有得到正确.SubstituteHoliday是一个布尔变量。但是,我只对yes和no selectItem都得到假。我可以为selectOneMenu得到适当的值。基于selectOneMenu价值如果是,则意味着我想要更换日期单位...
提前致谢...
<p:dataTable id="manager" var="item" value="#{employeeWorkingHolidayBean.userListTwo}"
paginator="true" rows="10"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="2,5,10,15"
editable="true" editMode="cell" style="width:600px;" styleClass="postformatte"
emptyMessage="No Employee Working Holiday Details found with given criteria" resizableColumns="true" >
<p:ajax event="cellEdit" listener="#{employeeWorkingHolidayBean.onCellEdit}"
update=":form:growl"/>
<p:ajax event="colResize" update=":form:growl" listener="#{employeeWorkingHolidayBean.onResize}" />
<p:column headerText="Employee Id" width="90" >
<h:outputText value="#{item.employeeId}" />
</p:column>
<p:column headerText="Is Substitute Holiday">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{item.substituteHoliday}" /></f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{item.substituteHoliday}" style="width:100%">
<f:selectItems value="#{employeeWorkingHolidayBean.subsholiday}"/>
<p:ajax event="change" update="subdate"/>
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Substitute Date" >
<p:cellEditor>
<f:facet name="output"><p:calendar pattern="dd-MM-yyyy" yearRange="#{c-100}" navigator="true" showButtonPanel="true" value="#{item.substituteDate}"/></f:facet>
<f:facet name="input"><p:calendar id="subdate" pattern="dd-MM-yyyy" yearRange="#{c-100}" navigator="true" showButtonPanel="true" value="#{item.substituteDate}" style="width:55px;" disabled="#{employeeWorkingHolidayBean.isdiableEffectdate}"/></f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
豆:
private Boolean isdiableEffectdate;
public Boolean getIsdiableEffectdate() {
return isdiableEffectdate;
}
public void setIsdiableEffectdate(Boolean isdiableEffectdate) {
this.isdiableEffectdate = isdiableEffectdate;
}
public void onCellEdit(CellEditEvent event)
{
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
logger.info("Old value"+oldValue);
logger.info("New value"+newValue);
if(newValue.equals(true))
{
logger.info("enter if true");
isdiableEffectdate=true;
}
else
{
logger.info("enter if false");
isdiableEffectdate=false;
}
if(newValue != null && !newValue.equals(oldValue))
{
FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Cell Changed", "Old: " + oldValue + ", New:" + newValue);
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
答案 0 :(得分:0)
为select as,
添加一个VCE(Value changeListener Event)<h:selectOneMenu value="#{item.substituteHoliday}"
valueChangeListener="#{item.selectHolidayValueChangeListner}"
style="width:100%">
<f:selectItems value="#{employeeWorkingHolidayBean.subsholiday}"/>
<p:ajax event="change" update="subdate"/>
</h:selectOneMenu>
并且在valueChangeListener方法中将新值赋给全局变量as,
public void selectHolidayValueChangeListner(ValueChangeEvent vce) {
if (vce.getNewValue() != null) {
substituteHoliday = vce.getNewValue().toString();
}
}
现在,在你的ajax方法中获取substituteHoliday
的值并执行所需的任何操作。