1

I'm trying for the first time to use JSF but I don't understand JSP taglibs for JSF.

Under Eclipse (Indigo) when I create a new JSP file, I can choose between some templates :

  • New JavaServer Faces (JSF) Page (html)
  • New JavaServer Faces (JSF) Page (xhtml)
  • New JavaServer Faces (JSF) Page (xhtml, xml syntax)
  • ...

html template uses <%@ taglib prefix="..." uri="..." %> whereas xhtml template uses <html xmlns:...="...">.

When I choose xhtml template JSF taglib seem to be not supported because when I use <h:outputText value="#{bean.beanMethod}" /> I received Exception :

[#|2012-10-04T10:51:45.734+0200|WARNING|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=39;_ThreadName=Thread-2;|ApplicationDispatcher[/testjsf] PWC1231: Servlet.service() for servlet jsp threw exception org.apache.jasper.JasperException: /b.jsp(14,25) PWC6228: #{...} not allowed in a template text body. at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:81) at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:376) at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:188) at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:755) at org.apache.jasper.compiler.Node$ELExpression.accept(Node.java:947) at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2297) at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2347) at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2353) at org.apache.jasper.compiler.Node$Root.accept(Node.java:499) at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2297) at org.apache.jasper.compiler.Validator.validate(Validator.java:1882) at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:223) at org.apache.jasper.compiler.Compiler.compile(Compiler.java:451) at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:625) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539) at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:787) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:649) at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:483) at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:454) at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:350) at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:300) at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:546) at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:364) at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:154) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:100) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:722)

With html template, it works.

So how can I use JSF with xhtml template ?

It works using :

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">

AND

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

together, but I believed that declaring xmlns would replace <%@ taglib %> directive ?

Thank you for your help

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Olivier J.
  • 3,115
  • 11
  • 48
  • 71

1 Answers1

2

JSP has been deprecated as JSF 2.0 view technology almost 3 years ago. Why are you trying to use it?


Coming back to your concrete problem:

PWC6228: #{...} not allowed in a template text body.

This basically means that the <h:outputText> has not been parsed by the FacesServlet and is thus interpreted as plain template text, including the EL expressions. However, #{} in template text as in <p>#{foo}</p> is not supported in JSP. It's only supported in its successor Facelets.

The <h:outputText> not being parsed by the FacesServlet can only mean that the request URL as appears in the browser's address bar didn't match the <url-pattern> of the FacesServlet as definied in the webapp's /WEB-INF/web.xml. This way the FacesServlet won't be invoked and all JSF components won't be parsed and be treated as plain text.

Perhaps you've mapped it on *.xhtml which explains that Facelets files work fine? You should then open it by b.xhtml instead of b.jsp.

However, as said, JSP is deprecated since JSF 2.0. It doesn't allow you to use all the JSF 2.0 awesomeness such as <h:head>, <f:ajax>, etc, let alone the Facelet templating awesomeness. Forget JSP and stick to its successor Facelets.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thank you for this clarification but I don't understand why with .xhtml extension, it's parsed by the FacesServlet since my url-pattern in my web.xml is /faces/* so it should work for none or both, no ? I've seen that GlassFish (my case) and others application servers automaticaly map some pattern (/faces/*, *.jsf) with FacesServlet but in my case, when I remove /faces/* pattern in web.xml, none of the .jsp or .xhtml pages are parsed anymore...I suspect maybe bad configuration...I don't know (PS: previoux comment was incomplete sorry) – Olivier J. Oct 04 '12 at 15:31