1 23 package org.enhydra.barracuda.config; 24 25 import java.io.*; 26 import java.util.*; 27 import javax.servlet.*; 28 import javax.servlet.http.*; 29 30 import org.apache.log4j.*; 31 32 import org.enhydra.barracuda.config.events.*; 33 import org.enhydra.barracuda.core.comp.*; 34 import org.enhydra.barracuda.core.util.dom.*; 35 import org.enhydra.barracuda.core.event.*; 36 import org.enhydra.barracuda.core.forms.*; 37 import org.enhydra.barracuda.plankton.data.*; 38 import org.enhydra.barracuda.plankton.http.*; 39 40 44 public class ViewConfig extends DefaultEventGateway { 45 46 protected static final Logger logger = Logger.getLogger(ViewConfig.class.getName()); 47 48 public static final String FORM = ViewConfig.class.getName()+".Form"; 50 51 public static final String MODEL_NAME = "View"; 53 54 public static final String ERROR_MESSAGE = "ErrorMessage"; 56 public static final String SUCCESS_MESSAGE = "SuccessMessage"; 57 public static final String UPDATE_BUTTON = "UpdateButton"; 58 59 private ListenerFactory updateConfigFactory = new DefaultListenerFactory() {public BaseEventListener getInstance() {return new UpdateConfigHandler();} public String getListenerID() {return getID(UpdateConfigHandler.class);}}; 61 62 public ViewConfig() { 63 specifyLocalEventInterests(updateConfigFactory); 65 } 66 67 73 class ViewModel extends AbstractTemplateModel { 74 75 public String getName() {return MODEL_NAME;} 77 78 public Object getItem(String key) { 80 if (logger.isDebugEnabled()) logger.debug("Asking for key:"+key); 81 ViewContext vc = getViewContext(); 82 83 if (key.equals(ERROR_MESSAGE)) { 85 return ScreenUtil.getErrMsg(vc, FORM, ERROR_MESSAGE); 86 } else if (key.equals(SUCCESS_MESSAGE)) { 87 return ScreenUtil.getSuccessMsg(vc, FORM, SUCCESS_MESSAGE); 88 } else if (key.equals(UPDATE_BUTTON)) { 89 BAction ba = ScreenUtil.getUpdateButtonComp(vc, updateConfigFactory); 92 ba.setEnabled(false); 93 return ba; 94 } else return super.getItem(key); 95 } 96 } 97 98 104 class ViewForm extends DefaultFormMap { 105 public ViewForm() { 106 if (logger.isDebugEnabled()) logger.debug("Defining form elements"); 111 } 113 } 114 115 122 class UpdateConfigHandler extends DefaultBaseEventListener { 123 public void handleControlEvent(ControlEventContext context) throws EventException, ServletException, IOException { 124 Locale locale = context.getViewCapabilities().getClientLocale(); 126 MasterScreen screen = new MasterScreenFactory().getInstance(ViewConfig.this, context, locale); 127 if (logger.isDebugEnabled()) ServletUtil.showParams(context.getRequest(), logger); 128 129 ValidationException ve = null; 131 ViewForm formMap = new ViewForm(); 132 try { 133 formMap.map(context.getRequest()).validate(true); 135 136 144 146 formMap.putState(SUCCESS_MESSAGE, new Boolean (true)); 148 149 } catch (ValidationException e) { 150 ve = e; 151 } 152 153 formMap.putState(ERROR_MESSAGE, ve); 156 context.putState(FORM, formMap); 157 158 ((ViewModel) screen.viewModel).fireModelChanged(); 160 161 throw new ClientSideRedirectException(new GetBConfig()); 163 } 164 } 165 166 public TemplateModel getModel() { 170 return new ViewModel(); 171 } 172 } 173 174 | Popular Tags |