Kiti
Kiti

Reputation: 543

How to use Cookies to store a List of String Array in GWT?

Based on the GWT ShowCase example (http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCookies) we can only store a Pair of String name - String value to Cookies.

What if we want to store a Triad such as (String ItemName, String ItemID, String CompanyID)? or even Foursome, FiveSome, SixSome.... of Info?

We can't set String Array for value in GWT Cookies

Cookies.setCookie(name, value, expires);

So How to use Gwt Cookies in that case?

Upvotes: 1

Views: 2704

Answers (1)

Churro
Churro

Reputation: 4366

A cookie is a key/value pair of strings, kinda like you'd do in a Java properties file. You can make some method that serializes/deserializes an array into a string and vice versa.

You can use the method described here to easily convert between Strings and arrays: string to string array conversion in java

And you can use Arrays.toString(array); to parse an array to a String. Concatenating elements in an array to a string

Upvotes: 1

Related Questions