001 package com.khubla.pragmatach.framework.controller.impl; 002 003 import java.util.HashMap; 004 import java.util.Map; 005 006 import com.khubla.pragmatach.framework.api.PragmatachException; 007 import com.khubla.pragmatach.framework.controller.BeanBoundController; 008 import com.khubla.pragmatach.framework.controller.ControllerBeanUtil; 009 import com.khubla.pragmatach.framework.controller.impl.template.AbstractTemplateEngineController; 010 import com.khubla.pragmatach.framework.form.Form; 011 import com.khubla.pragmatach.framework.form.FormItem; 012 013 /** 014 * @author tome 015 */ 016 public class FormPostBeanBoundController extends AbstractTemplateEngineController implements BeanBoundController { 017 protected Map<String, String> getPostFieldValues() throws PragmatachException { 018 try { 019 final Form form = Form.parse(getRequest().getHttpServletRequest()); 020 if (null != form) { 021 final Map<String, String> ret = new HashMap<String, String>(); 022 for (final FormItem formItem : form.getItems().values()) { 023 ret.put(formItem.getName(), formItem.getValue()); 024 } 025 return ret; 026 } else { 027 return null; 028 } 029 } catch (final Exception e) { 030 throw new PragmatachException("Exception in getPostFieldValues", e); 031 } 032 } 033 034 @Override 035 public void populateController() throws PragmatachException { 036 try { 037 ControllerBeanUtil.populateController(this, getPostFieldValues()); 038 } catch (final Exception e) { 039 throw new PragmatachException("Exception in populateController", e); 040 } 041 } 042 }