You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by Dipita Shah <di...@yahoo.com> on 2009/06/23 20:09:15 UTC

Can you have 2 html pages map to one java source file?

Hi,
I am trying to figure out if I can configure two html pages map to the same java
source file - the reason is the java source file is doing lots of manipulations
of the objects/code and I don't want to duplicate it in two places -
unfortunately, the code (which I have inheritted,) was not written in object
oriented fashion so refactoring all the code is going to be a lot of work - am
trying to find out the easiest way that I can reuse code that is needed in two
pages that have similar things but flows are different - e.g. one page is
fowarding to a certain page and the other page will forward to another page..

Thoughts on how I can get this to work without having to refactor all the code?

Thx!
Dipita


Re: Can you have 2 html pages map to one java source file?

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

Dipita Shah wrote:

> I am trying to figure out if I can configure two html pages map to the same java
> source file


Yep this is supported. You need to manually map the templates to the 
Page in click.xml:

   <click-app charset="UTF-8">

     <pages package="com.mycorp.page">
       <page path="customer.htm" classname="CustomerPage"/>
       <page path="customer2.htm" classname="CustomerPage"/>
     </pages>

   </click-app>

It might even work with automapping (haven't tested) so you only need 
to declare the following (by default customer.htm -> CustomerPage 
should be mapped automatically):

   <click-app charset="UTF-8">

     <pages package="com.mycorp.page">
       <page path="customer2.htm" classname="CustomerPage"/>
     </pages>

   </click-app>


There are some limitations when using multiple templates though. For 
example you cannot use the methods:

   getContext().getPagePath(Page.class);
   getContext().createPage(Page.class);

If you do it will throw an exception that Click doesn't know which 
template to use. Instead you will need to use the overloaded methods 
which accepts the path as argument:

   getContext().getPagePath(String template);
   getContext().createPage(String template);


kind regards

bob