You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Edvin Syse <ed...@sysedata.no> on 2007/11/03 23:49:03 UTC
WebWork and Wicket in the same application - session sharing?
Hi,
I have a large application written in WebWork, Spring and iBATIS. After
having started working with Wicket it really pains me that I have to
continue developing with WebWork, so I want to start migrating this
application on a page-by-page basis :)
I'm thinking I'd add a filter for wicket with a "/w" filter-mapping, and
migrate one page after another.
The WebWork session holds information about currently logged in user,
currently selected customer etc, and I need a way to sync this with a
Wicket session. I could ofcourse add this information to the url
everytime I hit a Wicket-page, but that seems really messy.
Any suggestions?
Sincerely,
Edvin Syse
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebWork and Wicket in the same application - session sharing?
Posted by John Patterson <jd...@gmail.com>.
I did exactly this for an old application. I wrote all the new code
in Wicket and just shared the log-in details from the session. They
would log in using wicket and the WW pages would check for the user
object in the HttpSession. Was very painless.
On 3 Nov 2007, at 16:49, Edvin Syse wrote:
> Hi,
>
> I have a large application written in WebWork, Spring and iBATIS.
> After having started working with Wicket it really pains me that I
> have to continue developing with WebWork, so I want to start
> migrating this application on a page-by-page basis :)
>
> I'm thinking I'd add a filter for wicket with a "/w" filter-
> mapping, and migrate one page after another.
>
> The WebWork session holds information about currently logged in
> user, currently selected customer etc, and I need a way to sync
> this with a Wicket session. I could ofcourse add this information
> to the url everytime I hit a Wicket-page, but that seems really messy.
>
> Any suggestions?
>
> Sincerely,
> Edvin Syse
>
>
> ---------------------------------------------------------------------
> 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: WebWork and Wicket in the same application - session sharing?
Posted by Edvin Syse <ed...@sysedata.no>.
Perfect!
It worked, and now I just need to create my own AuthorizationStrategy to
check the loggedinUser etc :) Thank you for the super help!
-- Edvin
Eelco Hillenius wrote:
> On 11/3/07, Eelco Hillenius <ee...@gmail.com> wrote:
>>> Sessions in WebWork are stored in the HttpSession like this:
>>>
>>> ActionContext.getContext().getSession().put(key, value);
>>>
>>> so this should be trivial. Thanks a lot!
>>>
>>> I have never needed to override newRequestCycle() in the WebApplication
>>> class before, and it seems getHttpSession() is not available in the
>>> default RequestCycle implementation. How do I get a hold of the
>>> HttpSession object?
>> Something like this in your application:
>>
>> private static class MyRequestCycle extends WebRequestCycle
>> {
>> public static MyRequestCycle get()
>> {
>> return (MyRequestCycle)RequestCycle.get();
>> }
>>
>> public MyRequestCycle(WebApplication application, WebRequest
>> request, Response response)
>> {
>> super(application, request, response);
>> }
>>
>> public HttpSession getHttpSession()
>> {
>> return getWebRequest().getHttpServletRequest().getSession(false);
>> }
>> }
>>
>> @Override
>> public RequestCycle newRequestCycle(Request request, Response response)
>> {
>> return new MyRequestCycle(this, (WebRequest)request, response);
>> }
>>
>> Of course, you could do this in a custom Wicket session or utility
>> class as well if you use:
>> ((WebRequestCycle)RequestCycle.get()).getWebRequest().getHttpServletRequest().getSession(false);
>
> And... why I would do this in a custom session and just call
> super.getAttribute("_webwork_user"):
> * Wicket encodes attributes in it's own way (prepends the application
> key to it), so you'd have to circumvent that;
> * It is not a certainty that the session store implementation that the
> Wicket session uses, is using the HttpSession to start with (might be
> a database or plain RAM for instance)
>
> So the safest thing to do here is go directly to the HttpSession. You
> can pretty much depend on the RequestCycle being a WebRequestCycle
> unless you're doing something really different.
>
> Eelco
>
> ---------------------------------------------------------------------
> 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: WebWork and Wicket in the same application - session sharing?
Posted by Eelco Hillenius <ee...@gmail.com>.
On 11/3/07, Eelco Hillenius <ee...@gmail.com> wrote:
> > Sessions in WebWork are stored in the HttpSession like this:
> >
> > ActionContext.getContext().getSession().put(key, value);
> >
> > so this should be trivial. Thanks a lot!
> >
> > I have never needed to override newRequestCycle() in the WebApplication
> > class before, and it seems getHttpSession() is not available in the
> > default RequestCycle implementation. How do I get a hold of the
> > HttpSession object?
>
> Something like this in your application:
>
> private static class MyRequestCycle extends WebRequestCycle
> {
> public static MyRequestCycle get()
> {
> return (MyRequestCycle)RequestCycle.get();
> }
>
> public MyRequestCycle(WebApplication application, WebRequest
> request, Response response)
> {
> super(application, request, response);
> }
>
> public HttpSession getHttpSession()
> {
> return getWebRequest().getHttpServletRequest().getSession(false);
> }
> }
>
> @Override
> public RequestCycle newRequestCycle(Request request, Response response)
> {
> return new MyRequestCycle(this, (WebRequest)request, response);
> }
>
> Of course, you could do this in a custom Wicket session or utility
> class as well if you use:
> ((WebRequestCycle)RequestCycle.get()).getWebRequest().getHttpServletRequest().getSession(false);
And... why I would do this in a custom session and just call
super.getAttribute("_webwork_user"):
* Wicket encodes attributes in it's own way (prepends the application
key to it), so you'd have to circumvent that;
* It is not a certainty that the session store implementation that the
Wicket session uses, is using the HttpSession to start with (might be
a database or plain RAM for instance)
So the safest thing to do here is go directly to the HttpSession. You
can pretty much depend on the RequestCycle being a WebRequestCycle
unless you're doing something really different.
Eelco
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebWork and Wicket in the same application - session sharing?
Posted by Eelco Hillenius <ee...@gmail.com>.
> Sessions in WebWork are stored in the HttpSession like this:
>
> ActionContext.getContext().getSession().put(key, value);
>
> so this should be trivial. Thanks a lot!
>
> I have never needed to override newRequestCycle() in the WebApplication
> class before, and it seems getHttpSession() is not available in the
> default RequestCycle implementation. How do I get a hold of the
> HttpSession object?
Something like this in your application:
private static class MyRequestCycle extends WebRequestCycle
{
public static MyRequestCycle get()
{
return (MyRequestCycle)RequestCycle.get();
}
public MyRequestCycle(WebApplication application, WebRequest
request, Response response)
{
super(application, request, response);
}
public HttpSession getHttpSession()
{
return getWebRequest().getHttpServletRequest().getSession(false);
}
}
@Override
public RequestCycle newRequestCycle(Request request, Response response)
{
return new MyRequestCycle(this, (WebRequest)request, response);
}
Of course, you could do this in a custom Wicket session or utility
class as well if you use:
((WebRequestCycle)RequestCycle.get()).getWebRequest().getHttpServletRequest().getSession(false);
Ugly, but it works.
Eelco
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebWork and Wicket in the same application - session sharing?
Posted by Edvin Syse <ed...@sysedata.no>.
> I don't know how WebWork stores it's sessions, but I imagine they do
> that just in the HttpSession, right? So all you need then is knowing
> what attribute (keys) are being used. You could write a custom Wicket
> session that proxies these, such as:
>
> class MySession extends WebSession {
> ...
> public User getUser() {
> return (User)MyRequestCycle.get().getHttpSession().getAttribute("_webwork_user");
> }
Sessions in WebWork are stored in the HttpSession like this:
ActionContext.getContext().getSession().put(key, value);
so this should be trivial. Thanks a lot!
I have never needed to override newRequestCycle() in the WebApplication
class before, and it seems getHttpSession() is not available in the
default RequestCycle implementation. How do I get a hold of the
HttpSession object?
-- Edvin
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: WebWork and Wicket in the same application - session sharing?
Posted by Eelco Hillenius <ee...@gmail.com>.
> I have a large application written in WebWork, Spring and iBATIS. After
> having started working with Wicket it really pains me that I have to
> continue developing with WebWork, so I want to start migrating this
> application on a page-by-page basis :)
>
> I'm thinking I'd add a filter for wicket with a "/w" filter-mapping, and
> migrate one page after another.
>
> The WebWork session holds information about currently logged in user,
> currently selected customer etc, and I need a way to sync this with a
> Wicket session. I could ofcourse add this information to the url
> everytime I hit a Wicket-page, but that seems really messy.
I don't know how WebWork stores it's sessions, but I imagine they do
that just in the HttpSession, right? So all you need then is knowing
what attribute (keys) are being used. You could write a custom Wicket
session that proxies these, such as:
class MySession extends WebSession {
...
public User getUser() {
return (User)MyRequestCycle.get().getHttpSession().getAttribute("_webwork_user");
}
Note that for the other way around, you can use WicketSessionFilter.
Eelco
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org