Imagine the following form/bean:
public class MyForm {
private BankAccountNumber accountNumber;
// getter + setter
}
where BankAccountNumber is a custom value object.
When I use metawidget and jsf with an instance of this class, no input field is generated for the accountNumber property (only the label is shown).
The problem is that metawidget does not know the BankAccountNumber type and wouldn't know what kind of UIInput should be used.
The only solution I found so far was to annotate my property with @UiAttribute(name = "type", value = "java.lang.String") and to have a javax.faces.Converter registered for the BankAccountNumber class.
That way, metawidget generates an HtmlnputText.
Is it the best solution?
I think I could also register my own InspectionResultProcessor to change BankAccountNumber to String everywhere but I don't even know if mapping my custom type to String is the right way to do it in the first place.
The recommended approach is to register your own
WidgetBuilderto match on an attributetypeofBankAccountNumberand return the appropriate widget. You can returnnullfor every othertype, and rely on using aCompositeWidgetBuilderto have the widget building process 'fall through' to a regularHtmlWidgetBuilderfor most types.Quite what sort of
UIInputyou return for a type ofBankAccountNumberis up to you. But if you use aHtmlInputTextthen you'll probably need to register JSF Converters in the usual way (this bit isn't specific to Metawidget) so that JSF knows how to convert fromHtmlInputTextinto aBankAccountNumber.For an example of registering a custom
WidgetBuilder(and combining it with aCompositeWidgetBuilder), see section 2.4.4 and 2.4.5 of the User Guide: http://metawidget.org/doc/reference/en/html/ch02s04.html