1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public static Boolean required(Object object, String propertyPath) { Method getMethod = findGetterMethod(object, propertyPath); if (getMethod == null) { return null; } else { return getMethod.isAnnotationPresent(NotNull.class); } } public static Boolean isDate(Object object, String propertyPath) { return java.util.Date.class.equals(getReturnType(object, propertyPath)); } public static Class getReturnType(Object object, String propertyPath) { Method getMethod = findGetterMethod(object, propertyPath); if (getMethod == null) { return null; } else { return getMethod.getReturnType(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <%@ taglib tagdir="/WEB-INF/tags/form" prefix="form" %> <form method="post" action="<c:url value="/signup/customer.edit"/>"> <form:select propertyPath="creditCard.type" collection="${creditCardTypeCollection}" required="true" labelKey="prompt.creditcard.type"/> <form:text propertyPath="creditCard.number" labelKey="prompt.creditcard.number"> <img src="<c:url value="/images/icons/help.png"/>" alt="Help" onclick="new Effect.SlideDown('creditCardHelp')"/> </form:text> <form:text propertyPath="creditCard.expirationDate"/> </form> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | <%@ attribute name="propertyPath" required="true" %> <%@ attribute name="size" required="false" type="java.lang.Integer" %> <%@ attribute name="maxlength" required="false" type="java.lang.Integer" %> <%@ attribute name="required" required="false" type="java.lang.Boolean" %> <%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %> <%@ taglib uri="formtags" prefix="form" %> <c:set var="objectPath" value="${form:getObjectPath(propertyPath)}"/> <spring:bind path="${objectPath}"> <c:set var="object" value="${status.value}"/> <c:if test="${object == null}"> <%-- Bind ignores the command object prefix, so simple properties of the command object return null above. --%> <c:set var="object" value="${commandObject}"/> <%-- We depend on the controller adding this to request. --%> </c:if> </spring:bind> <%-- If user did not specify whether this field is required, query the object for this info. --%> <c:if test="${required == null}"> <c:set var="required" value="${form:required(object,propertyPath)}"/> </c:if> <c:choose> <c:when test="${required == null || required == false}"> <c:set var="labelClass" value="optional"/> </c:when> <ctherwise> <c:set var="labelClass" value="required"/> </ctherwise> </c:choose> <c:if test="${maxlength == null}"> <c:set var="maxlength" value="${form:maxLength(object,propertyPath)}"/> </c:if> <c:set var="isDate" value="${form:isDate(object,propertyPath)}"/> <c:set var="cssClass" value="input_text"/> <c:if test="${isDate}"> <c:set var="cssClass" value="input_date"/> </c:if> <div class="field"> <spring:bind path="${propertyPath}"> <label for="${status.expression}" class="${labelClass}"><fmt:message key="prompt.${propertyPath}"/></label> <input type="text" name="${status.expression}" value="${status.value}" id="${status.expression}"<c:if test="${size != null}"> size="${size}"</c:if> <c:if test="${maxlength != null}"> maxlength="${maxlength}"</c:if> class="${cssClass}"/> <c:if test="${isDate}"> <img id="${status.expression}_button" src="<c:url value="/images/icons/calendar.png"/>" alt="calendar" style="cursor: pointer;"/> <script type="text/javascript"> Calendar.setup( { inputField : "${status.expression}", // ID of the input field ifFormat : "%m/%d/%Y", // the date format button : "${status.expression}_button" // ID of the button } ); </script> </c:if> <span class="icons"><jsp:doBody/></span> <c:if test="${status.errorMessage != null && status.errorMessage != ''}"> <p class="fieldError"><img id="${status.expression}_error" src="<c:url value="/images/icons/error.png"/>" alt="error"/>${status.errorMessage}</p> </c:if> </spring:bind> </div> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |