I may very well be daft, but it seems that the AjaxEditableChoiceLabel doesn't
take the ChoiceRenderer into account when creating the label version of itself.
There's no override, so in my case the toString() of most Enum's have to be the
database value which means my labels are F instead of Female, 2 instead of "Yes
please" etc.
I got around the problem by overriding the newLabel(...), however that was
complicated further by not having access to the ChoiceRenderer in my override.
It's a private member without any accessors. The resulting code is a bit
peculiar, and I know I changed the behaviour of the Label slightly, but it's
just a quick hack. Any chance of seeing something like this added as a default
behaviour in AECL?
Alex
label = new AjaxEditableChoiceLabel("cvStatus", new PropertyModel(careerData,
"cvStatus"), Arrays.asList(CvStatus.values()), new ChoiceRenderer("status"))
{
private static final long serialVersionUID = 1L;
@Override
protected Component newLabel( MarkupContainer parent, String
componentId, IModel model )
{
Label label = new Label(componentId, model)
{
private static final long serialVersionUID = 1L;
@Override
public IConverter getConverter( Class type )
{
//IConverter c = getConverter(type);
//return c != null ? c :
super.getConverter(type);
return super.getConverter(type);
}
@Override
protected void onComponentTagBody( MarkupStream
markupStream, ComponentTag openTag )
{
Object modelObject = getModelObject();
if (modelObject == null ||
"".equals(modelObject))
{
replaceComponentTagBody(markupStream,
openTag, defaultNullLabel());
} else
{
// Workaround to get to the
ChoiceRenderer
String displayValue = (String)
((DropDownChoice) getEditor()).getChoiceRenderer().getDisplayValue(modelObject);
replaceComponentTagBody(markupStream,
openTag, displayValue);
}
}
};
label.setOutputMarkupId(true);
label.add(new LabelAjaxBehavior(getLabelAjaxEvent()));
return label;
}
};