Persistent cookies / "Remember me"

Hi! Included this fix in the
1.0.4
.

Hi ,

nice add-on , what I need ,

in ur live demo , I set a cookie for 1 minute , but after 1 minute when refreshing the page it’s still there… ?!

Why I can’t edit my post? anyway I drop browsercookies-1.0.4 into lib dir , but when pressing “Compile Vaadin Widget” I get an error

“Select a widgetest file (…widgetest.gwt.xml) or a Vaadin project to compile.”

How I fix it? only drop the jar? or more things to do? in the live demo you configure into init-param something

and is it safe to save password into a cookie?

Hi! If you mean that the cookie contents is still listed in the demo, this is because the application session is still alive. Try to use the ?restartApplication parameter to reload the application and see what happens.

Hmm… Make sure you have activated the right project in the left pane. Sometimes the plugin does not find the project otherwise.

Well, no really. I mean cookies are readable in the browser and storing clear text passwords there would be easy to read there. However, other websites cannot read the cookies.

The safest way to make sure the plugin recognizes your project is to go in the Project Explorer view or the Package Explorer view and select you .gwt.xml file for your widgetset. The widgetset definition file is referenced by the WEB-INF/web.xml file – the location in web.xml should match your file.

Thanks for reply, although I found another way to use response/request using TFT add-on ( TPTApplication.getCurrentApplication () ) ,

I dont have .gwt.xml file either widgetset definition in web.xml , is both something I should have/create or it’s auto ?

Thanks for reply, although I found another way to use response/request using TFT add-on ( TPTApplication.getCurrentApplication () ) ,

I dont have .gwt.xml file either widgetset definition in web.xml , is both something I should have/create or it’s auto ?

Hi,

I’m using BrowserCookies v. 1.0.4, and I just noticed that the component doesn’t work for saving cookies unless I put it in my main window. I was trying to put the BrowserCookies component in my sub-window (actually, the login window), and I just can’t save a cookie (I can read them, but can’t add/update).

The problem is solved putting the component in my main window. It is not a big problem, but I think it would be nice to allow sub-windows to make their job without the blessings of the main one.

An other issue (here I go again, 90% of my posts are about that): the add-on is not 100% compatible with Google App Engine. The UpdateListener interface should extends Serializable, to allow clients to create anonymous listeners with no trouble.

For example, today GAE complains about this:


BrowserCookies cookies = new BrowserCookies();
cookies.addListener(new UpdateListener(){ //<-- not serializable!!!
@Override
public void cookiesUpdated(BrowserCookies browserCookies) {}
});

Instead, I have to create my own named class, make it implements UpdateListener and Serializable, and then use it:


private class BoringListener implements UpdateListener, Serializable {
@Override
public void cookiesUpdated(BrowserCookies browserCookies) {}
}
//...
BrowserCookies cookies = new BrowserCookies();
cookies.addListener(new BoringListener());

Hi,

I’m using BrowserCookies v. 1.0.4, and I just noticed that the component doesn’t work for saving cookies unless I put it in my main window. I was trying to put the BrowserCookies component in my sub-window (actually, the login window), and I just can’t save a cookie (I can read them, but can’t add/update).

The problem is solved putting the component in my main window. It is not a big problem, but I think it would be nice to allow sub-windows to make their job without the blessings of the main one.

An other issue (here I go again, 90% of my posts are about that =P): the add-on is not 100% compatible with Google App Engine. The UpdateListener interface should extends Serializable, to allow clients to create anonymous listeners with no trouble.

For example, today GAE complains about this:

BrowserCookies cookies = new BrowserCookies();
cookies.addListener(new UpdateListener(){ //<-- not serializable!!!
@Override
public void cookiesUpdated(BrowserCookies browserCookies) {}
});

Instead, I have to create my own named class, make it implements UpdateListener and Serializable, and then use it:

private class SerializableUpdateListener implements UpdateListener, Serializable {
@Override
public void cookiesUpdated(BrowserCookies browserCookies) {}
}
//...
BrowserCookies cookies = new BrowserCookies();
cookies.addListener(new SerializableUpdateListener());

Again, not a big problem, just an improvement that can be done. :wink:

Thanks.

Hmm. Actually, I cannot think why it does not work in subwindow as long as it added to the component hierarchy.
Overall, it is a little bit counterintuitive that components like this are added at all, but that is just how Vaadin works.

Right. This is a valid complaint :slight_smile: It should be an easy fix, and I try to find the time slot to fix that.

Hi, i’m using the addon to save the user’s fav locale.
It works good but, if i wanna use the setCookie method with the domain and path as params, it just won’t save the cookie.

I’m using Chrome on mac, and for localhost i do the following:

cookies.setCookie(“favLocale”, …the locale…, …new Date(), “localhost”, “\AppName”, false);

I tried all the combinations for localhost and the path, but it just won’t be saved on browser.
The browser address for my local deploy is http://localhost:8080/AppName

Any idea of why it shouldn’t work?

Thanks! :slight_smile:

Hi, i’m using the addon to save the user’s fav locale.
It works good but, if i wanna use the setCookie method with the domain and path as params, it just won’t save the cookie.

I’m using Chrome on mac, and for localhost i do the following:

cookies.setCookie(“favLocale”, …the locale…, …new Date(), “localhost”, “\AppName”, false);

I tried all the combinations for localhost and the path, but it just won’t be saved on browser.
The browser address for my local deploy is http://localhost:8080/AppName

Any idea of why it shouldn’t work?

Thanks! :slight_smile:

Ok, solved… problem is that localhost is not a valid domain, so whether you use 127.0.0.1 or you can set as domain an empty string “”.

Cheers!

Hi!

I’m try use browsercookies.

But in my application cookies not set.
In demo - sami.virtuallypreinstalled.com/browsercookies/ - cokiies work fine.

Tell me, what could be wrong?

My Application class


public class Application extends com.vaadin.Application implements
		HttpServletRequestListener {

	private BrowserCookies cookies;

	public void init() {
		setTheme("parus");

		cookies = new BrowserCookies();

		...
	}

	public BrowserCookies getCookies() {
		return cookies;
	}

CookieUtil


public class CookieUtil {

	/**
	 * Добавить кукис
	 * Значение куки кодируется в Base64
	 * @param name имя
	 * @param value значение
	 */
	public static void addCookie(String name, String value) {
		if (value != null && !value.isEmpty()) {
			Date date = DateUtil.shiftDate(DateUtil.getCurDate(), Calendar.HOUR, 24*7);
			//int saveCookiesTime = 7 * 24 * 60 * 60; //7 дней
			Application.getInstance()
					.getCookies().setCookie(name, CryptUtil.strToBase64(value, true), date);
		}
	}

	/**
	 * Получить кукис
	 * Значение декодируется из Base64
	 * @param name
	 * @return значение кукиса или null
	 */
	public static String getCookie(String name) {
		String value = Application.getInstance().getCookies().getCookie(name);
		if (value != null) {
			value = CryptUtil.base64ToStr(value, true);
		}
		return value;
	}
}

After user authorization i try add cookies. But the cookies did not appear.

Hi! First thing that comes to my mind is that did you remember to compile the client-side widgetset? If that is ok, then secondly, are you adding the browserCookies into UI using addComponent? Something like:

cookies = new BrowserCookies();
mainWindow.addComponent(cookies);

Also, I notice that you have made the functions static using ThreadLocal pattern or similar, right? This should work ok, but be careful out there, as the statics are shared among sessions (i.e. users).

Thank you, for you answer.

I’m use ThreadLocal pattern and i’m add browserCookies into UI.

But cookies not work.
So it wigetset.

I work with NetBeans. I compile wigetset, but probably it is compiled incorrectly. I’ll try again.

Thank you very much.

hello!!
i have added this addon dependency to my pom.xml

org.vaadin.addons
browsercookies
1.0.4

and after that when i compile my widgeset i get the following errors. Even if i remove the dependency i still keep getting the errors.
does anyone know how to solve this?

Starting GWT compiler
Compiling module teneoweb.gwt.ColorPickerWidgetSet
Validating newly compiled units
[ERROR]
Errors in ‘jar:file:/C:/Users/diana.razera/Downloads/gwt-2.3.0/gwt-2.3.0/gwt-user.jar!/com/google/gwt/editor/client/EditorDriver.java’
[ERROR]
Line 20: The import javax.validation.ConstraintViolation cannot be resolved
[ERROR]
Line 97: ConstraintViolation cannot be resolved to a type
[ERROR]
Errors in ‘jar:file:/C:/Users/diana.razera/Downloads/gwt-2.3.0/gwt-2.3.0/gwt-user.jar!/com/google/gwt/editor/client/impl/AbstractSimpleBeanEditorDriver.java’
[ERROR]
Line 28: Name clash: The method setConstraintViolations(Iterable<ConstraintViolation<?>>) of type BaseEditorDriver has the same erasure as setConstraintViolations(Iterable>) of type EditorDriver but does not override it
[ERROR]
Errors in ‘jar:file:/C:/Users/diana.razera/Downloads/gwt-2.3.0/gwt-2.3.0/gwt-user.jar!/com/google/gwt/editor/client/impl/BaseEditorDriver.java’
[ERROR]
Line 31: The import javax.validation.ConstraintViolation cannot be resolved
[ERROR]
Line 67: ConstraintViolation cannot be resolved to a type
[ERROR]
Errors in ‘jar:file:/C:/Users/diana.razera/Downloads/gwt-2.3.0/gwt-2.3.0/gwt-user.jar!/com/google/gwt/editor/client/impl/SimpleViolation.java’
[ERROR]
Line 25: The import javax.validation.ConstraintViolation cannot be resolved
[ERROR]
Line 40: ConstraintViolation cannot be resolved to a type
[ERROR]
Line 43: ConstraintViolation cannot be resolved to a type
[ERROR]
Line 44: Missing code implementation in the compiler
[ERROR]
Line 49: ConstraintViolation cannot be resolved to a type
[ERROR]
Line 49: Missing code implementation in the compiler
[ERROR]
Line 70: ConstraintViolation cannot be resolved to a type
[ERROR]
Line 72: ConstraintViolation cannot be resolved to a type
[ERROR]
Line 73: ConstraintViolation<?> cannot be resolved to a type [ERROR] Line 77: ConstraintViolation cannot be resolved to a type
[ERROR]
Line 81: ConstraintViolation<capture#3-of ?> cannot be resolved to a type
[ERROR]
Line 89: ConstraintViolation<capture#4-of ?> cannot be resolved to a type
[ERROR]
Line 93: ConstraintViolation<capture#5-of ?> cannot be resolved to a type
[ERROR]
Line 98: ConstraintViolation cannot be resolved to a type
[ERROR]
Errors in ‘jar:file:/C:/Users/diana.razera/Downloads/gwt-2.3.0/gwt-2.3.0/gwt-user.jar!/com/google/gwt/editor/client/testing/MockSimpleBeanEditorDriver.java’
[ERROR]
Line 26: The import javax.validation.ConstraintViolation cannot be resolved
[ERROR]
Line 35: The type MockSimpleBeanEditorDriver<T,E> must implement the inherited abstract method EditorDriver.setConstraintViolations(Iterable<ConstraintViolation<?>>) [ERROR] Line 107: Name clash: The method setConstraintViolations(Iterable>) of type MockSimpleBeanEditorDriver<T,E> has the same erasure as setConstraintViolations(Iterable<ConstraintViolation<?>>) of type EditorDriver but does not override it
[ERROR]
Line 108: ConstraintViolation cannot be resolved to a type
[ERROR]
Errors in ‘jar:file:/C:/Users/diana.razera/Downloads/gwt-2.3.0/gwt-2.3.0/gwt-user.jar!/javax/validation/super/javax/validation/Configuration.java’
[ERROR]
Line 93: TraversableResolver cannot be resolved to a type
[ERROR]
Line 105: ConstraintValidatorFactory cannot be resolved to a type
[ERROR]
Line 182: TraversableResolver cannot be resolved to a type
[ERROR]
Line 182: No source code is available for type TraversableResolver; did you forget to inherit a required module?
[ERROR]
Line 194: ConstraintValidatorFactory cannot be resolved to a type
[ERROR]
Line 194: No source code is available for type ConstraintValidatorFactory; did you forget to inherit a required module?
[ERROR]
Line 202: ValidatorFactory cannot be resolved to a type
[ERROR]
Line 202: No source code is available for type ValidatorFactory; did you forget to inherit a required module?
[ERROR]
Errors in ‘jar:file:/C:/Users/diana.razera/Downloads/gwt-2.3.0/gwt-2.3.0/gwt-user.jar!/javax/validation/ConstraintViolationException_CustomFieldSerializer.java’
[ERROR]
Line 30: ConstraintViolationException cannot be resolved to a type
[ERROR]
Line 34: ConstraintViolationException cannot be resolved to a type
[ERROR]
Line 34: No source code is available for type ConstraintViolationException; did you forget to inherit a required module?
[ERROR]
Line 39: ConstraintViolation cannot be resolved to a type
[ERROR]
Line 39: ConstraintViolation cannot be resolved to a type
[ERROR]
Line 40: ConstraintViolationException cannot be resolved to a type
[ERROR]
Line 44: ConstraintViolationException cannot be resolved to a type
[ERROR]
Errors in ‘jar:file:/C:/Users/diana.razera/Downloads/gwt-2.3.0/gwt-2.3.0/gwt-user.jar!/javax/validation/super/javax/validation/MessageInterpolator.java’
[ERROR]
Line 21: The import javax.validation.metadata cannot be resolved
[ERROR]
Line 66: ConstraintDescriptor cannot be resolved to a type
[ERROR]
Errors in ‘jar:file:/C:/Users/diana.razera/Downloads/gwt-2.3.0/gwt-2.3.0/gwt-user.jar!/javax/validation/super/javax/validation/constraints/Pattern.java’
[ERROR]
Line 30: The import javax.validation.Constraint cannot be resolved
[ERROR]
Line 31: The import javax.validation.Payload cannot be resolved
[ERROR]
Line 49: Constraint cannot be resolved to a type
[ERROR]
Line 49: The attribute validatedBy is undefined for the annotation type Constraint
[ERROR]
Line 75: Payload cannot be resolved to a type
[ERROR]
Errors in ‘jar:file:/C:/Users/diana.razera/Downloads/gwt-2.3.0/gwt-2.3.0/gwt-user.jar!/javax/validation/super/javax/validation/spi/ConfigurationState.java’
[ERROR]
Line 22: The import javax.validation.ConstraintValidatorFactory cannot be resolved
[ERROR]
Line 24: The import javax.validation.TraversableResolver cannot be resolved
[ERROR]
Line 93: ConstraintValidatorFactory cannot be resolved to a type
[ERROR]
Line 107: TraversableResolver cannot be resolved to a type
Computing all possible rebind results for ‘com.google.gwt.user.client.UserAgentAsserter’
Rebinding com.google.gwt.user.client.UserAgentAsserter
Checking rule
[WARN]
Detected warnings related to ‘com.google.gwt.editor.client.SimpleBeanEditorDriver’. Are validation-api-.jar and validation-api--sources.jar on the classpath?
[WARN]
Unknown type ‘com.google.gwt.editor.client.SimpleBeanEditorDriver’ specified in deferred binding rule
May 18, 2012 3:53:18 PM com.vaadin.terminal.gwt.widgetsetutils.ClassPathExplorer getPaintablesHavingWidgetAnnotation
INFO: Searching for paintables…
May 18, 2012 3:53:19 PM com.vaadin.terminal.gwt.widgetsetutils.ClassPathExplorer getPaintablesHavingWidgetAnnotation
INFO: Search took 1225ms
Widgetset compilation completed

How do you use BrowserCookies cookies because it only loads up with cookies after everything else in my app UI has loaded, such as an intro window.
I want the user to set whether he wants to see that window next time he visits my site, but I can’t stop the window because it loads at the same time as the BrowserCookies, so I can’t read the relevant cookie and not load the intro window…

Ok, I solved this issue like this:

@Override
	public void transactionStart(Application application, Object transactionData) {
		out: if (!processedIntroWindow) {
			for (Cookie cookie : ((HttpServletRequest) transactionData)
					.getCookies())
				if (cookie.getName().equals("hideIntro")) {
					if (cookie.getValue().equals("false")) {
						getMainWindow().addWindow(new IntroWindow(true));
						processedIntroWindow = true;
					}
					break out;
				} else
					continue;
			// if no cookie "hideIntro" is set
			getMainWindow().addWindow(new IntroWindow(true));
			processedIntroWindow = true;
		}

and still using BrowserCookies to set the cookie because I don’t want to keep a response reference to be able to set cookie (hopefully it’s not too much overhead and doesn’t add to traffic idlessly, then it would be about the same thing)

Used an OptionGroup instead of a CheckBox for the user choosing to hide the intro window on next visit :slight_smile:

private ValueChangeListener showNextTimeCB = new ValueChangeListener() {

		@Override
		public void valueChange(ValueChangeEvent event) {
			String hide;
			if (!((Collection) ((OptionGroup) event.getProperty()).getValue())
					.isEmpty())
				hide = "true";
			else
				hide = "false";
			Calendar expiry = Calendar.getInstance();
			expiry.set(Calendar.YEAR, expiry.getMaximum(Calendar.YEAR));
			// TODO: externalize domain and path names
			((ReallotoApplication) getApplication()).refs.cookies.setCookie(
					"hideIntro", hide, expiry.getTime());
		}
	};

Also, it didn’t work to set domain and path… cookie isn’t set at all if I choose that constructor…