【问题标题】:Primefaces obtain inputText value in managedBeanPrimefaces 获取 managedBean 中的 inputText 值
【发布时间】:2014-02-15 08:07:41
【问题描述】:

对于熟悉 Primefaces 但我才刚刚开始的人来说,我的问题应该是微不足道的。我的问题是: 当我像这样将 inputText 组件放入我的网页时:

<h:form id="formularz">
    <p:inputText id="workyears" value="#{appointentBean.year}" style="width: 40px;"/>
<h:form>

我想直接从appendentBean 中检索输入的文本。我的意思是我想在 AppendentBean 中创建另一个方法来处理输入的文本,所以我需要将输入的文本立即放在引用的字段 year 中。在另一个世界中,当有人将文本放入 inputText 组件时,我需要自动更新我在 AptentBean 中的字段年份。提交之类的?我希望你明白我的意思。

这是我的 managedBean:

@ManagedBean
@ViewScoped
@SessionScoped
public class appointentBean{

    private int year;

public int getYear() {
    return year;
}

public void setYear(int year) {
    this.year = year;
}

    //Here I will put another method that will be operate on year value
}

【问题讨论】:

  • my field year in appointentBean to be automaticaly updated while someone put text in inputText component 是指与按键事件的 ajax 交互来调用您的方法?
  • 想直接检索输入的文本---&gt; 你说的是这个自动完成吗?自动更新?
  • 是的,我将使用 commandButton 来调用我的方法

标签: ajax primefaces


【解决方案1】:

您可以使用这样的事件 (read more):

<h:form>
    <p:inputText value="#{viewMBean.hello}">
        <p:ajax event="keyup" update="hello" process="@this" />  
    </p:inputText>

    <h:outputText id="hello" value="#{viewMBean.hello}" />
</h:form>

这里是 viewMBean:

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class ViewMBean implements Serializable {

    private String hello;

    public String getHello() {
        return hello;
    }

    public void setHello(String hello) {
        this.hello = hello;
    }

}

PS:欢迎来到 Primefaces!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-22
    • 1970-01-01
    相关资源
    最近更新 更多