Wednesday, October 14, 2009

Dynamic Navigation in JSF

The last two post was about the use of dynamic JSF components and properties, but the other problem I faced is referred with the dynamic navigation,

"How can I extend or write a more dynamic navigation in JSF? for example to create dynamic parameters or calls to a non jsf pages with GET parameters?"

Ok, here's how I solved this. In the method of the backing bean that will be called when I the button is pressed I added this code:

FacesContext currentInstance = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) currentInstance.getExternalContext().getResponse();
HttpServletRequest request = (HttpServletRequest) currentInstance.getExternalContext().getRequest();
String url = request.getContextPath();
if (a == 1) {
url += "testpage.jsp?arg1=1&arg2=2";
} else {
url += "testpage2.jsp?arg1=1&arg2=3";

As you can see here the solution it's very simple and works very well.


Anonymous said...

Thanks for the tip, this saved my ass :)

Cross said...
This comment has been removed by the author.
Cross said...

you're welcome.