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
WidgetBuilder
to match on an attributetype
ofBankAccountNumber
and return the appropriate widget. You can returnnull
for every othertype
, and rely on using aCompositeWidgetBuilder
to have the widget building process 'fall through' to a regularHtmlWidgetBuilder
for most types.Quite what sort of
UIInput
you return for a type ofBankAccountNumber
is up to you. But if you use aHtmlInputText
then 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 fromHtmlInputText
into 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