使用spring框架hibernate使用bootstrap验证表单

时间:2014-12-24 05:01:37

标签: java spring hibernate twitter-bootstrap

所以我有这个表单,它需要验证,我正在使用引导程序,但现在我正在尝试使用hibernate将值插入我的数据库,但它不会允许我,因为它需要&#34 ;需要自动对焦"或"必需"一个等号,我没有看到任何关于bootstrap的文档如何验证我的表单..我现在需要使用javascript验证我的表单吗?我希望有人可以帮助我,这是我的代码

<c:url var="actionUrl" value="save" />
    <form:form id="registerForm" commandName="users" method="post" action="${actionUrl }" class="form-horizontal" >
        <fieldset>
        <div class="form-group">
            <label class="col-lg-2 control-label" for="email">Email</label>
            <div class="col-lg-10">
            <form:input path="email" class="form-control" placeholder="Email Address" type="email" required autofocus />
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-2 control-label" for="username">Username</label>
            <div class="col-lg-10">
            <form:input path="username" class="form-control" placeholder="Username" type="username" required />
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-2 control-label" for="password">Password</label>
            <div class="col-lg-10">
            <form:input path="password" class="form-control" placeholder="Password" type="password" required />
            </div>
        </div>

        <div class="form-group">
            <label class="col-lg-2 control-label" for="location">Location</label>
            <div class="col-lg-10">
                <form:select path="location" class="form-control" type="location" >
                <option>France</option>
                <option>Amsterdam</option>
                <option>Philippines</option>
                <option>Others</option>
            </form:select>

            <form:input path="userId" type="hidden" />
            </div>
        </div>

        <div class="modal-footer">
            <button class="btn btn-primary" type="submit" id="register">Register</button>
            <button class="btn btn-default" data-dismiss="modal" type="button">Cancel</button> 
        </div><!-- end modal-footer -->
        </fieldset>
    </form:form>

1 个答案:

答案 0 :(得分:1)

添加 <form:errors path="username" /> 对于所有输入字段等等..它对我有用