You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by wicket user <sa...@live.com> on 2012/05/30 00:41:30 UTC

handling user agent

Hi all,

I wondering what will be the difference if i use
*((WebRequest)RequestCycle.get().getRequest()).getHeader("User-Agent");* 

or 

*WebSession.get().getClientInfo().getUserAgent();*

As  the client info per session would be same . 
and If I need to control this on the WebApplication level , then how to
handle this ? 
I got some idea about RequestMapper but not sure I am on right track.  Peers
can anyone give some valuable suggestions. 

Thanks

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/handling-user-agent-tp4649565.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: handling user agent

Posted by wicket user <sa...@live.com>.
Awesome thanks alot !! 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/handling-user-agent-tp4649565p4649658.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: handling user agent

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

You have several options:
- use a IRequestMapper which will read the user agent and return : new
RenderPageRequestHandler(new PageProvider(UserAgentSpecificPage.class,
parameters))

- use IRequestCycleListener which implements #onBeginRequest() where
it reads the user agent and sets it as Session style (e.g.
Session.get().setStyle("android"))

- your page can implement IMarkupResourceStreamProvider and in its
#getResourceStream() you can read the user agent and construct
dynamically the markup

On Thu, May 31, 2012 at 7:42 PM, wicket user <sa...@live.com> wrote:
> just wondering how to implement it , i tried the following code not sure am i
> doing correct,
>
> public class MyMapper implements IRequestMapper {
>
>    private final IRequestMapper delegate;
>
>    public MyMapper(IRequestMapper delegate) {
>        this.delegate = delegate;
>    }
>
>    public IRequestHandler mapRequest(Request request) {
>        Url url = request.getUrl();
>        String user = WebSession.get().getClientInfo().getUserAgent();
>       //System.out.println(user);
>
>        return delegate.mapRequest(request.cloneWithUrl(url));
>    }
> }
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/handling-user-agent-tp4649565p4649628.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: handling user agent

Posted by wicket user <sa...@live.com>.
just wondering how to implement it , i tried the following code not sure am i
doing correct, 

public class MyMapper implements IRequestMapper {

    private final IRequestMapper delegate;
    
    public MyMapper(IRequestMapper delegate) {
        this.delegate = delegate;
    }
    
    public IRequestHandler mapRequest(Request request) {
        Url url = request.getUrl();
        String user = WebSession.get().getClientInfo().getUserAgent();
       //System.out.println(user);
        
        return delegate.mapRequest(request.cloneWithUrl(url));
    }
}

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/handling-user-agent-tp4649565p4649628.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: handling user agent

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

By using custom root request mapper this should be easy to achieve.

On Wed, May 30, 2012 at 7:23 PM, wicket user <sa...@live.com> wrote:
> Question was how to handle user agent on the application level , i dont wanna
> write same code on each page to check the user agent then render the
> appropriate page
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/handling-user-agent-tp4649565p4649584.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: handling user agent

Posted by wicket user <sa...@live.com>.
Question was how to handle user agent on the application level , i dont wanna
write same code on each page to check the user agent then render the
appropriate page 

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/handling-user-agent-tp4649565p4649584.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: handling user agent

Posted by Martin Grigorov <mg...@apache.org>.
On Wed, May 30, 2012 at 1:41 AM, wicket user <sa...@live.com> wrote:
> Hi all,
>
> I wondering what will be the difference if i use
> *((WebRequest)RequestCycle.get().getRequest()).getHeader("User-Agent");*
>
> or
>
> *WebSession.get().getClientInfo().getUserAgent();*
>
> As  the client info per session would be same .

The are the same. Just the latter is cached.

> and If I need to control this on the WebApplication level , then how to
> handle this ?

I don't understand your question.

> I got some idea about RequestMapper but not sure I am on right track.  Peers
> can anyone give some valuable suggestions.
>
> Thanks
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/handling-user-agent-tp4649565.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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