Setting cookies is easy like that, take the example project replace the onModuleLoad() function with the following, compile and run the following example.
public void onModuleLoad() { final TextBox nameField = new TextBox(); //get the cookie with name MyCookie String msg = Cookies.getCookie("MyCookie"); //if null, there was no cookie if(msg == null) msg = "0"; //set a new value msg = ""+(Integer.parseInt(msg)+1); Cookies.setCookie("MyCookie",msg); //dipslay the cookie nameField.setText(msg); RootPanel.get("nameFieldContainer").add(nameField); }
Date now = new Date(); long nowLong = now.getTime(); nowLong = nowLong + (1000 * 60 * 60 * 24 * 7);//seven days now.setTime(nowLong); Cookies.setCookie("sampleCookieName", "sampleCookiValue", now);