简体   繁体   English

如何将输入的文本值作为方法参数从JSF页面传递到Managedbean?

[英]how to pass input text value as method parameter from JSF page to Managedbean?

I want to pass input text value as method parameter from jsf page to managedbean as i submit the form. 我想在提交表单时将输入的文本值作为方法参数从jsf页传递到ManagedBean。 like 喜欢

<h:form>
   <p:inputText name="fname"/>
   <P:commandButton value="Submit" action="#{myClass.save(inputText value as parameters)}">
</h:form>

The standard approach is the following: 标准方法如下:

<h:form> 
    <p:inputText value="#{myClass.inputValue}"/> 
    <p:commandButton value="Submit" action="#{myClass.doSomething}"> 
</h:form> 

MyClass class: MyClass类:

@ManagedBean
@ViewScoped
public class myClass {
    private String inputValue;

    // getter and setter for inputValue

    public void doSomething() {
    }
}

When the user clicks the button, before doSomething is invoked, JSF cares about reading the value inputed in the inputText component, validating it if necessary, and invoking setter class for inputValue as per the EL expression #{myClass.inputValue} (note that EL automagically understands that the setter must be invoked in this case). 当用户单击按钮时,在调用doSomething之前, JSF关心读取在inputText组件中输入的值,必要时对其进行验证,并根据EL表达式#{myClass.inputValue}调用inputValue setter类(请注意,EL自动理解在这种情况下必须调用setter )。 This is very basic JSF. 这是非常基本的JSF。 I recommend to study some Java EE 6 tutorial ( this , for example). 我建议学习一些Java EE 6教程(例如this )。

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

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