You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Michael Fortin <mf...@monetizeit.com> on 2007/08/01 15:56:08 UTC

basic questions: cookies, session state

Hello,

I'm new to wicket and after going through the docs I still have some 
unanswered questions. If someone could answer them or point me in the 
right direction, I'd appreciate it.

- In other frameworks, if I want to save state between requests I add 
the attribute to the session.  How do different pages in wicket access 
the same session attribute?  There was just a post about this called 
'Sharing a model' that addresses this but with no example. How do you do 
that?

-  On every form submission I want to set the valid fields on a session 
object.  In spring I override the onBindAndValidate and iterate over the 
errors.  In Wicket, if there is no validation errors it's pretty simple, 
override the nested form's onSubmit but where do I get access to the 
model on invalid submits?

- How do I explicitly read and set a cookie?

- On session destroy I need to clean up my session attributes.  Do I 
override SessionStore and implement my own destroy method? 

Thanks,
Michael


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: basic questions: cookies, session state

Posted by Igor Vaynberg <ig...@gmail.com>.
On 8/1/07, Michael Fortin <mf...@monetizeit.com> wrote:
>
> Thanks Igor for your response.
>
> Sorry, I didn't explain myself clearly.  Partial form data can be
> valuable to us in some cases.  So, in the case of an incomplete or
> invalid form submission, we take the valid info and put it in a session
> placeholder.  If they don't complete the form we still evaluate what we
> have and possibly save the information when the session expires.
>
> Question one, is there a way to examine the model before the feedback
> panel gets returned?


wicket processing by default is atomic. either validation passes and all
models are updated, or it fails and none are updated.
what you can do is visit form components under a form, call isvalid() to see
if they are valid or not and then either save the raw user input getInput()
or save the type converted input getConvertedInput()

And two, how would I handle that session placeholder on session expire?
> There doesn't seem to be an obvious replacement for
> javax.servlet.http.HttpSessionListener#sessionDestroyed


like i said in my previous email, isessionstore.unbind() is what you want
afaict. if not you can still install  your own httpsessionlistener. see
WIcketSessionFilter to get access to wicket session object outside of wicket
requests.

-igor


Thanks again,
> Michael
>
>
>
> Igor Vaynberg wrote:
> > On 8/1/07, Michael Fortin <mf...@monetizeit.com> wrote:
> >
> >> - In other frameworks, if I want to save state between requests I add
> >> the attribute to the session.  How do different pages in wicket access
> >> the same session attribute?  There was just a post about this called
> >> 'Sharing a model' that addresses this but with no example. How do you
> do
> >> that?
> >>
> >
> >
> > class viewuserpage extends webpage {
> >   public viewuserpage(imodel<user> user) {
> >     add(new link("edit", user) {
> >       onclick() {
> >         setresponsepage(new edituserpage(getmodel());
> >         ^ pass the user model to the edit page
> >       }
> >    }
> > }
> >
> > class edituserpage extends webpage {
> >  public edituserpage(imodel<user> user) {
> >   ...
> >   }
> > }
> >
> >
> > -  On every form submission I want to set the valid fields on a session
> >
> >> object.  In spring I override the onBindAndValidate and iterate over
> the
> >> errors.
> >>
> >
> >
> > why exactly do you need to store field values in session?
> >
> > In Wicket, if there is no validation errors it's pretty simple,
> >
> >> override the nested form's onSubmit but where do I get access to the
> >> model on invalid submits?
> >>
> >
> >
> > if there is an error you cannot get to the invalid field's model because
> the
> > model isnt updated on errors. for example if you have a textfield with a
> > model that expects an integer and you put "a" then we cannot push the
> string
> > into the model. once again why do you need to have access to this?
> > feedbackpanel seems to cover the 90% usecase. for the rest you can use a
> > visitor to visit all invalid form components.
> >
> >
> > - How do I explicitly read and set a cookie?
> >
> >
> > ((WebRequest)getRequest()).getCookies();
> > ((WebResponse)getResponse()).add/deleteCookie(cookie);
> >
> > - On session destroy I need to clean up my session attributes.  Do I
> >
> >> override SessionStore and implement my own destroy method?
> >>
> >
> >
> > no. sessionstore only has one instance per application. destroy() is
> called
> > when application is destroyed - just like the javadoc says - you want
> > unbind() and dont forget to call super.
> >
> > -igor
> >
> >
> > Thanks,
> >
> >> Michael
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >>
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: basic questions: cookies, session state

Posted by Michael Fortin <mf...@monetizeit.com>.
Thanks Igor for your response.

Sorry, I didn't explain myself clearly.  Partial form data can be 
valuable to us in some cases.  So, in the case of an incomplete or 
invalid form submission, we take the valid info and put it in a session 
placeholder.  If they don't complete the form we still evaluate what we 
have and possibly save the information when the session expires.  

Question one, is there a way to examine the model before the feedback 
panel gets returned? 

And two, how would I handle that session placeholder on session expire? 
There doesn't seem to be an obvious replacement for 
javax.servlet.http.HttpSessionListener#sessionDestroyed

Thanks again,
Michael



Igor Vaynberg wrote:
> On 8/1/07, Michael Fortin <mf...@monetizeit.com> wrote:
>   
>> - In other frameworks, if I want to save state between requests I add
>> the attribute to the session.  How do different pages in wicket access
>> the same session attribute?  There was just a post about this called
>> 'Sharing a model' that addresses this but with no example. How do you do
>> that?
>>     
>
>
> class viewuserpage extends webpage {
>   public viewuserpage(imodel<user> user) {
>     add(new link("edit", user) {
>       onclick() {
>         setresponsepage(new edituserpage(getmodel());
>         ^ pass the user model to the edit page
>       }
>    }
> }
>
> class edituserpage extends webpage {
>  public edituserpage(imodel<user> user) {
>   ...
>   }
> }
>
>
> -  On every form submission I want to set the valid fields on a session
>   
>> object.  In spring I override the onBindAndValidate and iterate over the
>> errors.
>>     
>
>
> why exactly do you need to store field values in session?
>
> In Wicket, if there is no validation errors it's pretty simple,
>   
>> override the nested form's onSubmit but where do I get access to the
>> model on invalid submits?
>>     
>
>
> if there is an error you cannot get to the invalid field's model because the
> model isnt updated on errors. for example if you have a textfield with a
> model that expects an integer and you put "a" then we cannot push the string
> into the model. once again why do you need to have access to this?
> feedbackpanel seems to cover the 90% usecase. for the rest you can use a
> visitor to visit all invalid form components.
>
>
> - How do I explicitly read and set a cookie?
>
>
> ((WebRequest)getRequest()).getCookies();
> ((WebResponse)getResponse()).add/deleteCookie(cookie);
>
> - On session destroy I need to clean up my session attributes.  Do I
>   
>> override SessionStore and implement my own destroy method?
>>     
>
>
> no. sessionstore only has one instance per application. destroy() is called
> when application is destroyed - just like the javadoc says - you want
> unbind() and dont forget to call super.
>
> -igor
>
>
> Thanks,
>   
>> Michael
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>     
>
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: basic questions: cookies, session state

Posted by Igor Vaynberg <ig...@gmail.com>.
On 8/1/07, Michael Fortin <mf...@monetizeit.com> wrote:
>
>
> - In other frameworks, if I want to save state between requests I add
> the attribute to the session.  How do different pages in wicket access
> the same session attribute?  There was just a post about this called
> 'Sharing a model' that addresses this but with no example. How do you do
> that?


class viewuserpage extends webpage {
  public viewuserpage(imodel<user> user) {
    add(new link("edit", user) {
      onclick() {
        setresponsepage(new edituserpage(getmodel());
        ^ pass the user model to the edit page
      }
   }
}

class edituserpage extends webpage {
 public edituserpage(imodel<user> user) {
  ...
  }
}


-  On every form submission I want to set the valid fields on a session
> object.  In spring I override the onBindAndValidate and iterate over the
> errors.


why exactly do you need to store field values in session?

In Wicket, if there is no validation errors it's pretty simple,
> override the nested form's onSubmit but where do I get access to the
> model on invalid submits?


if there is an error you cannot get to the invalid field's model because the
model isnt updated on errors. for example if you have a textfield with a
model that expects an integer and you put "a" then we cannot push the string
into the model. once again why do you need to have access to this?
feedbackpanel seems to cover the 90% usecase. for the rest you can use a
visitor to visit all invalid form components.


- How do I explicitly read and set a cookie?


((WebRequest)getRequest()).getCookies();
((WebResponse)getResponse()).add/deleteCookie(cookie);

- On session destroy I need to clean up my session attributes.  Do I
> override SessionStore and implement my own destroy method?


no. sessionstore only has one instance per application. destroy() is called
when application is destroyed - just like the javadoc says - you want
unbind() and dont forget to call super.

-igor


Thanks,
> Michael
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>