JSF Spring MVC Primeface Navigating/Redirect with parameters form Bean using AJAX:
(adsbygoogle = window.adsbygoogle || []).push({});
Bean:
public void redirect() { try { FacesContext ctx = FacesContext.getCurrentInstance(); ExternalContext extContext = ctx.getExternalContext();
//Example: parsing with parameter ?id=“123”&name=“somename”
String id=123,name=“somename”; String charEncoding = extContext.getRequestCharacterEncoding(); String name = URLEncoder.encode("id", charEncoding); String value = URLEncoder.encode(id, charEncoding); String name2 = URLEncoder.encode("name", charEncoding); String value2 = URLEncoder.encode(name, charEncoding); String url = extContext.encodeActionURL(ctx.getApplication().getViewHandler().getActionURL(ctx, ""));
//Example path: PROJECT/app/customer/list?execution=e5s1 //path of redirection: PROJECT/app/customer/list?id=123&name=somenameexecution=e5s1 //replace with your path
String newUrl= url.replace("/list?", "?"+name + "="+value+"&"+name2+"="+value2);
extContext.redirect(newUrl); } catch (IOException ioe) { throw new FacesException(ioe); } }
In view .xhtml:
<p:ajax event=“click” listener=#{bean.redirect} update=“:idForm”>
To retrieve the parameter in bean:
public void init(){
protected transient HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String id=req.getParameter("id”);
String name=req.getParameter("name”);
}










