protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("guidemo_flexi_form_hideunhide");
final int defaultDisplaySize = 32;
final boolean inputMode = !personData.isReadOnly();
/*
* hide unhide chooser
*/
checkbox = new MultipleSelectionElementImpl("checkbox", MultipleSelectionElementImpl.createVerticalLayout("checkbox")) {
{
setLabel("guidemo.flexi.form.show", null);
keys = new String[] { "ison" };
values = new String[] { "" };
select("ison", true);
}
};
// add to velocity container
formLayout.add(checkbox);
// register for on click event to hide/disable other elements
checkbox.addActionListener(listener, FormEvent.ONCLICK);
//rule to hide/unhide at the end
firstName = new TextElementImpl("firstname", personData.getFirstName()){
{
this.displaySize = defaultDisplaySize;
setNotLongerThanCheck(256, "notlongerthan");
setLabel("guidemo.flexi.form.firstname", null);
setNotEmptyCheck("guidemo.flexi.form.mustbefilled");
setMandatory(true);
setEnabled(inputMode);
}
};
formLayout.add(firstName);
lastName = new TextElementImpl("guidemo.flexi.form.lastname", personData.getLastName()){
{
this.displaySize = defaultDisplaySize;
setNotLongerThanCheck(256, "guidemo.flexi.form.notlongerthan");
setLabel("guidemo.flexi.form.lastname", null);
setNotEmptyCheck("guidemo.flexi.form.mustbefilled");
setMandatory(true);
setEnabled(inputMode);
}
};
formLayout.add(lastName);
institution = new TextElementImpl("institution", personData.getInstitution()){
{
this.displaySize = defaultDisplaySize;
setNotLongerThanCheck(256, "guidemo.flexi.form.notlongerthan");
setLabel("guidemo.flexi.form.institution", null);
setEnabled(inputMode);
}
};
formLayout.add(institution);
if(inputMode){
//submit only if in input mode
submit = new FormSubmit("submit","submit");
formLayout.add(submit);
}
/*
* now the rules to hide unhide
*/
Set<FormItem> targets = new HashSet<FormItem>(){
{
add(firstName);
add(lastName);
add(institution);
add(submit);
}
};
RulesFactory.createHideRule(checkbox, null, targets, formLayout);
RulesFactory.createShowRule(checkbox, "ison", targets, formLayout);
}
|