Reputation: 175
I want to pass input text value as method parameter from jsf page to managedbean as i submit the form. like
<h:form>
<p:inputText name="fname"/>
<P:commandButton value="Submit" action="#{myClass.save(inputText value as parameters)}">
</h:form>
Upvotes: 2
Views: 5892
Reputation: 16273
The standard approach is the following:
<h:form>
<p:inputText value="#{myClass.inputValue}"/>
<p:commandButton value="Submit" action="#{myClass.doSomething}">
</h:form>
MyClass class:
@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). This is very basic JSF. I recommend to study some Java EE 6 tutorial (this, for example).
Upvotes: 1