Metawidget - a tool for generating Java forms
Hello reader.
I want to talk about a tool for Java that I recently came across and did not find a single mention of it on the Habr. It is called Metawidget and its purpose is to generate forms in Java.
Personally, I liked the fact that he does it in realtime. I worked with somehow with one project that generated Java beans at the compilation stage and I can say that I did not like it at all. Firstly, you cannot touch the generated classes since they can be regenerated at any time. The source material looks strange because not pure java. IDE does not recognize these "gadgets" either. Well, there is additional time during compilation / generation, either to drink coffee, or to grit your teeth with indignation.
The following features of this tool are no less important:
Metawidget generates a lot of what forms. I mean that it can be SWING, JSF, JSP and all sorts of other Java View technologies (a full list is on the site). True, not all it generates as I would liketo me , but more on that later.
This tool can work with any POJO objects and can correctly 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, if nullable = false, there will be no empty option.
Here is a brief example of using Metawidget to generate JSF forms.
First, we describe our ManagedBean:
In the line "metawidget.setValue (Musician.class);" indicate which class to use as the bean.
Then the JSF template: I will not give the bin, but in general it can be any class with public properties or with getters / setters. In my case, there was still a ManyToMany relationship. So. All is ready. Compile, run. Voila! Just something is not quite in order. Where ManyToMany links there are no editable fields. Just text. This is what upsets it. Of course, I understand that the tool in this case does not have the right to put a text field, but it cannot offer options either. doesn't know what they are.
The developers have found peculiar solutions to this problem. These are special Ui * Lookup annotations. For example, you can list the elements in this way: But in general, this does not solve the problem, since all values are hardcoded. For JSF, there is an expression annotation and it looks something like this: Metawidget, if necessary, draw an input element with a list of cities, will contact ManagedBean “myManagedBean”, the method “getCities ()”, and substitute the list received from there. And in ManagedBean we slip everything we want. Similar solutions are available not only for JFS. In the end, I want to write my personal impression of the instrument.
In general, he perfectly matches his goal and his paradigm, except for relationships. In addition, I recently tried Python / Django, and I really liked the opportunity to make an admin from ORM beans there. And so I would like to see it in Java ... Of course, I understand that if the site is serious enough, then there can be so many nuances that it would be better not to use automation, but to do everything as it is now, but when the project starts, Java would be very helpful to the developer.
In order to bring my dream closer to reality, I would like to make my own library-layer between JPA data and Metawidgets. So that everything is automatically pulled up and maintained. Today I made my annotation and its processing so that now I have connected elements themselves pulled by means of JPA.
I can’t say that I’m a great specialist, but the Metawidgets code seemed good enough to me and it was easy to find in it.
I want to talk about a tool for Java that I recently came across and did not find a single mention of it on the Habr. It is called Metawidget and its purpose is to generate forms in Java.
Personally, I liked the fact that he does it in realtime. I worked with somehow with one project that generated Java beans at the compilation stage and I can say that I did not like it at all. Firstly, you cannot touch the generated classes since they can be regenerated at any time. The source material looks strange because not pure java. IDE does not recognize these "gadgets" either. Well, there is additional time during compilation / generation, either to drink coffee, or to grit your teeth with indignation.
The following features of this tool are no less important:
Metawidget generates a lot of what forms. I mean that it can be SWING, JSF, JSP and all sorts of other Java View technologies (a full list is on the site). True, not all it generates as I would like
This tool can work with any POJO objects and can correctly 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, if nullable = false, there will be no empty option.
Here is a brief example of using Metawidget to generate JSF forms.
First, we 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);" indicate which class to use as the bean.
Then the JSF template: I will not give the bin, but in general it can be any class with public properties or with getters / setters. In my case, there was still a ManyToMany relationship. So. All is ready. Compile, run. Voila! Just something is not quite in order. Where ManyToMany links there are no editable fields. Just text. This is what upsets it. Of course, I understand that the tool in this case does not have the right to put a text field, but it cannot offer options either. doesn't know what they are.
....
xmlns:m="http://metawidget.org/faces"
....
....
The developers have found peculiar solutions to this problem. These are special Ui * Lookup annotations. For example, you can list the elements in this way: But in general, this does not solve the problem, since all values are hardcoded. For JSF, there is an expression annotation and it looks something like this: Metawidget, if necessary, draw an input element with a list of cities, will contact ManagedBean “myManagedBean”, the method “getCities ()”, and substitute the list received from there. And in ManagedBean we slip everything we want. Similar solutions are available not only for JFS. In the end, I want to write my personal impression of the instrument.
@UiLookup( { "Riga", "Moscow", "Kukuyevo" } )
public String getCity()
@UiFacesLookup("#{myManagedBean.cities}")
In general, he perfectly matches his goal and his paradigm, except for relationships. In addition, I recently tried Python / Django, and I really liked the opportunity to make an admin from ORM beans there. And so I would like to see it in Java ... Of course, I understand that if the site is serious enough, then there can be so many nuances that it would be better not to use automation, but to do everything as it is now, but when the project starts, Java would be very helpful to the developer.
In order to bring my dream closer to reality, I would like to make my own library-layer between JPA data and Metawidgets. So that everything is automatically pulled up and maintained. Today I made my annotation and its processing so that now I have connected elements themselves pulled by means of JPA.
I can’t say that I’m a great specialist, but the Metawidgets code seemed good enough to me and it was easy to find in it.