public void execute(Event<UIRegisterEditMode> event) throws Exception
{
// TODO Auto-generated method stub
UIRegisterEditMode uiForm = event.getSource();
boolean useCaptcha = uiForm.getUIFormCheckBoxInput(USE_CAPTCHA).isChecked();
PortletRequestContext pcontext = (PortletRequestContext)WebuiRequestContext.getCurrentInstance();
PortletPreferences pref = pcontext.getRequest().getPreferences();
pref.setValue(USE_CAPTCHA, Boolean.toString(useCaptcha));
pref.store();
//Show/hide the captcha input in UIRegisterInputSet
UIRegisterPortlet registerPortlet = uiForm.getParent();
UIRegisterInputSet registerInputSet = registerPortlet.findFirstComponentOfType(UIRegisterInputSet.class);
if(useCaptcha)
{
if(!registerInputSet.getCaptchaInputAvailability())
{
registerInputSet.addUIFormInput(new UICaptcha(UIRegisterInputSet.CAPTCHA, UIRegisterInputSet.CAPTCHA, null).addValidator(MandatoryValidator.class).addValidator(CaptchaValidator.class));
registerInputSet.setCaptchaInputAvailability(true);
}
}
else
{
if(registerInputSet.getCaptchaInputAvailability())
{
registerInputSet.removeChildById(UIRegisterInputSet.CAPTCHA);
registerInputSet.setCaptchaInputAvailability(false);
}
}
UIPortalApplication portalApp = Util.getUIPortalApplication();
if (portalApp.getModeState() == UIPortalApplication.NORMAL_MODE)
pcontext.setApplicationMode(PortletMode.VIEW);
}