I need to send values (the input from a Textbox) as parameters to a method & I am new at JSF.
Say I have a form, linked to a managed bean
<h:form id="myForm">
<h:inputText id="atribute1" value="#{myBean.atribute1}"></h:inputText>
<h:inputText id="atribute2" value="#{myBean.atribute2}"></h:inputText>
<h:commandButton id="btn" value="SendData" action="#{myBean.save}">
<p:param name="param1" value="${atribute1}"/>
<p:param name="param2" value="${atribute2}"/>
</h:commandButton>
</h:form>
the managed bean has a “save” method (i made it here a void method, but Eclipse seems to want it to return a String??)
public void save() {
FacesContext context = FacesContext.getCurrentInstance();
Map<String,String> params = context.getExternalContext().getRequestParameterMap();
String param1= params.get("param1");
String param2= params.get("param2");
System.out.println("param1:"+param1+" & param2:"+param2);
}
This doesnt seem to do anything, I get no values printed, but i doesn’t crash. So anyone?
Assuming you want to act on values in save method.
You have already linked the values to be entered in textbox to backing bean via
value="#{myBean.atribute1}"which states that vallue entered here will be available in property atribute1 of managed bean namedmybean, when you submit the page you can acces them in save method directly.make sure you have getter/setters for both properties and remove child tags from commandbutton.