Un metodo di un bean può ricevere in input parametri da una pagina jsf:
#{bean.method(param)}
Questa sintassi funziona con Tomcat 7, perchè supporta le EL 2.2 (el-impl-2.2.jar).
passParameter.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui" xmlns:c="http://java.sun.com/jsp/jstl/core"> <h:head/> <h:body> <h:form> <h:commandButton action="#{passParameterBean.getParameter(gigi)}" /> </h:form> </h:body> </html>
package com;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class PassParameterBean {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getParameter(String name)
{
this.name = name;
return "./passParameterResult.xhtml";
}
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head />
<h:body>
<h:form>
<h:outputText value="#{passParameterBean.name}" />
</h:form>
</h:body>
</html>