When building a new site you have to program a lot of repetitive tasks. Most of them are related with managing your database objects. Adding users removing users and so on.
Scaffolding is a technique that builds forms for you. It keeps all information relating to a business object together. And most important, it keeps you from making mistakes when managing the objects. Repetitive tasks are not for humans!!!!
This is why we built this new module for wicket. It integrates tightly with dojo so every form created will contain the needed logic to add, update and remove objects with ajax and beautiful interfaces.
The idea behind is to have some objects (DAOs) that we want to manage.
private UuidUserType uuid;
private Date dateUpdated
; private Date dateCreated
; private Set<LeadIdentifier> leadIdentifiers = new HashSet<LeadIdentifier>(0);
private Set<LeadBasicDetail> leadBasicDetails = new HashSet<LeadBasicDetail>(
0);
}
We can see the code for the constructor as follows:
/**
* Constructor
*/
public BasicFormPage()
{
/*
* Need this because wicket serializes everything and need to reload it when
* it's needed. This way wicket and hibernate plays well
*/
IModel scaffoldableModel = new LoadableHibernateModelImpl(getFirst())
{
/**
*
*/
private static final long serialVersionUID = 1L;
@SpringBean(name = "leadDAOBean")
private LeadDAO leadDAO;
private UuidUserType uuid;
@Override
protected Lead load() {
Lead lead = this.getObject();
if(!isAttached() || lead==null)
{
lead = leadDAO.find(uuid);
this.setObject(lead);
}
return lead;
}
@Override
protected void setNonTransientObject() {
Lead lead = this.getObject();
if(lead!=null)
uuid = lead.getUuid();
}
};
ScaffoldingForm myForm = new ScaffoldingForm("myForm", scaffoldableModel)
{
@Override
protected void onSubmit() {
super.onSubmit();
Lead object = (Lead) this.getDefaultModelObject();
if(leadDAO!=null)
{
leadDAO.save(object);
}
}
};
//myForm.addField("email");
add(myForm);
// Don't forget the feedback panel
add(new FeedbackPanel("feedback"));
}
Note: This markup is removing <and > characters and what's inside of them. So this code will not work and you should wait until an update is sent. Alternatively you can download the code from the git repository.
The result after running the program inside tomcat is like this: