here is how i would do it

class WelcomePage extends WebPage {
  public WelcomePage(long userId) {
     User user=getUser(userId);
     add(new Label("message", "welcome "+user.getName()));
  }
}

so now you have a welcome page that can display the correct message based on the login id you pass into the constructor.

then in your login page:
onsubmit() {
  setResponsePage(new WelcomePage(userId));
}


Maybe you dont even need to pass in the loggedin user id into the welcomepage as a constructor. you have to store that somewhere in the session right? maybe the welcome page can pull it out of session, then all you need to do is setResponsePage(new WelcomePage());

There is a signin example in wicket-examples project that shows this exact scenario.

-Igor



On 12/20/05, karthik Guru < [EMAIL PROTECTED]> wrote:
cool!
 
Ok here is what am trying. I have a 'login' page and on successful login sends the user to the 'welcome' page. On the onSubmit of login page i do this
 
Form form = new Form("loginForm"){
 public void onSubmit(){
  //get the user id , password and validate

  //this is my welcome page
  Welcome welcomePage = new Welcome();
  //it has a span with id "message"
  Component c = welcomePage.get("message");
  c.setModel(new Model("Welcome To Wicket Mr " + userId));
  setResponsePage(welcomePage);
 }
};
 
Now that you tell me that wicket maintains the page instance in the PageMap, can i do new Welcome( )?
S'd i be getting it from the PageMap instead?
 
I didnt do setResponsePage(Welcome.class) since am not sure how i can supply the model for the "message" component in the 'Welcome.html'
 
thanks
karthik

 
On 12/21/05, Igor Vaynberg <[EMAIL PROTECTED] > wrote:
after the page is rendered it is put into a PageMap. the pagemap lives in session and keeps the last 10  pages ( this number is configurable through application settings object). so when you submit a form or click a link the page is brought back from pagemap and the link/form handler is executed on it. the pagemap uses an mru algorithm to only keep the most recent pages - to reduce space taken up in session.

when you click a link the url contains the page id in the pagemap, the component path of the link object you clicked and what kind of interface to invoke on the component that is pointed to by the path ( in this case a link). from this information wicket can lookup the page that the link belongs to from the pagemap, find the right component, and then execute a callback method on it. in this case it would result in Link's onClick() handler being invoked.

similar happens for forms.


hope this helps, if you have more questions fire away.

-Igor



On 12/20/05, karthik Guru < [EMAIL PROTECTED] > wrote:
I'm still on the HelloWorld example. I can see that wicket has a component that corresponds to all the HTML tags in the html template file and they are being added to the HelloPage component in the constructor. I guess an instance of HelloPage is probably created (and with that all the contained components) when i request the html and then the page can pull the data from the model and render it.
What happens after that , is the HelloWorldPage instance discarded? When i submit, does wicket again instantiate a HelloWorldPage instance or pull it from some cache it has internally? Does it look at the html template, check the component hierarchy in the template, and then go look for an equivalent java component in the Page hierarchy and fill up the values from the request?
 
and wicket knows somehow that the form has been submitted and hence onSubmit needs to be called?
 
Can someone explain the behaviour.
 
thank you.
regards,
karthik
 
 
 



Reply via email to