Hi Thiago,
How would that work? The ValueEncoder.toClient method must return a
String...something like this:
import org.apache.tapestry5.ValueEncoder;
public class MapValueEncoder implements ValueEncoder {
private static final String DELIM = "/";
@Override
public String toClient(Object value) {
String res = "";
Map<String,Object> map = (Map<String, Object>) value;
for (Iterator<String> it = map.keySet().iterator();
it.hasNext(); ) {
if (res.length() > 0) {
res += DELIM;
}
String key = it.next();
res += key + DELIM + map.get(key).toString();
}
return res;
}
@Override
public Object toValue(String clientValue) {
try {
clientValue = URLDecoder.decode(clientValue, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String[] tokens = clientValue.split(DELIM);
Map<String, String> res = new HashMap<String, String>();
boolean tokIsKey = true;
String currKey = null;
for (int i = 0; i < tokens.length; i++) {
String tok = tokens[i];
if (tokIsKey) {
currKey = tok;
} else {
res.put(currKey, tok);
}
tokIsKey = !tokIsKey;
}
return null;
}
}
Thiago H. de Paula Figueiredo wrote:
Em Thu, 09 Oct 2008 08:06:09 -0300, Joel Halbert
<[EMAIL PROTECTED]> escreveu:
Encode a Map of String/Object pairs to a string of the following
form: key1/value1/key2/value2 etc...
(and of course decode said string back to a map that can be passed to
the context)
Instead of encoding to a String, encode it to a List (first key, first
value, second key, second value, etc). This way, the slashes won't be
URL encoded.
--
SU3 Analytics Ltd
61b Oxford Gardens
W10 5UJ
London
Tel: +44 20 8960 2634
Mob: +44 75 2501 0825
www.su3analytics.com
SU3 Analytics Ltd is a company registered in England and Wales under company
number 06639473 at registered address 61b Oxford Gardens, London W10 5UJ,
United Kingdom.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]