You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by ljnb01 <im...@gmail.com> on 2009/07/07 17:50:52 UTC

Anyone tried pre-compile JSP pages?

JSPs can be precompiled and commercial products do it.
They don't deliver the JSPs - only the precompiled files. How would Click
work in this case?

I need to work this out since we have an old code base/scripts that automate
pre-compiling jsps and now my click jsp's would not pass nightly build. Any
directions? 

Thank you.

-----
http://blogs.dengsoft.com/index.php/tech/ Java Technology Blog 
-- 
View this message in context: http://n2.nabble.com/Anyone-tried-pre-compile-JSP-pages--tp3220104p3220104.html
Sent from the click-user mailing list archive at Nabble.com.

Re: Anyone tried pre-compile JSP pages?

Posted by Malcolm Edgar <ma...@gmail.com>.
Interesting we should look at making those methods protected
visibility, as this class is designed to be extended.

regards Malcolm Edgar

On Wed, Jul 8, 2009 at 4:12 PM, Bob Schellink<sa...@gmail.com> wrote:
> If you don't want to manually map JSP to Page classes it might be worth
> looking at creating a customized ConfigService to handle the mapping.
>
> Look at subclassing XmlConfigService and overriding:
>
>  public boolean isJspPage(String path);
>  public Class getPageClass(String path);
>
>
> Here is rough untested example:
>
> public class MyConfigService extends XmlConfigService {
>
>  private Map<String, Class> jspPathMap = new ConcurrentHashMap();
>
>  public boolean is isJspPage(String path) {
>    boolean isJsp = super.isJspPage(path);
>    if (!isJsp) {
>        isJsp = jspPathMap.containsKey(path);
>    }
>    return isJsp;
>  }
>
>  public Class getPageClass(String path) {
>    Class cls = super.getPageClass(path);
>
>    // Check if Page class could be found for the path
>    if (cls == null) {
>
>        if (jspPathMap.containsKey(path)) {
>            cls = jspPathMap.get(path);
>
>        } else {
>            Class cls = lookupPageClass(path);
>
>            // If Page class was found for path, add it to jsp map
>            if (cls != null) {
>              jspPathMap.put(path, cls);
>            }
>        }
>    }
>    return cls;
>  }
>
>  private String lookupPageClass(String path) {
>     // Add rules to map path to Page class, e.g:
>     for (int i = 0; i < pagePackages.size(); i++) {
>       String pagesPackage =  pagePackages.get(i).toString();
>       Class cls = getPageClass(String path, pagesPackage);
>
>       if (cls != null) {
>         return cls.getName();
>       }
>     }
>     return null;
>  }
> }
>
> One problem with the above example is it uses a package private method so
> this class will have to be placed in the "org.apache.click.service" package.
>
> See ConfigService JavaDoc[1] on how to configure it.
>
> Hope this helps.
>
> bob
>
> [1]:http://incubator.apache.org/click/docs/click-api/org/apache/click/service/ConfigService.html
>
>
> ljnb01 wrote:
>>
>> Thanks Bob. But I really like auto mapping...
>>
>>
>> sabob wrote:
>>>
>>> ljnb01 wrote:
>>>>
>>>> JSPs can be precompiled and commercial products do it.
>>>> They don't deliver the JSPs - only the precompiled files. How would
>>>> Click
>>>> work in this case?
>>>>
>>>> I need to work this out since we have an old code base/scripts that
>>>> automate
>>>> pre-compiling jsps and now my click jsp's would not pass nightly build.
>>>> Any
>>>> directions?
>>>
>>> Interesting. To answer its probably worth explaining what is happening
>>> under the hood.
>>>
>>> At application startup Click recursively scans through the web folder
>>> looking for any JSP and htm templates. For every JSP and template found,
>>> Click
>>> attempts to find its matching Page class. It derives the Page class from
>>> the
>>> template name. This feature is called page-automapping[1].
>>>
>>> Problem with compiled JSPs is that there is no JSP template Click can use
>>> to lookup the corresponding Page class.
>>>
>>> My only suggestions at this point is to try and manually map the JSPs to
>>> Page classes.
>>>
>>> For example:
>>>
>>>  <pages package="com.myapp.page">
>>>    <!-- map index.jsp to com.myapp.page.Home -->
>>>    <page path="index.jsp" classname="Home"/>
>>>
>>>    <page path="customer/edit-customer.jsp"
>>> classname="customer.EditCustomer"/>
>>>    <page path="customer/view-customers.jsp"
>>> classname="customer.ViewCustomers"/>
>>>  </pages>
>>>
>>>
>>> kind regards
>>>
>>> bob
>>>
>>> [1]:
>>> http://incubator.apache.org/click/docs/user-guide/html/ch04s02.html#application-automapping
>>>
>>>
>>
>>
>> -----
>> http://blogs.dengsoft.com/index.php/tech/ Java Technology Blog
>
>
>

Re: Anyone tried pre-compile JSP pages?

Posted by Bob Schellink <sa...@gmail.com>.
If you don't want to manually map JSP to Page classes it might be worth looking 
at creating a customized ConfigService to handle the mapping.

Look at subclassing XmlConfigService and overriding:

   public boolean isJspPage(String path);
   public Class getPageClass(String path);


Here is rough untested example:

public class MyConfigService extends XmlConfigService {

   private Map<String, Class> jspPathMap = new ConcurrentHashMap();

   public boolean is isJspPage(String path) {
     boolean isJsp = super.isJspPage(path);
     if (!isJsp) {
         isJsp = jspPathMap.containsKey(path);
     }
     return isJsp;
   }

   public Class getPageClass(String path) {
     Class cls = super.getPageClass(path);

     // Check if Page class could be found for the path
     if (cls == null) {

         if (jspPathMap.containsKey(path)) {
             cls = jspPathMap.get(path);

         } else {
             Class cls = lookupPageClass(path);

             // If Page class was found for path, add it to jsp map
             if (cls != null) {
               jspPathMap.put(path, cls);
             }
         }
     }
     return cls;
   }

   private String lookupPageClass(String path) {
      // Add rules to map path to Page class, e.g:
      for (int i = 0; i < pagePackages.size(); i++) {
        String pagesPackage =  pagePackages.get(i).toString();
        Class cls = getPageClass(String path, pagesPackage);

        if (cls != null) {
          return cls.getName();
        }
      }
      return null;
   }
}

One problem with the above example is it uses a package private method so this 
class will have to be placed in the "org.apache.click.service" package.

See ConfigService JavaDoc[1] on how to configure it.

Hope this helps.

bob

[1]:http://incubator.apache.org/click/docs/click-api/org/apache/click/service/ConfigService.html


ljnb01 wrote:
> Thanks Bob. But I really like auto mapping...
> 
> 
> sabob wrote:
>> ljnb01 wrote:
>>> JSPs can be precompiled and commercial products do it.
>>> They don't deliver the JSPs - only the precompiled files. How would Click
>>> work in this case?
>>>
>>> I need to work this out since we have an old code base/scripts that
>>> automate
>>> pre-compiling jsps and now my click jsp's would not pass nightly build.
>>> Any
>>> directions? 
>>
>> Interesting. To answer its probably worth explaining what is happening
>> under the 
>> hood.
>>
>> At application startup Click recursively scans through the web folder
>> looking 
>> for any JSP and htm templates. For every JSP and template found, Click
>> attempts 
>> to find its matching Page class. It derives the Page class from the
>> template 
>> name. This feature is called page-automapping[1].
>>
>> Problem with compiled JSPs is that there is no JSP template Click can use
>> to 
>> lookup the corresponding Page class.
>>
>> My only suggestions at this point is to try and manually map the JSPs to
>> Page 
>> classes.
>>
>> For example:
>>
>>   <pages package="com.myapp.page">
>>     <!-- map index.jsp to com.myapp.page.Home -->
>>     <page path="index.jsp" classname="Home"/>
>>
>>     <page path="customer/edit-customer.jsp"
>> classname="customer.EditCustomer"/>
>>     <page path="customer/view-customers.jsp"
>> classname="customer.ViewCustomers"/>
>>   </pages>
>>
>>
>> kind regards
>>
>> bob
>>
>> [1]: 
>> http://incubator.apache.org/click/docs/user-guide/html/ch04s02.html#application-automapping
>>
>>
> 
> 
> -----
> http://blogs.dengsoft.com/index.php/tech/ Java Technology Blog 



Re: Anyone tried pre-compile JSP pages?

Posted by "Adrian A." <a....@gmail.com>.
> Thanks Bob. But I really like auto mapping...
Precompiling is not that much an issue for Click apps because
most of the code(if apps are written well) is in Java files not JSPs. 
The same like with *.htm files, the JSPs will contain mostly only one 
line of code with:
${form} or $(table) or ${panel).

Even more, for commercial applications, with Click it's much easier to 
use an obfuscator than all other web frameworks (one just needs to 
exclude from obfuscation the page names and the listener method names).

Adrian.


Re: Anyone tried pre-compile JSP pages?

Posted by ljnb01 <im...@gmail.com>.
Thanks Bob. But I really like auto mapping...


sabob wrote:
> 
> ljnb01 wrote:
>> JSPs can be precompiled and commercial products do it.
>> They don't deliver the JSPs - only the precompiled files. How would Click
>> work in this case?
>> 
>> I need to work this out since we have an old code base/scripts that
>> automate
>> pre-compiling jsps and now my click jsp's would not pass nightly build.
>> Any
>> directions? 
> 
> 
> Interesting. To answer its probably worth explaining what is happening
> under the 
> hood.
> 
> At application startup Click recursively scans through the web folder
> looking 
> for any JSP and htm templates. For every JSP and template found, Click
> attempts 
> to find its matching Page class. It derives the Page class from the
> template 
> name. This feature is called page-automapping[1].
> 
> Problem with compiled JSPs is that there is no JSP template Click can use
> to 
> lookup the corresponding Page class.
> 
> My only suggestions at this point is to try and manually map the JSPs to
> Page 
> classes.
> 
> For example:
> 
>   <pages package="com.myapp.page">
>     <!-- map index.jsp to com.myapp.page.Home -->
>     <page path="index.jsp" classname="Home"/>
> 
>     <page path="customer/edit-customer.jsp"
> classname="customer.EditCustomer"/>
>     <page path="customer/view-customers.jsp"
> classname="customer.ViewCustomers"/>
>   </pages>
> 
> 
> kind regards
> 
> bob
> 
> [1]: 
> http://incubator.apache.org/click/docs/user-guide/html/ch04s02.html#application-automapping
> 
> 


-----
http://blogs.dengsoft.com/index.php/tech/ Java Technology Blog 
-- 
View this message in context: http://n2.nabble.com/Anyone-tried-pre-compile-JSP-pages--tp3220104p3221739.html
Sent from the click-user mailing list archive at Nabble.com.

Re: Anyone tried pre-compile JSP pages?

Posted by Bob Schellink <sa...@gmail.com>.
ljnb01 wrote:
> JSPs can be precompiled and commercial products do it.
> They don't deliver the JSPs - only the precompiled files. How would Click
> work in this case?
> 
> I need to work this out since we have an old code base/scripts that automate
> pre-compiling jsps and now my click jsp's would not pass nightly build. Any
> directions? 


Interesting. To answer its probably worth explaining what is happening under the 
hood.

At application startup Click recursively scans through the web folder looking 
for any JSP and htm templates. For every JSP and template found, Click attempts 
to find its matching Page class. It derives the Page class from the template 
name. This feature is called page-automapping[1].

Problem with compiled JSPs is that there is no JSP template Click can use to 
lookup the corresponding Page class.

My only suggestions at this point is to try and manually map the JSPs to Page 
classes.

For example:

  <pages package="com.myapp.page">
    <!-- map index.jsp to com.myapp.page.Home -->
    <page path="index.jsp" classname="Home"/>

    <page path="customer/edit-customer.jsp" classname="customer.EditCustomer"/>
    <page path="customer/view-customers.jsp" classname="customer.ViewCustomers"/>
  </pages>


kind regards

bob

[1]: 
http://incubator.apache.org/click/docs/user-guide/html/ch04s02.html#application-automapping