Spring中form:label标签的优点是什么? [英] What is the advantage of form:label tag in Spring?

查看:198
本文介绍了Spring中form:label标签的优点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<form:label path="company">Enter company name:</form:label>

渲染器-

<label for="company">Enter company name:</label>

为什么我不应该直接使用更简洁的HTML标记?

Why shouldn't I directly use the HTML tag which is more concise?

推荐答案

<form:label />标记可以访问基础模型和绑定结果,因此可以在出错时使用另一个样式类.

The <form:label /> tag has access to the underlying model and binding results and as such can, on error, use another style class.

<form:label cssClass="title" cssErrorClass="title error" path="company" />

在发生错误的情况下,以上代码与正常情况下的呈现方式会有所不同.当然,您也可以在没有form标记的情况下执行此操作,但这意味着您需要在页面中包含一些逻辑,通常不建议这样做.

The code above would, in case of an error, render differently than the normal case. Of course you could also do this without the form tag but that would mean you need to include some logic into your pages, which in general isn't advised.

有关所有属性,请参见

For all the properties see the reference guide

这篇关于Spring中form:label标签的优点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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