Spring - 登录页面有条款和条件页面(使用Javascript) [英] Spring - login page to have terms and condition page (using Javascript)

查看:704
本文介绍了Spring - 登录页面有条款和条件页面(使用Javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的web应用程序中,我使用Spring MVC。我有默认的登录页面,春天MVC使用。在我的登录页面,我需要有一个复选框。登录时,用户必须启用复选框,然后单击登录按钮。

如果他不选中复选框,则应显示一个弹出窗口(带有一些错误消息) 。



我想使用javascript来实现这个。



/ p>

这是我的JSPX文件。对不起是很大的

 < div xmlns:spring =http://www.springframework.org/tagsxmlns: fn =http://java.sun.com/jsp/jstl/functionsxmlns:util =urn:jsptagdir:/ WEB-INF / tags / utilxmlns:c =http://java.sun。 com / jsp / jstl / corexmlns:jsp =http://java.sun.com/JSP/Pageversion =2.0> 
< jsp:directive.page contentType =text / html; charset = UTF-8/>
< jsp:output omit-xml-declaration =yes/>
< spring:message code =security_login_titlevar =titlehtmlEscape =false/>
< util:panel id =titletitle =$ {title}>
< c:if test =$ {not empty param.login_error}>
< div class =errors>
< p>
< spring:message code =security_login_unsuccessful/>
< c:out value =$ {SPRING_SECURITY_LAST_EXCEPTION.message}/>

< / p>
< / div>
< / c:if>
< c:if test =$ {empty param.login_error}>
< p>
< spring:message code =security_login_message/>
< / p>
< / c:if>
< spring:url value =/ resources / j_spring_security_checkvar =form_url/>
< form name =faction =$ {fn:escapeXml(form_url)}method =POST>
< div>
< label for =j_username>
< spring:message code =security_login_form_name/>
< / label>
< input id =j_usernametype ='text'name ='j_username'style =width:150px/>
< spring:message code =security_login_form_name_messagevar =name_msghtmlEscape=false/>
< script type =text / javascript>
< c:set var =sec_name_msg>
< spring:escapeBody javaScriptEscape =true> $ {name_msg}< / spring:escapeBody>
< / c:set>
Spring.addDecoration(new Spring.ElementDecoration({elementId:j_username,widgetType:dijit.form.ValidationTextBox,widgetAttrs:{promptMessage:$ {sec_name_msg},required:true}})
< / script>
< / div>
< br />
< div>
< label for =j_password>
< spring:message code =security_login_form_password/>
< / label>
< input id =j_passwordtype ='password'name ='j_password'style =width:150px/>
< spring:message code =security_login_form_password_messagevar =pwd_msghtmlEscape =false/>
< script type =text / javascript>
< c:set var =sec_pwd_msg>
< spring:escapeBody javaScriptEscape =true> $ {pwd_msg}< / spring:escapeBody>
< / c:set>
Spring.addDecoration(new Spring.ElementDecoration({elementId:j_password,widgetType:dijit.form.ValidationTextBox,widgetAttrs:{promptMessage:$ {sec_pwd_msg},required:true}})
< / script>
< / div>
< br />
< div class =submit>
< script type =text / javascript> Spring.addDecoration(new Spring.ValidateAllDecoration({elementId:'proceed',event:'onclick'}));< / script&
< spring:message code =button_submitvar =submit_labelhtmlEscape =false/>
< input id =proceedtype =submitvalue =$ {fn:escapeXml(submit_label)}/>
< spring:message code =button_resetvar =reset_labelhtmlEscape =false/>
< input id =resettype =resetvalue =$ {fn:escapeXml(reset_label)}/>
< / div>
< / form>
< / util:panel>
< / div>

我有以下input.tagx文件

 < jsp:root xmlns:c =http://java.sun.com/jsp/jstl/corexmlns:fn =http://java.sun。 com / jsp / jstl / functionsxmlns:spring =http://www.springframework.org/tagsxmlns:form =http://www.springframework.org/tags/formxmlns:jsp =http ://java.sun.com/JSP/Pageversion =2.0> 
< jsp:output omit-xml-declaration =yes/>

< jsp:directive.attribute name =idtype =java.lang.Stringrequired =truertexprvalue =truedescription =此标记的标识符改变!)/>
< jsp:directive.attribute name =fieldtype =java.lang.Stringrequired =truertexprvalue =truedescription =从表单支持对象公开的字段/&
< jsp:directive.attribute name =labeltype =java.lang.Stringrequired =falsertexprvalue =truedescription =该标签用于此字段, bundle if not supplied/>
< jsp:directive.attribute name =labelCodetype =java.lang.Stringrequired =falsertexprvalue =truedescription =如果未提供标签, >
< jsp:directive.attribute name =requiredtype =java.lang.Booleanrequired =falsertexprvalue =truedescription =指示此字段是否必需>
< jsp:directive.attribute name =disabledtype =java.lang.Booleanrequired =falsertexprvalue =truedescription =指定是否应启用此字段/&
< jsp:directive.attribute name =validationRegextype =java.lang.Stringrequired =falsertexprvalue =truedescription =指定要用于验证输入的正则表达式内容/>
< jsp:directive.attribute name =validationMessageCodetype =java.lang.Stringrequired =falsertexprvalue =truedescription =指定要显示的消息正则表达式验证失败/>
< jsp:directive.attribute name =validationMessagetype =java.lang.Stringrequired =falsertexprvalue =truedescription =指定正则表达式验证失败时显示的消息/>
< jsp:directive.attribute name =mintype =java.lang.Stringrequired =falsertexprvalue =truedescription =指定输入内容的最小长度
< jsp:directive.attribute name =maxtype =java.lang.Stringrequired =falsertexprvalue =truedescription =指定输入内容的最大长度
< jsp:directive.attribute name =decimalMintype =java.lang.Stringrequired =falsertexprvalue =truedescription =指定输入内容的最小大小/&
< jsp:directive.attribute name =decimalMaxtype =java.lang.Stringrequired =falsertexprvalue =truedescription =指定输入内容的最大大小/&
< jsp:directive.attribute name =disableFormBindingtype =java.lang.Booleanrequired =falsertexprvalue =truedescription =设置为true以禁用Spring表单绑定/>
< jsp:directive.attribute name =typetype =java.lang.Stringrequired =falsertexprvalue =truedescription =设置字段类型(默认为'text' ')/>
< jsp:directive.attribute name =rendertype =java.lang.Booleanrequired =falsertexprvalue =truedescription =指示此标记的内容和所有封闭标记(默认'true')/>
< jsp:directive.attribute name =ztype =java.lang.Stringrequired =falsedescription =用于检查元素是否已被修改(重新计算只需提供空字符串值) />

< c:if test =$ {empty render or render}>

< c:if test =$ {empty type}>
< c:set value =textvar =type/>
< / c:if>

< c:if test =$ {empty disabled}>
< / c:if>

< c:if test =$ {empty label}>
< c:if test =$ {empty labelCode}>
< c:set var =labelCodevalue =$ {fn:substringAfter(id,'_')}/>
< / c:if>
< spring:message code =label _ $ {fn:toLowerCase(labelCode)}var =labelhtmlEscape =false/>
< / c:if>

< c:if test =$ {empty validationMessage}>
< c:choose>
< c:when test =$ {empty validationMessageCode}>
< spring:message arguments =$ {fn:escapeXml(label)}code =field_invalidvar =field_invalidhtmlEscape =false/>
< / c:when>
< c:otherwise>
< spring:message arguments =$ {fn:escapeXml(label)}code =$ {validationMessageCode}var =field_invalidhtmlEscape =false/&
< / c:otherwise>
< / c:choose>
< / c:if>

< c:if test =$ {empty required}>
< c:set value =falsevar =必需/>
< / c:if>

< c:set var =sec_field>
< spring:escapeBody javaScriptEscape =true> $ {field}< / spring:escapeBody>
< / c:set>

< div id =_ $ {fn:escapeXml(id)} _ id>
< label for =_ $ {sec_field} _id>
< c:out value =$ {fn:escapeXml(label)}/>

< / label>
< c:choose>
< c:when test =$ {disableFormBinding}>
< input id =_ $ {sec_field} _idname =$ {sec_field}type =$ {fn:escapeXml(type)}/>
< / c:when>
< c:otherwise>
< c:choose>
< c:when test =$ {type eq'password'}>
< form:password id =_ $ {sec_field} _idpath =$ {sec_field}disabled =$ {disabled}/>
< / c:when>
< c:otherwise>
< form:input id =_ $ {sec_field} _idpath =$ {sec_field}disabled =$ {disabled}/>
< / c:otherwise>
< / c:choose>
< br />
< form:errors cssClass =errorsid =_ $ {sec_field} _error_idpath =$ {sec_field}/>
< / c:otherwise>
< / c:choose>
< c:choose>
< c:when test =$ {required}>
< spring:message code =field_requiredvar =field_requiredhtmlEscape =false/>
< spring:message argumentSeparator =,arguments =$ {label},($ {field_required})code =field_simple_validationvar =field_validationhtmlEscape =false/>
< / c:when>
< c:otherwise>
< spring:message argumentSeparator =,arguments =$ {label},code =field_simple_validationvar =field_validationhtmlEscape =false/>
< / c:otherwise>
< / c:choose>
< c:set var =sec_field_validation>
< spring:escapeBody javaScriptEscape =true> $ {field_validation}< / spring:escapeBody>
< / c:set>
< c:set var =sec_field_invalid>
< spring:escapeBody javaScriptEscape =truehtmlEscape =true> $ {field_invalid}< / spring:escapeBody>
< / c:set>
< c:set var =sec_field_required>
< spring:escapeBody javaScriptEscape =true> $ {field_required}< / spring:escapeBody>
< / c:set>
< c:set var =sec_validation_regexvalue =/>
< c:if test =$ {!empty validationRegex}>
< c:set var =sec_validation_regexvalue =regExp:'$ {validationRegex}',/>
< / c:if>
< script type =text / javascript>
Spring.addDecoration(new Spring.ElementDecoration({elementId:'_ $ {sec_field} _id',widgetType:'dijit.form.ValidationTextBox',widgetAttrs:{promptMessage:'$ {sec_field_validation}',invalidMessage: $ {sec_field_invalid}',required:$ {required},$ {sec_validation_regex} missingMessage:'$ {sec_field_required}'}}));
< / script>
< / div>
< br />
< / c:if>
< / jsp:root>

我有下面的checkbox.tagx文件

 < jsp:root xmlns:c =http://java.sun.com/jsp/jstl/corexmlns:fn =http://java.sun。 com / jsp / jstl / functionsxmlns:spring =http://www.springframework.org/tagsxmlns:form =http://www.springframework.org/tags/formxmlns:jsp =http ://java.sun.com/JSP/Pageversion =2.0> 
< jsp:output omit-xml-declaration =yes/>

< jsp:directive.attribute name =idtype =java.lang.Stringrequired =truertexprvalue =truedescription =此标记的标识符改变!)/>
< jsp:directive.attribute name =fieldtype =java.lang.Stringrequired =truertexprvalue =truedescription =从表单支持对象公开的字段/&
< jsp:directive.attribute name =labeltype =java.lang.Stringrequired =falsertexprvalue =truedescription =该标签用于此字段, bundle if not supplied/>
< jsp:directive.attribute name =disableFormBindingtype =java.lang.Booleanrequired =falsertexprvalue =truedescription =设置为true以禁用Spring表单绑定/>
< jsp:directive.attribute name =rendertype =java.lang.Booleanrequired =falsertexprvalue =truedescription =指示此标记的内容和所有封闭标记(默认'true')/>
< jsp:directive.attribute name =ztype =java.lang.Stringrequired =falsedescription =用于检查元素是否已被修改(重新计算只需提供空字符串值) />

< c:if test =$ {empty render or render}>
< c:if test =$ {empty label}>
< spring:message code =label _ $ {fn:toLowerCase(fn:substringAfter(id,'_'))}var =labelhtmlEscape =false/&
< / c:if>
< c:set var =sec_field>
< spring:escapeBody javaScriptEscape =true> $ {field}< / spring:escapeBody>
< / c:set>

< script type =text / javascript> dojo.require(dijit.form.CheckBox);< / script&
< div id =_ $ {sec_id} _id>
< label for =_ $ {sec_field} _id>
< c:out value =$ {fn:escapeXml(label)}/>:
< / label>
< c:choose>
< c:when test =$ {disableFormBinding}>
< input id =_ $ {sec_field} _idname =$ {sec_field}type =checkbox/>
< / c:when>
< c:otherwise>
< form:checkbox id =_ $ {sec_field} _idpath =$ {sec_field}/>
< / c:otherwise>
< / c:choose>
< script type =text / javascript>
Spring.addDecoration(new Spring.ElementDecoration({elementId:'_ $ {sec_field} _id',widgetType:'dijit.form.CheckBox',widgetAttrs:{}})));
< / script>
< / div>
< br />
< / c:if>
< / jsp:root>


解决方案

也许

在您的代码中:


$

.net / rDjJH / 1 /rel =nofollow b $ b

 <! - 添加id属性到你的表单,用JS  - > 
< form id =fname =faction =$ {fn:escapeXml(form_url)}method =POST>
...
<! - 添加输入复选框 - >
< input type =checkboxid =terms/>
....
<! - 在你的输入按钮添加onclick属性调用JS函数 - >
< input id =proceedonclick =doSubmit()type =submitvalue =$ {fn:escapeXml(submit_label)}/>
...
< / form>

这是你需要的JS函数:

  function doSubmit(){
var checkbox = document.getElementById(terms);
if(!checkbox.checked){
alert(error message here!);
return;
}
document.getElementById(f)。submit();
}

希望它有帮助。


In my web application, I am using Spring MVC. I have the default login page that spring MVC uses. In my login page I need to have a checkbox. While logging in, the user must enable the checkbox and then click the 'LOGIN' button.
If he doesn't check the 'checkbox' a pop-up window should be displayed(with some error message).

I would like to implement this using javascript.

Can anyone please tell how to implement this?

This is my JSPX file. Sorry it is big

<div xmlns:spring="http://www.springframework.org/tags" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:util="urn:jsptagdir:/WEB-INF/tags/util" xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
  <jsp:directive.page contentType="text/html;charset=UTF-8" />
  <jsp:output omit-xml-declaration="yes" />
  <spring:message code="security_login_title" var="title" htmlEscape="false" />
  <util:panel id="title" title="${title}">
    <c:if test="${not empty param.login_error}">
      <div class="errors">
        <p>
          <spring:message code="security_login_unsuccessful" />
          <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}" />
          .
        </p>
      </div>
    </c:if>
    <c:if test="${empty param.login_error}">
      <p>
        <spring:message code="security_login_message" />
      </p>
    </c:if>
    <spring:url value="/resources/j_spring_security_check" var="form_url" />
    <form name="f" action="${fn:escapeXml(form_url)}" method="POST">
      <div>
        <label for="j_username">
          <spring:message code="security_login_form_name" />
        </label>
        <input id="j_username" type='text' name='j_username' style="width:150px" />
        <spring:message code="security_login_form_name_message" var="name_msg" htmlEscape="false" />
        <script type="text/javascript">
          <c:set var="sec_name_msg">
            <spring:escapeBody javaScriptEscape="true">${name_msg}</spring:escapeBody>
          </c:set>
          Spring.addDecoration(new Spring.ElementDecoration({elementId : "j_username", widgetType : "dijit.form.ValidationTextBox", widgetAttrs : {promptMessage: "${sec_name_msg}", required : true}})); 
        </script>
      </div>
      <br />
      <div>
        <label for="j_password">
          <spring:message code="security_login_form_password" />
        </label>
        <input id="j_password" type='password' name='j_password' style="width:150px" />
        <spring:message code="security_login_form_password_message" var="pwd_msg" htmlEscape="false" />
        <script type="text/javascript">
          <c:set var="sec_pwd_msg">
            <spring:escapeBody javaScriptEscape="true">${pwd_msg}</spring:escapeBody>
          </c:set>
          Spring.addDecoration(new Spring.ElementDecoration({elementId : "j_password", widgetType : "dijit.form.ValidationTextBox", widgetAttrs : {promptMessage: "${sec_pwd_msg}", required : true}})); 
        </script>
      </div>
      <br />
      <div class="submit">
        <script type="text/javascript">Spring.addDecoration(new Spring.ValidateAllDecoration({elementId:'proceed', event:'onclick'}));</script>
        <spring:message code="button_submit" var="submit_label" htmlEscape="false" />
        <input id="proceed" type="submit" value="${fn:escapeXml(submit_label)}" />
        <spring:message code="button_reset" var="reset_label" htmlEscape="false" />
        <input id="reset" type="reset" value="${fn:escapeXml(reset_label)}" />
      </div>
    </form>
  </util:panel>
</div>

I have the following input.tagx file

<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:spring="http://www.springframework.org/tags" xmlns:form="http://www.springframework.org/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
  <jsp:output omit-xml-declaration="yes" />

  <jsp:directive.attribute name="id" type="java.lang.String" required="true" rtexprvalue="true" description="The identifier for this tag (do not change!)" />
  <jsp:directive.attribute name="field" type="java.lang.String" required="true" rtexprvalue="true" description="The field exposed from the form backing object" />
  <jsp:directive.attribute name="label" type="java.lang.String" required="false" rtexprvalue="true" description="The label used for this field, will default to a message bundle if not supplied" />
  <jsp:directive.attribute name="labelCode" type="java.lang.String" required="false" rtexprvalue="true" description="Key for label message bundle if label is not supplied" />
  <jsp:directive.attribute name="required" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicates if this field is required (default false)" />
  <jsp:directive.attribute name="disabled" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Specify if this field should be enabled" />
  <jsp:directive.attribute name="validationRegex" type="java.lang.String" required="false" rtexprvalue="true" description="Specify regular expression to be used for the validation of the input contents" />
  <jsp:directive.attribute name="validationMessageCode" type="java.lang.String" required="false" rtexprvalue="true" description="Specify the message (message property code) to be displayed if the regular expression validation fails" />
  <jsp:directive.attribute name="validationMessage" type="java.lang.String" required="false" rtexprvalue="true" description="Specify the message to be displayed if the regular expression validation fails" />
  <jsp:directive.attribute name="min" type="java.lang.String" required="false" rtexprvalue="true" description="Specify the minimum length of the input contents" />
  <jsp:directive.attribute name="max" type="java.lang.String" required="false" rtexprvalue="true" description="Specify the maximum length of the input contents" />
  <jsp:directive.attribute name="decimalMin" type="java.lang.String" required="false" rtexprvalue="true" description="Specify the minimum size of the input contents" />
  <jsp:directive.attribute name="decimalMax" type="java.lang.String" required="false" rtexprvalue="true" description="Specify the maximum size of the input contents" />
  <jsp:directive.attribute name="disableFormBinding" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Set to true to disable Spring form binding" />
  <jsp:directive.attribute name="type" type="java.lang.String" required="false" rtexprvalue="true" description="Set field type (default 'text', or 'password')" />
  <jsp:directive.attribute name="render" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicate if the contents of this tag and all enclosed tags should be rendered (default 'true')" />
  <jsp:directive.attribute name="z" type="java.lang.String" required="false" description="Used for checking if element has been modified (to recalculate simply provide empty string value)" />

  <c:if test="${empty render or render}">

    <c:if test="${empty type}">
      <c:set value="text" var="type" />
    </c:if>

    <c:if test="${empty disabled}">
      <c:set value="false" var="disabled" />
    </c:if>

    <c:if test="${empty label}">
      <c:if test="${empty labelCode}">
        <c:set var="labelCode" value="${fn:substringAfter(id,'_')}" />
      </c:if>
      <spring:message code="label_${fn:toLowerCase(labelCode)}" var="label" htmlEscape="false" />
    </c:if>

    <c:if test="${empty validationMessage}">
      <c:choose>
        <c:when test="${empty validationMessageCode}">
          <spring:message arguments="${fn:escapeXml(label)}" code="field_invalid" var="field_invalid" htmlEscape="false" />
        </c:when>
        <c:otherwise>
          <spring:message arguments="${fn:escapeXml(label)}" code="${validationMessageCode}" var="field_invalid" htmlEscape="false" />
        </c:otherwise>
      </c:choose>
    </c:if>

    <c:if test="${empty required}">
      <c:set value="false" var="required" />
    </c:if>

    <c:set var="sec_field">
      <spring:escapeBody javaScriptEscape="true" >${field}</spring:escapeBody>
    </c:set>

    <div id="_${fn:escapeXml(id)}_id">
      <label for="_${sec_field}_id">
        <c:out value="${fn:escapeXml(label)}" />
        :
      </label>
      <c:choose>
        <c:when test="${disableFormBinding}">
          <input id="_${sec_field}_id" name="${sec_field}" type="${fn:escapeXml(type)}" />
        </c:when>
        <c:otherwise>
          <c:choose>
            <c:when test="${type eq 'password'}">
              <form:password id="_${sec_field}_id" path="${sec_field}" disabled="${disabled}" />
            </c:when>
            <c:otherwise>
              <form:input id="_${sec_field}_id" path="${sec_field}" disabled="${disabled}" />
            </c:otherwise>
          </c:choose>
          <br />
          <form:errors cssClass="errors" id="_${sec_field}_error_id" path="${sec_field}" />
        </c:otherwise>
      </c:choose>
      <c:choose>
        <c:when test="${required}">
          <spring:message code="field_required" var="field_required" htmlEscape="false" />
          <spring:message argumentSeparator="," arguments="${label},(${field_required})" code="field_simple_validation" var="field_validation" htmlEscape="false" />
        </c:when>
        <c:otherwise>
          <spring:message argumentSeparator="," arguments="${label}, " code="field_simple_validation" var="field_validation" htmlEscape="false" />
        </c:otherwise>
      </c:choose>
      <c:set var="sec_field_validation">
        <spring:escapeBody javaScriptEscape="true">${field_validation}</spring:escapeBody>
      </c:set>
      <c:set var="sec_field_invalid">
        <spring:escapeBody javaScriptEscape="true" htmlEscape="true">${field_invalid}</spring:escapeBody>
      </c:set>
      <c:set var="sec_field_required">
        <spring:escapeBody javaScriptEscape="true">${field_required}</spring:escapeBody>
      </c:set>
      <c:set var="sec_validation_regex" value="" />
      <c:if test="${!empty validationRegex}">
        <c:set var="sec_validation_regex" value="regExp : '${validationRegex}', " />
      </c:if>
      <script type="text/javascript">
        Spring.addDecoration(new Spring.ElementDecoration({elementId : '_${sec_field}_id', widgetType : 'dijit.form.ValidationTextBox', widgetAttrs : {promptMessage: '${sec_field_validation}', invalidMessage: '${sec_field_invalid}', required : ${required}, ${sec_validation_regex} missingMessage : '${sec_field_required}' }})); 
      </script>
    </div>
    <br />
  </c:if>
</jsp:root>

I have the following checkbox.tagx file

<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:spring="http://www.springframework.org/tags" xmlns:form="http://www.springframework.org/tags/form" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
  <jsp:output omit-xml-declaration="yes" />

  <jsp:directive.attribute name="id" type="java.lang.String" required="true" rtexprvalue="true" description="The identifier for this tag (do not change!)" />
  <jsp:directive.attribute name="field" type="java.lang.String" required="true" rtexprvalue="true" description="The field exposed from the form backing object" />
  <jsp:directive.attribute name="label" type="java.lang.String" required="false" rtexprvalue="true" description="The label used for this field, will default to a message bundle if not supplied" />
  <jsp:directive.attribute name="disableFormBinding" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Set to true to disable Spring form binding" />
  <jsp:directive.attribute name="render" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicate if the contents of this tag and all enclosed tags should be rendered (default 'true')" />
  <jsp:directive.attribute name="z" type="java.lang.String" required="false" description="Used for checking if element has been modified (to recalculate simply provide empty string value)" />

  <c:if test="${empty render or render}">
    <c:if test="${empty label}">
      <spring:message code="label_${fn:toLowerCase(fn:substringAfter(id,'_'))}" var="label" htmlEscape="false" />
    </c:if>
    <c:set var="sec_field">
      <spring:escapeBody javaScriptEscape="true">${field}</spring:escapeBody>
    </c:set>

    <script type="text/javascript">dojo.require("dijit.form.CheckBox");</script>
    <div id="_${sec_id}_id">
      <label for="_${sec_field}_id">
        <c:out value="${fn:escapeXml(label)}" />:
      </label>
      <c:choose>
        <c:when test="${disableFormBinding}">
          <input id="_${sec_field}_id" name="${sec_field}" type="checkbox"/>
        </c:when>
        <c:otherwise>
          <form:checkbox id="_${sec_field}_id" path="${sec_field}"/>
        </c:otherwise>
      </c:choose>
      <script type="text/javascript">
        Spring.addDecoration(new Spring.ElementDecoration({elementId : '_${sec_field}_id', widgetType : 'dijit.form.CheckBox', widgetAttrs : {}}));
      </script>
    </div>
    <br />
  </c:if>
</jsp:root>

解决方案

Maybe this sample helps.

In your code:

<!-- add the id attribute to your form, to get it with JS -->
<form id="f" name="f" action="${fn:escapeXml(form_url)}" method="POST">
    ...
    <!-- add an input checkbox -->
    <input type="checkbox" id="terms" />
    ....
    <!-- in your input button add onclick attribute calling the JS function -->
    <input id="proceed" onclick="doSubmit()" type="submit" value="${fn:escapeXml(submit_label)}" />
    ...
</form>

And this is the JS function you need:

function doSubmit() {
    var checkbox = document.getElementById("terms");
    if (!checkbox.checked) {
        alert("error message here!");
        return;
    }
    document.getElementById("f").submit();
}​

Hope it helps.

这篇关于Spring - 登录页面有条款和条件页面(使用Javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆