简体   繁体   English

如何在JSF中使用inputText设置String变量?

[英]How do I set a String variable using inputText in JSF?

I have a flow.xml file that's calling a method on a bean. 我有一个flow.xml文件,该文件正在Bean上调用方法。 I just want to have a string that I get from a textbox passed in as a parameter to the method. 我只想有一个从文本框获得的字符串,该字符串作为参数传递给方法。 I've added ah:inputText to my xhtml page, but I can't get it to set a String variable in the corresponding flow. 我已经将ah:inputText添加到我的xhtml页面中,但是我无法在相应的流程中设置它来设置String变量。 What is the simplest possible way I can get a value from a textbox into a flowscope String variable? 我可以从文本框中获取值到flowscope String变量的最简单方法是什么?

public class SomeBean{
String val;
  //getters & setters
  public String foo(){
    System.out.println(val);
    return "SUCCESS";
  }
}

xhtml 的xhtml

    <h:form>
      <h:inputtext value="#{someBean.val}"/>
      <h:commandButton action="#{someBean.foo}"/>
    </h:form>

as html it will render a html form with a textbox and a submit button on licking button it will call foo() and text from txtbox will get binded to val 作为html,它将呈现一个带有文本框和一个单击按钮的提交按钮的html表单,它将调用foo()而txtbox中的文本将被绑定到val

MyBean myBean = (MyBean) facesContext.getApplication().createValueBinding("#{flowScope.myBean}").getValue(facesContext);
String val = myBean.GetBeanProperty();

Here you should more examples. 在这里您应该更多示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM