Search your topic in Java2share
Home > FAQs
eXTReMe Tracker

Java Server Faces FAQs

Untitled Document

Q13. How to add context path to URL for outputLink?

Current JSF implementation does not add the context path for outputLink if the defined path starts with '/'. To correct this problem use
#{facesContext.externalContext.requestContextPath} prefix at the beginning of the
outputLink value attribute.
For example:
<h:outputLink value="#{facesContext.externalContext.requestContextPath}/myPage.faces">

Q14 How to get current page URL from backing bean?

You can get a reference to the HTTP request object via FacesContext like this:
FacesContext fc = FacesContext.getCurrentInstance();
HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();
and then use the normal request methods to obtain path information. Alternatively,
will return you the name of the current JSP (JSF view IDs are basically just JSP path

Q15. How to access web.xml init parameters from java code?

You can get it using externalContext getInitParameter method. For example, if you have:

You can access this connection string with:
FacesContext fc = FacesContext.getCurrentInstance();
String connection = fc.getExternalContext().getInitParameter("connectionString");

Q16. How to access web.xml init parameters from jsp page?

You can get it using initParam pre-defined JSF EL valiable.
For example, if you have:
You can access this parameter with #{initParam['productId']} . For example:
Product Id: <h:outputText value="#{initParam['productId']}"/>