Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: 16e1ba9b14
executable file 103 lines (88 sloc) 3.419 kB
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<%@ taglib prefix="c" uri=""%>
<%@ taglib prefix="fmt" uri=""%>
<%@ taglib prefix="form" uri=""%>
<%@ taglib prefix="spring" uri=""%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add User</title>
<spring:url value="/bootstrap/css/bootstrap.min.css" var="bootstrapUrl" />
<link href="${bootstrapUrl}" rel="stylesheet">
<spring:url value="/js/jquery.js" var="jqueryUrl" />
<script src="${jqueryUrl}"></script>
<div class="container" style="padding-top: 50px;">
<jsp:include page="../menu.jsp"/>
<c:if test="${successMessage != null}">
<spring:url value="/userAjaxBootstrap.htm" var="formUrl" />
<spring:url value="/userAjaxBootstrap.json" var="formJsonUrl" />
<!-- Bootstrap form -->
<form:form modelAttribute="user" class="form-horizontal"
id="add-user-form" action="${formUrl}">
<div class="control-group" id="firstName">
<label class="control-label">Enter your first name:</label>
<div class="controls">
<form:input path="firstName" />
<span class="help-inline"><form:errors path="firstName" /></span>
<div class="control-group" id="lastName">
<label class="control-label">Enter your last name:</label>
<div class="controls">
<form:input path="lastName" />
<span class="help-inline"><form:errors path="lastName" /></span>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save changes</button>
<button type="reset" class="btn">Cancel</button>
<script type="text/javascript">
function collectFormData(fields) {
var data = {};
for (var i = 0; i < fields.length; i++) {
var $item = $(fields[i]);
data[$item.attr('name')] = $item.val();
return data;
$(document).ready(function() {
var $form = $('#add-user-form');
$form.bind('submit', function(e) {
// Ajax validation
var $inputs = $form.find('input');
var data = collectFormData($inputs);
$.post('${formJsonUrl}', data, function(response) {
if (response.status == 'FAIL') {
for (var i = 0; i < response.result.length; i++) {
var item = response.result[i];
var $controlGroup = $('#' + item.fieldName);
} else {
var $alert = $('<div class="alert alert-success"></div>');
}, 'json');
return false;
Jump to Line
Something went wrong with that request. Please try again.