diff --git a/webapp/src/edu/cornell/mannlib/vedit/controller/BaseEditController.java b/webapp/src/edu/cornell/mannlib/vedit/controller/BaseEditController.java index 707f67bde..0e97159b6 100644 --- a/webapp/src/edu/cornell/mannlib/vedit/controller/BaseEditController.java +++ b/webapp/src/edu/cornell/mannlib/vedit/controller/BaseEditController.java @@ -33,7 +33,8 @@ public class BaseEditController extends VitroHttpServlet { public static final String JSP_PREFIX = "/templates/edit/specific/"; - protected static DateFormat DISPLAY_DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy"); + protected static DateFormat DISPLAY_DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy"); + protected static final int BASE_10 = 10; private static final Log log = LogFactory.getLog(BaseEditController.class.getName()); private static final String DEFAULT_LANDING_PAGE = Controllers.SITE_ADMIN; diff --git a/webapp/src/edu/cornell/mannlib/vedit/controller/OperationController.java b/webapp/src/edu/cornell/mannlib/vedit/controller/OperationController.java index 80ae4f85e..6d8b6e158 100644 --- a/webapp/src/edu/cornell/mannlib/vedit/controller/OperationController.java +++ b/webapp/src/edu/cornell/mannlib/vedit/controller/OperationController.java @@ -11,7 +11,6 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -23,6 +22,7 @@ import edu.cornell.mannlib.vedit.forwarder.PageForwarder; import edu.cornell.mannlib.vedit.listener.ChangeListener; import edu.cornell.mannlib.vedit.listener.EditPreProcessor; import edu.cornell.mannlib.vedit.util.FormUtils; +import edu.cornell.mannlib.vedit.util.FormUtils.NegativeIntegerException; import edu.cornell.mannlib.vedit.util.OperationUtils; import edu.cornell.mannlib.vedit.validator.ValidationObject; import edu.cornell.mannlib.vedit.validator.Validator; @@ -201,17 +201,6 @@ public class OperationController extends BaseEditController { } } - private void applySimpleMask(EditProcessObject epo, Object newObj) { - // apply the simple mask - //if (epo.getSimpleMask() != null) { - // Iterator smaskIt = epo.getSimpleMask().iterator(); - // while (smaskIt.hasNext()){ - // Object[] simpleMaskPair = (Object[]) smaskIt.next(); - // FormUtils.beanSet(newObj,(String)simpleMaskPair[0],simpleMaskPair[1].toString()); - // } - //} - } - private Object getNewObj(EditProcessObject epo) { Object newObj = null; if (epo.getOriginalBean() != null) { // we're updating or deleting an existing bean @@ -292,10 +281,14 @@ public class OperationController extends BaseEditController { epo.getBadValueMap().remove(currParam); } catch (NumberFormatException e) { if (currValue.length()>0) { - valid=false; + valid = false; epo.getErrMsgMap().put(currParam,"Please enter an integer"); epo.getBadValueMap().put(currParam,currValue); } + } catch (NegativeIntegerException nie) { + valid = false; + epo.getErrMsgMap().put(currParam,"Please enter a positive integer"); + epo.getBadValueMap().put(currParam,currValue); } catch (IllegalArgumentException f) { valid=false; log.error("doPost() reports IllegalArgumentException for "+currParam); diff --git a/webapp/src/edu/cornell/mannlib/vedit/util/FormUtils.java b/webapp/src/edu/cornell/mannlib/vedit/util/FormUtils.java index 7b14c77ea..7a7607b34 100644 --- a/webapp/src/edu/cornell/mannlib/vedit/util/FormUtils.java +++ b/webapp/src/edu/cornell/mannlib/vedit/util/FormUtils.java @@ -5,6 +5,7 @@ package edu.cornell.mannlib.vedit.util; import java.lang.reflect.Method; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -26,32 +27,45 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; public class FormUtils { - protected static final Log log = LogFactory.getLog(FormUtils.class.getName()); + protected static final Log log = LogFactory.getLog(FormUtils.class.getName()); + protected static final int BASE_10 = 10; + protected static final Class[] SUPPORTED_TYPES = { String.class, + int.class, + Integer.class, + boolean.class, + Date.class + }; + + protected static final List SUPPORTED_TYPE_LIST = Arrays + .asList(SUPPORTED_TYPES); /* this class needs to be reworked */ - public static String htmlFormFromBean (Object bean, String action, FormObject foo) { - return htmlFormFromBean(bean,action,null,foo,new HashMap()); + public static void populateFormFromBean (Object bean, + String action, + FormObject foo) { + populateFormFromBean(bean,action,null,foo,new HashMap()); } - public static String htmlFormFromBean (Object bean, String action, FormObject foo, Map badValuesHash) { - return htmlFormFromBean(bean,action,null,foo,badValuesHash); + public static void populateFormFromBean (Object bean, + String action, + FormObject foo, + Map badValuesHash) { + populateFormFromBean(bean,action,null,foo,badValuesHash); } /** - * Creates a basic XHTML editing form for a bean class - * - * This is the simplest version, creating an input field for each and every setter method in the bean. - * - * @param bean the bean class for which an editing form should be built - * @return XHTML markup of an editing form for the specified class - * @author bjl23 + * Populates form objects with bean values */ - public static String htmlFormFromBean (Object bean, String action, EditProcessObject epo, FormObject foo, Map BadValuesHash) { - - String formMarkup = ""; - - Class beanClass = (epo != null && epo.getBeanClass() != null) ? epo.getBeanClass() : bean.getClass(); + public static void populateFormFromBean (Object bean, + String action, + EditProcessObject epo, + FormObject foo, + Map BadValuesHash) { + Class beanClass = + (epo != null && epo.getBeanClass() != null) + ? epo.getBeanClass() + : bean.getClass(); Method[] meths = beanClass.getMethods(); @@ -60,32 +74,16 @@ public class FormUtils { if (meths[i].getName().indexOf("set") == 0) { // we have a setter method - Method currMeth = meths[i]; Class[] currMethParamTypes = currMeth.getParameterTypes(); Class currMethType = currMethParamTypes[0]; - String currMethTypeStr = currMethType.toString(); + + if (SUPPORTED_TYPE_LIST.contains(currMethType)) { + //we only want people directly to type in ints, strings, and dates + //of course, most of the ints are probably foreign keys anyway... - if (currMethTypeStr.equals("int") || currMethTypeStr.indexOf("class java.lang.String")>-1 || currMethTypeStr.indexOf("class java.util.Date")>-1) { - //we only want people directly to type in ints, strings, and dates - //of course, most of the ints are probably foreign keys anyway... - - String elementName = currMeth.getName().substring(3,currMeth.getName().length()); - - formMarkup += ""; - - formMarkup += "

"+elementName+"

"; - - formMarkup += ""; - - formMarkup += " makeOptionListFromBeans (List beanList, + String valueField, + String bodyField, + String selectedValue, + String selectedBody) { + return makeOptionListFromBeans ( + beanList, valueField, bodyField, selectedValue, selectedBody, true); } - public static List /*of Option*/ makeOptionListFromBeans (List beanList, String valueField, String bodyField, String selectedValue, String selectedBody, boolean forceSelectedInclusion) { - List optList = new LinkedList(); + public static List