You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris <ch...@gmx.at> on 2015/04/22 23:47:45 UTC

setting cookie

Hi all,

I would like to call a certain JS method in the #renderHead method based on whether a cookie is set:

I am getting a Last cause: org.apache.wicket.response.StringResponse cannot be cast to org.apache.wicket.request.http.WebResponse exception.
Is it still possible to do this in the #renderHead method?

if (cookie == null) {
	response.render(OnDomReadyHeaderItem.forScript("show();"));
            cookieUtils.save(key, value);
} else {
	response.render(OnDomReadyHeaderItem.forScript("hide();"));
}

Thanks, Chris

Re: setting cookie

Posted by Martin Grigorov <mg...@apache.org>.
This is a bug.
https://issues.apache.org/jira/browse/WICKET-5893
Thanks!

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Fri, Apr 24, 2015 at 2:11 AM, Chris <ch...@gmx.at> wrote:

> Hi Martin,
>
> I would like to place the cookie statement in the renderHead as based on
> this I would like to show/hide JS bar.
>
>    @Override
>     public void renderHead(IHeaderResponse response) {
>         super.renderHead(response);
>
>         Cookie cookie = cookieUtils.getCookie("vis");
>         if (cookie == null) {
>             response.render(OnDomReadyHeaderItem.forScript("bar_show();"));
>             cookieUtils.save("vis", "true");
>         } else {
>             response.render(OnDomReadyHeaderItem.forScript("bar_hide();"));
>         }
>     }
>
> Trace:
>
> Last cause: org.apache.wicket.response.StringResponse cannot be cast to
> org.apache.wicket.request.http.WebResponse
> WicketMessage: Exception in rendering component: [HtmlHeaderContainer
> [Component id = _header_0]]
>
> Root cause:
>
> java.lang.ClassCastException: org.apache.wicket.response.StringResponse
> cannot be cast to org.apache.wicket.request.http.WebResponse
>      at
> org.apache.wicket.util.cookies.CookieUtils.getWebResponse(CookieUtils.java:362)
>      at
> org.apache.wicket.util.cookies.CookieUtils.save(CookieUtils.java:304)
>      at
> org.apache.wicket.util.cookies.CookieUtils.save(CookieUtils.java:190)
>
> Thanks a lot,
> Chris
>
>
> > Am 23.04.2015 um 07:43 schrieb Martin Grigorov <mg...@apache.org>:
> >
> > It seems you have changed the response to StringResponse earlier and you
> > try to write a Cookie into it.
> >
> > Please paste the stacktrace if you need more help.
> > On Apr 23, 2015 12:48 AM, "Chris" <ch...@gmx.at> wrote:
> >
> >> Hi all,
> >>
> >> I would like to call a certain JS method in the #renderHead method based
> >> on whether a cookie is set:
> >>
> >> I am getting a Last cause: org.apache.wicket.response.StringResponse
> >> cannot be cast to org.apache.wicket.request.http.WebResponse exception.
> >> Is it still possible to do this in the #renderHead method?
> >>
> >> if (cookie == null) {
> >>        response.render(OnDomReadyHeaderItem.forScript("show();"));
> >>            cookieUtils.save(key, value);
> >> } else {
> >>        response.render(OnDomReadyHeaderItem.forScript("hide();"));
> >> }
> >>
> >> Thanks, Chris
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: setting cookie

Posted by Chris <ch...@gmx.at>.
Hi Martin,

I would like to place the cookie statement in the renderHead as based on this I would like to show/hide JS bar.

   @Override
    public void renderHead(IHeaderResponse response) {
        super.renderHead(response);

        Cookie cookie = cookieUtils.getCookie("vis");
        if (cookie == null) {
            response.render(OnDomReadyHeaderItem.forScript("bar_show();"));
            cookieUtils.save("vis", "true");
        } else {
            response.render(OnDomReadyHeaderItem.forScript("bar_hide();"));
        }
    }

Trace:

Last cause: org.apache.wicket.response.StringResponse cannot be cast to org.apache.wicket.request.http.WebResponse
WicketMessage: Exception in rendering component: [HtmlHeaderContainer [Component id = _header_0]]

Root cause:

java.lang.ClassCastException: org.apache.wicket.response.StringResponse cannot be cast to org.apache.wicket.request.http.WebResponse
     at org.apache.wicket.util.cookies.CookieUtils.getWebResponse(CookieUtils.java:362)
     at org.apache.wicket.util.cookies.CookieUtils.save(CookieUtils.java:304)
     at org.apache.wicket.util.cookies.CookieUtils.save(CookieUtils.java:190)

Thanks a lot,
Chris


> Am 23.04.2015 um 07:43 schrieb Martin Grigorov <mg...@apache.org>:
> 
> It seems you have changed the response to StringResponse earlier and you
> try to write a Cookie into it.
> 
> Please paste the stacktrace if you need more help.
> On Apr 23, 2015 12:48 AM, "Chris" <ch...@gmx.at> wrote:
> 
>> Hi all,
>> 
>> I would like to call a certain JS method in the #renderHead method based
>> on whether a cookie is set:
>> 
>> I am getting a Last cause: org.apache.wicket.response.StringResponse
>> cannot be cast to org.apache.wicket.request.http.WebResponse exception.
>> Is it still possible to do this in the #renderHead method?
>> 
>> if (cookie == null) {
>>        response.render(OnDomReadyHeaderItem.forScript("show();"));
>>            cookieUtils.save(key, value);
>> } else {
>>        response.render(OnDomReadyHeaderItem.forScript("hide();"));
>> }
>> 
>> Thanks, Chris


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


Re: setting cookie

Posted by Martin Grigorov <mg...@apache.org>.
It seems you have changed the response to StringResponse earlier and you
try to write a Cookie into it.

Please paste the stacktrace if you need more help.
On Apr 23, 2015 12:48 AM, "Chris" <ch...@gmx.at> wrote:

> Hi all,
>
> I would like to call a certain JS method in the #renderHead method based
> on whether a cookie is set:
>
> I am getting a Last cause: org.apache.wicket.response.StringResponse
> cannot be cast to org.apache.wicket.request.http.WebResponse exception.
> Is it still possible to do this in the #renderHead method?
>
> if (cookie == null) {
>         response.render(OnDomReadyHeaderItem.forScript("show();"));
>             cookieUtils.save(key, value);
> } else {
>         response.render(OnDomReadyHeaderItem.forScript("hide();"));
> }
>
> Thanks, Chris