senderParam.xhtml
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Sender Param</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</h:head>
<h:body>
<h:form id="senderParamForm" prependId="false">
<p:commandButton value="Send param" action="#{receiverParam.goToReceiverParam}" ajax="false">
<f:param name="carId" value="-10" />
<f:param name="otherParam" value="otherParam" />
</p:commandButton>
</h:form>
</h:body>
</html>
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Car Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</h:head>
<h:body>
<h:form id="carForm" prependId="false">
Passed Param is: <h:outputText value="#{receiverParam.carId}" />
</h:form>
</h:body>
</html>
Code: Select all
import javax.annotation.PostConstruct;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Component("receiverParam")
@Scope("request")
public class ReceiverParam {
private String carId = "";
@PostConstruct
public void init() {
carId = getParameter("carId");
if (carId == null || "".equals(carId)) {
carId = "No param";
}
}
public String goToReceiverParam() {
return "/receiverParam.html";
}
public String getCarId() {
return carId;
}
private String getParameter(final String name) {
return getRequest().getParameter(name);
}
private HttpServletRequest getRequest() {
return (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
}
}
JSF 2.0.3 Mojarra
Spring 3.0.5.RELEASE
Jetty 7.3.0.v20110203