Announcement Announcement Module
Collapse
No announcement yet.
Is dynamic include possible ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is dynamic include possible ?

    Hello,

    I am trying to convert existing apps to Spring Webflow, and I am facing the following problem :

    All our pages are of the following form :

    Code:
    <jsp:forward page='common/page.jsp'>
      <jsp:param name='page' value='../pages/pagecontent.jsp'/>
    </jsp:forward>
    The page.jsp file contains a common layout, in which the different blocks are included. Typically :

    Code:
    <html>
      <jsp:include page="head.jsp"/>
      <body>
        <jsp:include page="header.jsp"/>
        <jsp:include page="menu.jsp"/>
        <jsp:include page='<%= request.getParameter("page") %>'/>
        <jsp:include page="footer.jsp"/>
      </body>
    </html>
    We have used this configuration for years with Struts, without any problem. Now, we can get it to work with WebFlow. We get the following error :

    Code:
    /jsp/common/page.jsp:1: org.xml.sax.SAXParseException: The value of attribute
    "page" associated with an element type "jsp:include" must not contain the
    '<' character.
    What I do not understand is why the page would be parsed by a Sax Parser, since it is not XML ?

    To break the problem in parts, we tried to modify the phonebook example, replacing :

    Code:
    <%@ include file="includeTop.jsp" %>
    with :

    Code:
    <jsp:include page='<%="includeTop.jsp" %>'/>
    Here, we do not get a parsing error, which seems to show that there must be something wrong in the other app that causes the JSP page to be Sax Parsed.

    But we now have another error : the searchCriteria.jsp page now displays an error message :

    Please provide valid search criteria
    and the input fields are not dispalyed.

    Theis seems to indicate that dynamic include is not possible. Is that true ? Unfortunately, that would make WebFlow useless for us

    Is there another way to get dynamic include ?

  • #2
    Have you tried using this instead?

    Code:
    <html>
      <jsp:include page="head.jsp"/>
      <body>
        <jsp:include page="header.jsp"/>
        <jsp:include page="menu.jsp"/>
        <jsp:include page='${param.page}'/>
        <jsp:include page="footer.jsp"/>
      </body>
    </html>
    Also, what does the stack trace for the exception reveal about where the XML parser is getting called from?

    Comment


    • #3
      SWF should have no impact on JSP compiling. Are you also upgrading from an earlier JSP version to JSP 2.0?

      Erwin

      Comment


      • #4
        There are two different problems. First, if we use :

        Code:
        <jsp:include page='${param.page}'/>
        We get the following error:

        Code:
        java.io.FileNotFoundException: /phonebook/WEB-INF/jsp/${param.page}
        	at com.caucho.servlets.FileServlet.service(FileServlet.java:257)
        	at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106)
        	at com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain.java:115)
        	at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
        	at com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherImpl.java:485)
        	at com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherImpl.java:350)
        	at com.caucho.jsp.PageContextImpl.include(PageContextImpl.java:927)
        	at _jsp._web_22dinf._jsp._page2__jsp._jspService(WEB-INF/jsp/page2.jsp:1)
        	at com.caucho.jsp.JavaPage.service(JavaPage.java:60)
        	at com.caucho.jsp.Page.pageservice(Page.java:570)
        	at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:179)
        	at com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain.java:115)
        	at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
        	at com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherImpl.java:485)
        	at com.caucho.server.webapp.RequestDispatcherImpl.include(RequestDispatcherImpl.java:350)
        	at com.caucho.jsp.PageContextImpl.include(PageContextImpl.java:927)
        	at com.caucho.jsp.PageContextImpl.include(PageContextImpl.java:882)
        	at _jsp._web_22dinf._jsp._page__jsp._jspService(WEB-INF/jsp/page.jsp:1)
        	at com.caucho.jsp.JavaPage.service(JavaPage.java:60)
        	at com.caucho.jsp.Page.pageservice(Page.java:570)
        	at com.caucho.server.dispatch.PageFilterChain.doFilter(PageFilterChain.java:179)
        	at com.caucho.server.webapp.DispatchFilterChain.doFilter(DispatchFilterChain.java:115)
        	at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
        	at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:277)
        	at com.caucho.server.webapp.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:106)
        	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:142)
        	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:247)
        	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1105)
        	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:841)
        	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:755)
        	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396)
        	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:115)
        	at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
        	at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106)
        	at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:173)
        	at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
        	at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:274)
        	at com.caucho.server.port.TcpConnection.run(TcpConnection.java:511)
        	at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:520)
        	at com.caucho.util.ThreadPool.run(ThreadPool.java:442)
        	at java.lang.Thread.run(Thread.java:595)
        Note that :

        Code:
        <c:out value="/${param.page}"/>
        we get the ${param.page} evaluated correctly.

        The second error is obtained if we use :
        Code:
        <jsp:include page='searchCriteria.jsp'/>
        In that case, the include works fine but the result page display the error messae :

        Please provide valid search criteria
        Which is the validation error message for the form, displayed by the <spring:hasBindErrors> element. (As it is the first display of the form, there should not be any validation)

        However if we use :

        Code:
        <%@ include file="searchCriteria.jsp" %>
        Everything works fine.

        Comment


        • #5
          You can only directly use EL expression (${...}) when using JSP 2.0 and Servlet API 2.4. Make sure your webapp uses these and a container that supports them (e.g. Tomcat 5).

          Erwin

          Comment


          • #6
            Thanks ! It was a configuration problem, with two versions of JSP conflicting. It works fine now.

            Comment


            • #7
              One seems to be able to include JSP pages, but for some reason not jspf? Does anyone know how to configure that? (I'm still a newbie to spring).

              Comment


              • #8
                You can include JSPF (JSP fragments).
                Spring or SWF have no effect on this, this is just the Servlet API and your Servlet engine (e.g. Tomcat or Jetty).

                Erwin

                Comment


                • #9
                  Originally posted by klr8 View Post
                  You can include JSPF (JSP fragments).
                  Spring or SWF have no effect on this, this is just the Servlet API and your Servlet engine (e.g. Tomcat or Jetty).

                  Erwin
                  Hmmmmm it's not quite what I'm after I've discovered. I've now just created a jax-ws WebService that will expose all my persistent objects and then will use PHP-5 to render the returned data for now (reason for php is the site I'm building this for is php and we're moving it to java, so until I start work on a proper web ui for it, php would fit the bill for doing basic stuff like outputting html nicely).

                  Comment

                  Working...
                  X