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. I just want to have a string that I get from a textbox passed in as a parameter to the method. I've added a h:inputText to my xhtml page, but I can't get it to set a String variable in the corresponding flow. What is the simplest possible way I can get a value from a textbox into a flowscope String variable?

Upvotes: 1

Views: 3620

Answers (2)

Jigar Joshi
Jigar Joshi

Reputation: 240956

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

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

Upvotes: 1

r.piesnikowski
r.piesnikowski

Reputation: 2961

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

Here you should more examples.

Upvotes: 0

Related Questions