【问题标题】:Is it possible to change EL base on the selected value from dropdown list?是否可以根据下拉列表中的选定值更改 EL?
【发布时间】:2017-04-28 02:32:36
【问题描述】:
<th>
  <h:outputText value="Pending Actions" style="font-weight:bold" />
    <td colspan="4">
      <p:selectOneMenu value="#{selectedValue}" required="true">
         <f:selectItem itemValue="#{null}" itemLabel="--Select One--" />
         <f:selectItem itemValue="organization1" itemLabel="ORGANIZAION1" />
         <f:selectItem itemValue="organization2" itemLabel="ORGANIZAION2" />
         <f:selectItem itemValue="organization3" itemLabel="ORGANIZAION3" />
         <f:selectItem itemValue="organization4" itemLabel="ORGANIZAION4" />
       </p:selectOneMenu>
  <h:inputTextarea value="#{casesBean.organization1PendingActionDetails}"/>
 </td>
</th>

如上所示,有一个下拉列表让用户选择他们想要分配任务的组织。

  • 在我的数据库中,有列 organization1PendingActionDetails, organization2PendingActionDetails等

  • 所以我的问题是:

    是否可以更改inputTextarea 值 基于从下拉列表中选择的值?

  • 例如:

如果用户选择organization2,那么inputTextarea 将变为
value="#{casesBean.organization2PendingActionDetails}"

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    您可能需要有多个 inputTextarea。每个区域应该有不同的值,并根据选定的值进行渲染设置。选择后在 inputTextarea 上设置适当的渲染值并通过 ajax 更新它。

    <p:ajax event="change" listener=#{casesBean.decideRenderedInputTextArea} update="InputTextAreasWrapper" />
    

    更好的解决方案: 拥有一个 inputTextArea 会更加优雅。正如您所说,您想将其中的值存储到数据库中。因此,在执行将数据存储到数据库的操作之前(在提交表单之后),根据内部选定的值决定将数据存储在哪里。

    【讨论】:

    • @vennis 然后考虑通过接受答案来结束这个话题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-16
    • 1970-01-01
    • 2015-05-12
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    相关资源
    最近更新 更多