Click
  1. Click
  2. CLK-141

Page.setPath to JSP Pages not working

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.4
    • Fix Version/s: 1.5 M1
    • Component/s: core
    • Labels:
      None
    • Environment:
      Linux Tomcat java 1.5

      Description

      Click servlet does not take JSP pages into consideration when rendering with a Page.getPath().

      eg. in your Page you have
      addModel("data", mydata)
      setPath("mypage.jsp")

      click uses renderTemplate() which only handles velocity templates.
      See attachment for my fix.

        Activity

        Hide
        Malcolm Edgar added a comment -

        Hi Huy,

        with JSP pages you have to forward to them using setForward() as JSP are forward to via the request dispatcher.

        I dont think this is discussed in the documentation.

        regards Malcolm Edgar

        Show
        Malcolm Edgar added a comment - Hi Huy, with JSP pages you have to forward to them using setForward() as JSP are forward to via the request dispatcher. I dont think this is discussed in the documentation. regards Malcolm Edgar
        Hide
        Huy Do added a comment -

        I have a use case for this as follows. I have a report. MyReport.java with my-report.htm where display a form to gather report criteria. On submit, the MyReport validates the form, then loads the report data into the model using addModel("data", mydata). I then just want to render the report using jsp, by using setPath("my-report-data.jsp"). Using setForward will force me into having a backing MyReportData.java which in this case serves no purpose.

        Please reconsider this use case and see my attachment for a patch to fix this. Thanks.

        Show
        Huy Do added a comment - I have a use case for this as follows. I have a report. MyReport.java with my-report.htm where display a form to gather report criteria. On submit, the MyReport validates the form, then loads the report data into the model using addModel("data", mydata). I then just want to render the report using jsp, by using setPath("my-report-data.jsp"). Using setForward will force me into having a backing MyReportData.java which in this case serves no purpose. Please reconsider this use case and see my attachment for a patch to fix this. Thanks.
        Hide
        Bob Schellink added a comment -

        Hi Huy,

        Will the attached patch work correctly when you have a template defined? If a path is specified e.g. "edit-customer.jsp" the patch will dispatch to this path instead of the template.

        What I am thinking is that if the path ends with .jsp, we should set the forward to this path instead.

        Will this work for you use case?

        regards

        bob

        Show
        Bob Schellink added a comment - Hi Huy, Will the attached patch work correctly when you have a template defined? If a path is specified e.g. "edit-customer.jsp" the patch will dispatch to this path instead of the template. What I am thinking is that if the path ends with .jsp, we should set the forward to this path instead. Will this work for you use case? regards bob
        Hide
        Huy Do added a comment -

        Hi Bob,

        The problem here is that I have one page which on entry loads a htm page and on post loads a jsp page. To get the template to work correctly, I would have to have a conditional in my getTemplate() method to know when to load my layout.htm or layout.jsp. This isn't nice. To really fix this problem, I think we need a setTemplate(String myTemplate) method as well. That way, your solution would work for me, because I could set the correct template.

        I'm currently not affected by this because I use sitemesh for my border templates.

        Regards,

        Huy

        Show
        Huy Do added a comment - Hi Bob, The problem here is that I have one page which on entry loads a htm page and on post loads a jsp page. To get the template to work correctly, I would have to have a conditional in my getTemplate() method to know when to load my layout.htm or layout.jsp. This isn't nice. To really fix this problem, I think we need a setTemplate(String myTemplate) method as well. That way, your solution would work for me, because I could set the correct template. I'm currently not affected by this because I use sitemesh for my border templates. Regards, Huy
        Hide
        Bob Schellink added a comment -

        I have checked in some code to resolve this issue.

        When setting the path to a JSP, ClickServlet will check if the path has a jsp extension, and set this as the new forward value, effectively overriding the current forward value.

        Setting the path value should work when moving from htm to jsp as well as jsp to jsp.

        >To really fix this problem, I think we need a setTemplate(String myTemplate) method as well.

        Nods, having a Page#setTemplate seems like a good idea. I will add this tonight.

        Show
        Bob Schellink added a comment - I have checked in some code to resolve this issue. When setting the path to a JSP, ClickServlet will check if the path has a jsp extension, and set this as the new forward value, effectively overriding the current forward value. Setting the path value should work when moving from htm to jsp as well as jsp to jsp. >To really fix this problem, I think we need a setTemplate(String myTemplate) method as well. Nods, having a Page#setTemplate seems like a good idea. I will add this tonight.
        Hide
        Bob Schellink added a comment -

        Fixed in trunk. Will be available for 1.5M1.

        Show
        Bob Schellink added a comment - Fixed in trunk. Will be available for 1.5M1.

          People

          • Assignee:
            Bob Schellink
            Reporter:
            Huy Do
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development