You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@click.apache.org by "Bob Schellink (JIRA)" <ji...@apache.org> on 2009/07/16 18:31:14 UTC

[jira] Created: (CLK-568) Add ability to use templates with custom extensions

Add ability to use templates with custom extensions
---------------------------------------------------

                 Key: CLK-568
                 URL: https://issues.apache.org/jira/browse/CLK-568
             Project: Click
          Issue Type: New Feature
          Components: core
            Reporter: Bob Schellink
            Assignee: Bob Schellink


A recurring question on the user list is the ability to map alternative extensions as Page class templates instead of the default ".htm".

We could add a method ConfigService#isTemplate(String path), that can be invoked (at app startup) to check if a template is .htm/.jsp. Users can then override this single method to map alternative extensions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: AW: [jira] Created: (CLK-568) Add ability to use templates with custom extensions

Posted by Bob Schellink <sa...@gmail.com>.
Hi Jozsef,

I've recently checked in a small change[1] to the XmlConfigService#isJsp 
implementation to make it more robust. With this change in place, your 
modification of performRender should not be necessary anymore.

kind regards

bob

[1]:http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/service/XmlConfigService.java?r1=793525&r2=794701&diff_format=h

jozsef.gabor@bluewin.ch wrote:
> Hello. This is my favorite issue.
> 
> Currently I use a small hack in order to generate stylesheet from velocity template.
> Example: http://212.25.31.150/shop2/style.css
> 
> 
> First I tell the ClickServlet to trigger for special extensions in the deployment descriptor. (web.xml).
> 
> 	<servlet-mapping>
> 		<servlet-name>SpringClickServlet</servlet-name>
> 		<url-pattern>*.htm</url-pattern>
> 		<url-pattern>/robots.txt</url-pattern>
> 		<url-pattern>/style.css</url-pattern>
> 	</servlet-mapping>
> 
> 
> 
> 
> 
> Small modification of performRender method in the ClickServlet is necessary.
> It is not perfect solution because it prevents using jsp pages. (IMHO jsp is a nightmare)
> 
>     /**
>      * Performs rendering of the specified page.
>      *
>      * @param page page to render
>      * @param context the request context
>      * @throws java.lang.Exception if error occurs
>      */
>     protected void performRender(Page page, Context context) throws Exception {
> 
>         final HttpServletRequest request = context.getRequest();
>         final HttpServletResponse response = context.getResponse();
> 
>         if (StringUtils.isNotBlank(page.getRedirect())) {
>             String url = page.getRedirect();
> 
>             url = response.encodeRedirectURL(url);
> 
>             if (logger.isTraceEnabled()) {
>                 logger.debug("   redirect: " + url);
> 
>             } else if (logger.isDebugEnabled()) {
>                 logger.debug("redirect: " + url);
>             }
> 
>             response.sendRedirect(url);
> 
>         } else if (StringUtils.isNotBlank(page.getForward())) {
>             // Indicates the request is forwarded
>             request.setAttribute(CLICK_FORWARD, CLICK_FORWARD);
> 
>             if (logger.isTraceEnabled()) {
>                 logger.debug("   forward: " + page.getForward());
> 
>             } else if (logger.isDebugEnabled()) {
>                 logger.debug("forward: " + page.getForward());
>             }
> 
>             if (page.getForward().endsWith(".jsp")) {
>                 renderJSP(page);
> 
>             } else {
>                 RequestDispatcher dispatcher =
>                     request.getRequestDispatcher(page.getForward());
> 
>                 dispatcher.forward(request, response);
>             }
> 
>         } else if (page.getPath() != null) {
>         	// MODIFICATION JGA ---------------------
>         	/*
>             String pagePath = page.getPath();
> 
>             // Check if request is a JSP page
>             if (pagePath.endsWith(".jsp") || configService.isJspPage(pagePath)) {
>                 // CLK-141. Set pagePath as the forward value.
>                 page.setForward(StringUtils.replace(pagePath, ".htm", ".jsp"));
> 
>                 // Indicates the request is forwarded
>                 request.setAttribute(CLICK_FORWARD, CLICK_FORWARD);
>                 renderJSP(page);
> 
>             } else {
>                 renderTemplate(page);
>             }
>             */
>             renderTemplate(page);
>             // MODIFICATION JGA ---------------------
> 
>         } else {
>             if (logger.isTraceEnabled()) {
>                 logger.debug("   path not defined for " + page.getClass().getName());
> 
>             } else if (logger.isDebugEnabled()) {
>                 logger.debug("path not defined for " + page.getClass().getName());
>             }
>         }
>     }
> 
> 
> 


AW: [jira] Created: (CLK-568) Add ability to use templates with custom extensions

Posted by "jozsef.gabor@bluewin.ch" <jo...@bluewin.ch>.
Hello. This is my favorite issue.

Currently I use a small hack in order to generate stylesheet from velocity template.
Example: http://212.25.31.150/shop2/style.css


First I tell the ClickServlet to trigger for special extensions in the deployment descriptor. (web.xml).

	<servlet-mapping>
		<servlet-name>SpringClickServlet</servlet-name>
		<url-pattern>*.htm</url-pattern>
		<url-pattern>/robots.txt</url-pattern>
		<url-pattern>/style.css</url-pattern>
	</servlet-mapping>





Small modification of performRender method in the ClickServlet is necessary.
It is not perfect solution because it prevents using jsp pages. (IMHO jsp is a nightmare)

    /**
     * Performs rendering of the specified page.
     *
     * @param page page to render
     * @param context the request context
     * @throws java.lang.Exception if error occurs
     */
    protected void performRender(Page page, Context context) throws Exception {

        final HttpServletRequest request = context.getRequest();
        final HttpServletResponse response = context.getResponse();

        if (StringUtils.isNotBlank(page.getRedirect())) {
            String url = page.getRedirect();

            url = response.encodeRedirectURL(url);

            if (logger.isTraceEnabled()) {
                logger.debug("   redirect: " + url);

            } else if (logger.isDebugEnabled()) {
                logger.debug("redirect: " + url);
            }

            response.sendRedirect(url);

        } else if (StringUtils.isNotBlank(page.getForward())) {
            // Indicates the request is forwarded
            request.setAttribute(CLICK_FORWARD, CLICK_FORWARD);

            if (logger.isTraceEnabled()) {
                logger.debug("   forward: " + page.getForward());

            } else if (logger.isDebugEnabled()) {
                logger.debug("forward: " + page.getForward());
            }

            if (page.getForward().endsWith(".jsp")) {
                renderJSP(page);

            } else {
                RequestDispatcher dispatcher =
                    request.getRequestDispatcher(page.getForward());

                dispatcher.forward(request, response);
            }

        } else if (page.getPath() != null) {
        	// MODIFICATION JGA ---------------------
        	/*
            String pagePath = page.getPath();

            // Check if request is a JSP page
            if (pagePath.endsWith(".jsp") || configService.isJspPage(pagePath)) {
                // CLK-141. Set pagePath as the forward value.
                page.setForward(StringUtils.replace(pagePath, ".htm", ".jsp"));

                // Indicates the request is forwarded
                request.setAttribute(CLICK_FORWARD, CLICK_FORWARD);
                renderJSP(page);

            } else {
                renderTemplate(page);
            }
            */
            renderTemplate(page);
            // MODIFICATION JGA ---------------------

        } else {
            if (logger.isTraceEnabled()) {
                logger.debug("   path not defined for " + page.getClass().getName());

            } else if (logger.isDebugEnabled()) {
                logger.debug("path not defined for " + page.getClass().getName());
            }
        }
    }



[jira] Updated: (CLK-568) Add ability to use templates with custom extensions

Posted by "Bob Schellink (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLK-568?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bob Schellink updated CLK-568:
------------------------------

    Attachment: istemplate.patch

Attached is a patch for this issue. It is heavily commented, but only about 6 lines of code to implement.

> Add ability to use templates with custom extensions
> ---------------------------------------------------
>
>                 Key: CLK-568
>                 URL: https://issues.apache.org/jira/browse/CLK-568
>             Project: Click
>          Issue Type: New Feature
>          Components: core
>            Reporter: Bob Schellink
>            Assignee: Bob Schellink
>         Attachments: istemplate.patch
>
>
> A recurring question on the user list is the ability to map alternative extensions as Page class templates instead of the default ".htm".
> We could add a method ConfigService#isTemplate(String path), that can be invoked (at app startup) to check if a template is .htm/.jsp. Users can then override this single method to map alternative extensions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CLK-568) Add ability to use templates with custom extensions

Posted by "Bob Schellink (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLK-568?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bob Schellink updated CLK-568:
------------------------------

    Fix Version/s: 2.1.0

> Add ability to use templates with custom extensions
> ---------------------------------------------------
>
>                 Key: CLK-568
>                 URL: https://issues.apache.org/jira/browse/CLK-568
>             Project: Click
>          Issue Type: New Feature
>          Components: core
>            Reporter: Bob Schellink
>            Assignee: Bob Schellink
>             Fix For: 2.1.0
>
>         Attachments: istemplate.patch
>
>
> A recurring question on the user list is the ability to map alternative extensions as Page class templates instead of the default ".htm".
> We could add a method ConfigService#isTemplate(String path), that can be invoked (at app startup) to check if a template is .htm/.jsp. Users can then override this single method to map alternative extensions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (CLK-568) Add ability to use templates with custom extensions

Posted by "Bob Schellink (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLK-568?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bob Schellink resolved CLK-568.
-------------------------------

    Resolution: Fixed

fixed in trunk

> Add ability to use templates with custom extensions
> ---------------------------------------------------
>
>                 Key: CLK-568
>                 URL: https://issues.apache.org/jira/browse/CLK-568
>             Project: Click
>          Issue Type: New Feature
>          Components: core
>            Reporter: Bob Schellink
>            Assignee: Bob Schellink
>             Fix For: 2.1.0
>
>         Attachments: istemplate.patch
>
>
> A recurring question on the user list is the ability to map alternative extensions as Page class templates instead of the default ".htm".
> We could add a method ConfigService#isTemplate(String path), that can be invoked (at app startup) to check if a template is .htm/.jsp. Users can then override this single method to map alternative extensions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CLK-568) Add ability to use templates with custom extensions

Posted by "Malcolm Edgar (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLK-568?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12732258#action_12732258 ] 

Malcolm Edgar commented on CLK-568:
-----------------------------------

+1 looks good

> Add ability to use templates with custom extensions
> ---------------------------------------------------
>
>                 Key: CLK-568
>                 URL: https://issues.apache.org/jira/browse/CLK-568
>             Project: Click
>          Issue Type: New Feature
>          Components: core
>            Reporter: Bob Schellink
>            Assignee: Bob Schellink
>         Attachments: istemplate.patch
>
>
> A recurring question on the user list is the ability to map alternative extensions as Page class templates instead of the default ".htm".
> We could add a method ConfigService#isTemplate(String path), that can be invoked (at app startup) to check if a template is .htm/.jsp. Users can then override this single method to map alternative extensions.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.