Difference between revisions of "JsfGetRequests"
Jump to navigation
Jump to search
Line 3: | Line 3: | ||
* modifying the parameters in the URL is possible | * modifying the parameters in the URL is possible | ||
* bookmarking this page is possible | * bookmarking this page is possible | ||
What this procedure does not change is the behaviour of the JSF links. This means that a "Open link in a new window" is still not possible. | |||
Usually, no changes in the JSPs/JSPFs are needed. Assuming you have the following | Usually, no changes in the JSPs/JSPFs are needed. Assuming you have the following |
Revision as of 13:37, 24 August 2007
The following steps have to be taken to make a JSF page basically RESTful, that is
- calling the page via a HTTP GET request is possible
- modifying the parameters in the URL is possible
- bookmarking this page is possible
What this procedure does not change is the behaviour of the JSF links. This means that a "Open link in a new window" is still not possible.
Usually, no changes in the JSPs/JSPFs are needed. Assuming you have the following
- a source page with a form
- a java bean for the source page containing an action method
- a target page
- a java bean for the target page containing an action method
- a session- or request-scoped backing bean holding the parameters
Modify source bean action method to evaluate parameters and redirect to target page[edit]
public String doSomething() { String foo = this.fooInput.getSubmittedValue(); boolean bar = "true".equals(this.barInput.getSubmittedValue()); // change from // return this.getTargetBean().doMore(); // to FacesContext .getCurrentInstance() .getExternalContext() .redirect("myTargetPage.jsp?foo=" + urlEscape(foo) + "&bar=" + bar); return ""; }
Define parameters in target page bean[edit]
This can look something like this:
public class MyPage extends AbstractPageBean { //... public final static String URL_PARAM_FOO = "foo"; public final static String URL_PARAM_BAR = "bar"; //... }
Catch Parameters in target page bean init method , add to session/request bean and execute action method[edit]
Like this:
public void init() { // Perform initializations inherited from our superclass super.init(); //... HttpServletRequest request = (HttpServletRequest)FacesContext .getCurrentInstance().getExternalContext().getRequest(); String foo = request.getParameter(targetPage.URL_PARAM_FOO); boolean bar = ("true".equals(request.getParameter(targetPage.URL_PARAM_BAR))); mySessionBean.setFoo(foo); mySessionBean.setBar(bar); //... this.processForm(); }