Hi Mike,

Sorry for the late reply. I believe the PageScopeResolver is suppose to resolve this issue by making pages prototype. The Click examples uses the same approach so not 100% sure why you are seeing different behavior. Could you post your click.xml and spring.xml here, perhaps its a configuration issue?

kind regards

bob

On 3/02/2010 10:02 AM, Mike W wrote:


Yes, it's the same.

elloWorldPage.onRender(): this.hashCode = 18557807
[Click] [info ] renderTemplate: /hello-world.htm - 131 ms
[Click] [info ] handleRequest: /hello-world.htm - 171 ms
[Click] [debug] GET http://localhost:8080/lamapp/hello-world.htm
HelloWorldPage.onRender(): this.hashCode = 18557807

On February 2, 2010 at 10:08 PM Bob Schellink <[email protected]> wrote:

 > Hmm, sounds as if Spring is creating a singleton Page instance and
reserving it each request.
 >
 > If you print the Page hashcode do you receive the same value each
request?
 >
 > public void onRender() {
 > System.out.println("Hash : " + this.getHashcode());
 > }
 >
 > kind regards
 >
 > bob
 >
 >
 > On 3/02/2010 08:31 AM, Mike W wrote:
 > >
 > >
 > > Thanks for the quick reply, Bob.
 > >
 > > Yes, that's what it's acting like but how does the page get set to
 > > Stateful? I'm not doing it by calling setStateful(true) or doing
 > > anything in click.xml. The Page is just HelloWorld with @Component
added
 > > to it.
 > >
 > > Does @Component/PageScopeResolver set the Page to stateful? I thought
 > > that was supposed to do the opposite -- set any injected spring
beans to
 > > 'prototype'.
 > >
 > > BTW, I'm using 2.1.0-RC1 if it makes a difference.
 > >
 > > Thanks again.
 > >
 > > On February 2, 2010 at 9:22 PM Bob Schellink <[email protected]> wrote:
 > >
 > > > Hi Mike,
 > > >
 > > > My guess is that the Page is set to stateful? Stateful Pages are
 > > created once and reused on
 > > > subsequent calls. You'll need to either put a guard against adding to
 > > the model twice or use the
 > > > onDestroy event to remove the value from the model.
 > > >
 > > > kind regards
 > > >
 > > > bob
 > > >
 > > > On 3/02/2010 02:42 AM, Mike W wrote:
 > > > >
 > > > >
 > > > > I'm new to Click and I'm trying to integrate a Spring DAO into the
 > > > > HelloWorldPage (at end) example.
 > > > >
 > > > > I'm getting a 'model already contains value' exception on the
second
 > > > > call to the onRender() method so it appears that the page is being
 > > > > reused instead of recreated. I guess I'm not sure what the
 > > > > PageScopeResolver is supposed to do.
 > > > >
 > > > > I added @Component (with the intention of adding @Resource for DAOs
 > > > > later) to HelloWorldPage.java and
 > > > >
 > > > > <context:component-scan
 > > > > base-package="clickhello.page"
 > > > >
 > > > > scope-resolver="org.apache.click.extras.spring.PageScopeResolver"/>
 > > > >
 > > > > to my Spring beans configuration. If I take either of the above
changes
 > > > > out, the page can be re-rendered as expected.
 > > > >
 > > > > Thanks.
 > > > >
 > > > >
 > > > >
 > > > >
 > > > > package clickhello.page;
 > > > >
 > > > > import java.util.Date;
 > > > > import java.util.Random;
 > > > > import org.apache.click.Page;
 > > > > import org.apache.click.control.ActionLink;
 > > > >
 > > > > *...@component
 > > > > *public class HelloWorldPage extends Page {
 > > > > private static final Random randomGenerator = new Random();
 > > > > private Date date = new Date();
 > > > >
 > > > > public HelloWorldPage() {
 > > > > ActionLink refreshLink = new ActionLink("refresh");
 > > > > ActionLink randomLink = new ActionLink("random", this, "onRandom");
 > > > >
 > > > > addControl(refreshLink);
 > > > > addControl(randomLink);
 > > > > }
 > > > >
 > > > > public boolean onRandom() {
 > > > > long maximum = System.currentTimeMillis();
 > > > > long random = randomGenerator.nextLong() % maximum;
 > > > > date = new Date(random);
 > > > > return true;
 > > > > }
 > > > >
 > > > > @Override
 > > > > public void onRender() {
 > > > > addModel("dateAndTime", date);
 > > > > }
 > > > > }
 > > > >
 > > > >
 > > > >
 > > >
 >

Reply via email to