【问题标题】:disabled value getting null in bean for p:selectOneMenup:selectOneMenu 的禁用值在 bean 中为空
【发布时间】:2013-12-12 07:00:31
【问题描述】:

我想根据员工编号禁用部门字段。但是,我希望 bean 中的部门值。当,我使用禁用值在 bean 中获取 null 但不使用禁用没问题...

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

【问题讨论】:

  • 您确定 #{salarypromotionBean.designationDiaspleValue} 不会返回“true”并因此禁用 selectOneMenu?
  • Emil Kaminski: 是的,肯定 #{salarypromotionBean.designationDiaspleValue} 值为真,这就是为什么 selectOneMenu 被禁用,我也希望 bean 中的禁用值。但是,禁用时 bean 中的值变为空......
  • 很抱歉,您的问题很难理解。因此,当 selectOneMenu 被禁用时,您希望将值“Disabled”解析为您的 bean,而不是 null?
  • @ArunRaj JSF 不会处理带有disabled="true" 的组件。这就是禁用部门下拉菜单时该值为 null 的原因。当元素被禁用时,您应该只使用已在支持 bean 中设置的值作为 #{salarypromotionBean.salarypromotiondto.department}

标签: jsf primefaces


【解决方案1】:

你可以这样做。

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

【讨论】:

  • 请添加一些文字来解释为什么这是一个解决方案
猜你喜欢
  • 2013-10-10
  • 2012-10-30
  • 1970-01-01
  • 2013-06-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多