Saturday, February 16, 2013

setAsText: Cannot find FacesContext warning / error

I was recently converting a project from Faces (JSF) to NonFaces using JSTL, JSP, AJAX and jQuery.

I was making changes to a JSP page.  All of a sudden, the page which was working before stopped working.  The console logged the warning:setAsText: Cannot find FacesContext
Also, the error " com.ibm.ws.jsp.JspCoreException: com.ibm.ws.jsp.JspCoreException: javax.faces.Face
sException: Cannot find FacesContext."

I started to panic - do I still need the JSF config?

The cause of the issue happens to be
< jsp:setProperty name="tsdec" property="entryDate" value="${pped1}"  / >

Whenever JSTL needs to convert "string" value to a complex data type for example java.util.Date and it does not find a custom tag for its conversion,  it applies setAsText() method.  If it does not find the JSF implementation files, it throws the above error.   I find it odd that this method is bundled into JSF implementation.

In the above case, I added the fmt tag to parse the date:

< fmt:parseDate var="pped1" value="${s_pped}" type="date" pattern="MM/dd/yyyy" scope="request"  / >


That resolved the issue.

No comments:

Post a Comment