在spring petclinic中以jsp jstl形式创建布尔字段

时间:2013-12-27 23:33:10

标签: java spring jsp spring-mvc jstl

春季petclinic带有jsp中的字段类型,用于文本输入和选择框。如何创建一个字段类型,为用户提供添加/编辑布尔数据的复选框?

以下是inputField和selectField的标记语法示例:

<petclinic:inputField label="Name" name="name"/>  
<petclinic:selectField name="type" label="Type " names="${types}" size="5"/>

您可以看到使用这些标记{j}的jsp。

定义inputField标记的代码是at this link。定义selectField标记的代码是at this link

那么如何为布尔数据类型和复选框设置自定义标签?我以前从未见过这种语法,我想知道它是如何工作的。

1 个答案:

答案 0 :(得分:1)

复选框:

<%@ attribute name="name" required="true" rtexprvalue="true"
              description="Name of corresponding property in bean object" %>
<%@ attribute name="label" required="true" rtexprvalue="true"
              description="Label appears in red color if input is considered as invalid after submission" %>
<%@ attribute name="names" required="true" rtexprvalue="true" type="java.util.List"
              description="Names in the list" %>
<%@ attribute name="size" required="true" rtexprvalue="true"
              description="Size of Checkbox List" %>
<spring:bind path="${name}">
    <c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/>
    <div class="${cssGroup}">
        <label class="control-label">${label}</label>

        <div class="controls">
            <form:checkboxes path="${name}" items="${names}" size="${size}"/>
            <span class="help-inline">${status.errorMessage}</span>
        </div>
    </div>
</spring:bind>

布尔/单选按钮:

<%@ attribute name="name" required="true" rtexprvalue="true"
              description="Name of corresponding property in bean object" %>
<%@ attribute name="label" required="true" rtexprvalue="true"
              description="Label appears in red color if input is considered as invalid after submission" %>
<%@ attribute name="value" required="true" rtexprvalue="true" type="java.lang.Boolean"
              description="True or False" %>
<spring:bind path="${name}">
    <c:set var="cssGroup" value="control-group ${status.error ? 'error' : '' }"/>
    <div class="${cssGroup}">
        <label class="control-label">${label}</label>

        <div class="controls">
            <form:radiobutton path="${name}" value="${value}"/>
            <span class="help-inline">${status.errorMessage}</span>
        </div>
    </div>
</spring:bind>