The ValueEncoder
interface has only two methods:
String toClient(Object obj)
that tells Tapestry what exactly should be used for thevalue
attribute of<option>
, corresponding to the given object.Object toValue(String str)
, works in the opposite direction, given the contents of thevalue
attribute of an option selected by the user, it should define which exactly object corresponds to this value.
Here is one possible implementation of this interface that will deal with the Celebrity
object in our application:
package com.packtpub.celebrities.util; import com.packtpub.celebrities.data.IDataSource; import com.packtpub.celebrities.model.Celebrity; import org.apache.tapestry.ValueEncoder; public class CelebrityEncoder implements ValueEncoder { private IDataSource source; public CelebrityEncoder(IDataSource source) { this.source = source; } public String toClient(Object obj) { return "" + ((Celebrity)obj).getId(); } public Object toValue(String str) { return source...