One solution is to add an action method to the bean - it is possible to have it process itself.
For example, this simple bean:
public class SimpleBean {
private String forename;
private String surname;
public String processData() {
// TODO: real work
System.out.println("forename=" + forename);
System.out.println("surname=" + surname);
return null; // optional navigation rule
}
public String getForename() {
return forename;
}
public void setForename(String forename) {
this.forename = forename;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
}
...defined in WEB-INF/faces-config.xml:
<managed-bean>
<managed-bean-name>simpleBean</managed-bean-name>
<managed-bean-class>simplebean.SimpleBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
...can be processed using the this JSP:
<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<jsp:directive.page language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />
<jsp:text>
<![CDATA[<?xml version="1.0" encoding="UTF-8" ?>]]>
</jsp:text>
<jsp:text>
<![CDATA[<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">]]>
</jsp:text>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Enter Name</title>
</head>
<body>
<f:view>
<h:form>
<h:panelGrid columns="2">
<h:outputText value="forename:" />
<h:inputText id="it1" value="#{simpleBean.forename}" />
<h:outputText value="surname:" />
<h:inputText id="it2" value="#{simpleBean.surname}" />
</h:panelGrid>
<h:commandButton action="#{simpleBean.processData}"
value="process" />
</h:form>
</f:view>
</body>
</html>
</jsp:root>
Note the method binding #{simpleBean.processData}. This must be a public method that takes no arguments and returns a String argument (which can be used for page navigation if desired).
This isn't the only way to go about this, but it is fairly straightforward.