In order to demonstrate the changes typically required to incorporate Metawidget into a project (and the code savings it typically brings) I retrofitted one of Adam's original projects, his GatewayWarDeployment example. I've called mine GatewayWarDeploymentWithMetawidget.
To view the new example:
- Ensure you have Metawidget installed at its default location (/metawidget-1.05/metawidget.jar)
- Get sources for the Java EE Patterns Kenai project in NetBeans using Team > Team Server > Get Sources... (see this screencast for detailed instructions)
- Open the GatewayWarDeploymentWithMetawidget project
LoadView.java | createorder.xhtml |
---|
In such a small example there is no overall saving in lines of code (larger examples have more dramatic savings). But there is still a significant reduction in duplicated declarations (field names, types, action names etc) and therefore reduced possibility of error when building (and maintaining) the UI. Note Metawidget is handling both the input boxes and the buttons, including enabling/disabling the buttons in line with the business logic. This is declared by the code:
@UiAction
@UiFacesAttribute( name = "read-only", expression = "#{load.emptyLoad}" )
public void dropLightest(){
...
}
@UiFacesAttribute( name = "read-only", expression = "#{load.emptyLoad}" )
public void dropLightest(){
...
}
Of course, this is not a great demonstration of all the features of Metawidget. More extensive examples can be found under the /examples folder of the Metawidget distribution. But hopefully it's enough to get people excited without confusing them with lots of code.
My thanks to Adam for his help and encouragement in developing this example!
3 comments:
example dont work please fix
anotacion
@UiFacesAttribute( name = "read-only", expression = "#{load.emptyLoad}" )
lost in metawiget-all.jar
Apologies. As of Metawidget 1.30...
http://blog.kennardconsulting.com/2011/08/metawidget-125-to-130-migration-guide.html
...you'll need to do:
@UiAttribute( name = "read-only", value = "#{load.emptyLoad}" )
Can you try that?
Thanks,
Richard.
thank you very much i will try
Post a Comment