Browser information

I wanna use the example from
Sampler
for Browswer Information ,

as a Utiltiy class , something like this ,

public class BrowserInformation {

	
	private boolean populated = false;
	private WebApplicationContext context;
	private WebBrowser webBrowser;
	
	public BrowserInformation(){

         context = ((WebApplicationContext) getApplication()   .getContext());
         webBrowser = context.getBrowser();
	}
	
	

I tried the code from the sampler , but didn’t attach it to any compoments , so @attach method didn’t work.

Spring solution would be better.

That sample code is actually just a component which extends a VerticalLayout. To use this you then have to add this component to your Vaadin application. If you create a regular Vaadin application and add this sample code as a component to that, then you should be fine.

E.g. by providing a reference to an application along with the call to the utility class, I think you should get the context from that.

If you are trying to use this without a Vaadin application, then it’s not going to work. This since then you don’t have the context and the corresponding GWT widget which does that actual parsing from the browser: VBrowserDetails. Also the communication to the server side does not work. If you look at the source of VBrowserDetails, you might see how it works on the client side.

You could perhaps check out if you can use the
getApplicationContext(HttpSession session)
method and then
getApplications()
to get a reference without passing the application to the utility class. This is just a guess without testing.