Hello reader.
I want to tell you about a tool for Java that I recently stumbled upon and did not find a single mention of it at Habré. It is called
Metawidget and its purpose is to generate forms in Java.
I personally liked the fact that he does it in realtime. I worked with somehow with one project that generated Java beans at compile time and I can say that I didn’t like it at all. First, the generated classes cannot be touched. they can be regenerated at any time. The source material looks weird. not pure java. IDE also does not recognize these “bells and whistles”. Well, there is extra time when compiling / generating, either to drink coffee, or to grit your teeth out of indignation.
The following features of this tool are equally important:
Metawidget generates a lot of any forms. I mean that it can be SWING, JSF, JSP and all sorts of other View technologies Java'y (a complete list is on the site). True, not all it generates as I would like, but more on that later.
This tool can work with any POJO objects and can competently use JPA / Hibernate annotations if there are any in the object. That is, for example, if a drop-down list is created (HTML select) and there is a JPA annotation @Column (nullable = true), then the first option of the list will be null, but if nullable = false, there will be no empty option.
I will give a brief example of using Metawidget to generate JSF forms.
We first describe our ManagedBean:
@ManagedBean
public class MetawidgetBB {
@EJB
private FlexibleDAO flexibleDAO;
public UIMetawidget getMetawidget() {
HtmlMetawidget metawidget = new HtmlMetawidget();
initMetawidget(metawidget);
return metawidget;
}
public void setMetawidget(UIMetawidget metawidget) {
initMetawidget(metawidget);
}
private void initMetawidget(UIMetawidget metawidget) {
metawidget.setValue(Musician.class);
}
}
In the line "metawidget.setValue (Musician.class);" we indicate which class to use as a bin.
')
Then the jsf template:
....
xmlns:m="http://metawidget.org/faces"
....
<h:form>
<m:metawidget binding="#{metawidgetBB.metawidget}"/>
<h:form>
....
I will not give the bean, but in general it can be any class with public properties or with getters / setters. In my case, there were still ManyToMany relationships.
So. All is ready. Compile, run.

Voila!
Only something is not quite in order.
There where the ManyToMany links do not have any editable fields. Just a text.
This is what upsets you. Of course, I understand that the tool in this case does not have the right to put a text field, but it cannot offer the options either. I do not know what they are.
The developers have found original solutions to this problem. These are special Ui * Lookup annotations. For example, you can list items like this:
@UiLookup( { "Riga", "Moscow", "Kukuyevo" } )
public String getCity()
But in general, this does not solve the problem as all values are hard-coded. For JSF, there is an expression annotation and it looks like this:
@UiFacesLookup("#{myManagedBean.cities}")
Metawidget, if necessary, to draw an input element with a list of cities, will refer to ManagedBean "myManagedBean", method "getCities ()", and substitute the list received from there. And in ManagedBean, we’ll give you whatever we want. Such solutions are not only for JFS.
In the end I want to write my personal impression of the tool.
In general, it fits perfectly with its goal and its paradigm, except for relationships. In addition, I recently tried Python / Django and I really liked the ability to create admin admin from ORM beans. And so I would like to see it in Java ... Of course, I understand that if the site is serious enough, then there may be so many nuances that it would be more correct not to use automation, but to do everything as now, but when starting the project it would greatly help Java to the developer.
In order to bring my dream closer to reality, I would like to make my own interlayer library between JPA data and Metawidgets. To automatically everything was tightened and saved. Today I made a soy annotation and its processing in such a way that now my related elements are tightened by JPA.
I cannot say that I am a great specialist, but the Metawidgets code seemed to me good enough and it was easy to find in it what I needed.