【问题标题】:Primefaces selectOneMenu update outputLabel and inputTextPrimefaces selectOneMenu 更新 outputLabel 和 inputText
【发布时间】:2015-05-04 05:28:54
【问题描述】:

我在 Google 上搜索过很多次,但我似乎找不到答案。
What needs to be done is that the outputLabel's value needs to be updated when the selection change, also inputText's disabled needs to change to enabled when you select option B. (Furthermore; the selected value is displayed in the inputText)

我的 xhtml 被剪断了:

<p:selectOneMenu id="findex" value="#{myController.selected.findex}" >
    <p:ajax update="extra1 labelextra1" immediate="true"/>
    <f:selectItem itemLabel="Value A" itemValue="A" />
    <f:selectItem itemLabel="Value B" itemValue="B" />
</p:selectOneMenu>

<p:outputLabel id="labelextra1" value="#{myController.selected.findex == 'A' ? '' : 'X'}" for="extra1"/>
<p:inputText id="extra1" value="#{myController.selected.findex}" disabled="#{myController.selected.findex == 'A'}"/>

(如果我将支持 bean 中的侦听器添加到 ajax 中,它确实会被调用,但我不确定我是否需要它,这是一个简单的更改事件,不是吗?)

【问题讨论】:

  • 没有immediate="true"也能用吗?
  • 不,无论是否有 immediate="true" 都没有变化

标签: jsf-2 primefaces selectonemenu


【解决方案1】:

我举个小例子。这工作正常。我想你没有&lt;h:form&gt; 对吧?你需要一个表格。

.XHTML

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">

<h:head>
<title>Jsf page.</title>
</h:head>

<h:body>
<h:form>
    <p:selectOneMenu id="findex" value="#{myController.test}">
        <f:selectItem itemLabel="Value A" itemValue="A" />
        <f:selectItem itemLabel="Value B" itemValue="B" />
        <p:ajax update="labelextra1 extra1" />
    </p:selectOneMenu>

    <p:outputLabel id="labelextra1" value="#{myController.test}" for="extra1" />
    <p:inputText id="extra1" value="hello" disabled="#{myController.test == 'A'}"/>
</h:form>

</h:body>
</html>

豆:

@ManagedBean
@ViewScoped
public class MyController implements Serializable{

private String test = "hallo";


public String getTest() {
    return test;
}

public void setTest(String test) {
    this.test = test;
}


}

【讨论】:

  • 它在一个
    这个例子确实有效,我已经将它合并到实际的 xhtml 中。它一直有效,直到我开始使用表单所基于的数据库实体。解决方案更复杂,但我必须让它发挥作用。禁用的逻辑在控制器中(不在 xhtml 中)
猜你喜欢
  • 2018-07-15
  • 1970-01-01
  • 2013-08-14
  • 2014-09-03
  • 1970-01-01
  • 1970-01-01
  • 2015-11-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多