Seems fine, though you might want to abstract your strings into a resource file
- this would avoid hard-coding string constants in your source code and would
help facilitate localization if you ever wanted to do that.
On May 21, 2011, at 5:57 PM, Edvin Syse wrote:
> I have a ListButton in a Form that binds to a String property in my domain
> object. The String properties are keywords, but I want to display a more
> describing label to the user in the ListButton dropdown.
>
> This is the solution I came up with. I'm wondering if there is a simpler
> solution?
>
> public void initialize(Map<String, Object> namespace, URL location, Resources
> resources) {
> htmlEditor.setItemRenderer(new ItemRenderer());
> htmlEditor.setDataRenderer(new DataRenderer());
> htmlEditor.setListData("['tiny', 'jedit', 'osdefault']");
> }
>
> class ItemRenderer extends ListViewItemRenderer {
> public void render(Object item, int index, ListView listView, boolean
> selected, boolean checked, boolean highlighted, boolean disabled) {
> super.render(item, index, listView, selected, checked, highlighted,
> disabled);
> alterLabel(label, (String) item);
> }
> }
>
> class DataRenderer extends ListButtonDataRenderer {
> public void render(Object data, Button button, boolean highlighted) {
> alterLabel(label, (String) data);
> }
> }
>
> private void alterLabel(Label label, String string) {
> if ("jedit".equals(string))
> label.setText("Internal code editor");
> else if ("tiny".equals(string))
> label.setText("Tiny MCE");
> else
> label.setText("Your OS default editor");
> }
>
> -- Edvin
>