JSTL - <form:select> 的用法

本文详细介绍了表单中下拉框组件的使用方法及其构成要素,包括单选和多选下拉框的实现原理,并解释了如何通过属性设置来生成对应的下拉选项。

转载自: http://www.web-tag.net/3c98ca7b0cac8312.htm

下拉框组件标签  
    下拉框标签的典型形式为:
    <form: select path="city" items="${cityList}"/>,它包括两方面的数据:

    1)对应表单对象属性值(city);
    2)用于构造整个下拉框选项的数据(cityList)。

    严格地说,下拉框组件分为单选和多选两种形式,当表单对象对应属性为复数形态的类型时(如String[]、List、Set),产生的目标组件为多选下拉框,反之为单选下拉框.

   

把下面的source,改写成thymeleaf形式文件。 <%@ page contentType="text/html; charset=UTF-8"%> <%@ page pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <!DOCTYPE html> <html> <head> <!-- IEバージョン設定 --> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE11"> <title> 会社マスタ一覧画面</title> <!-- jQuery設定 --> <script src="<c:url value="/resources/js/jquery-1.11.3.min.js" />"></script> <!-- CSS設定 --> <link rel="stylesheet" type="text/css" href="<c:url value="/resources/css/tsocms.css" />"> <script> $(function() { $(".stockCompanyMasterListTable tr:odd").addClass("odd"); $(".stockCompanyMasterListTable tr:even").addClass("even"); }); </script> <script> <!-- function stockCompanyclearButton() { document.select.mechSubCode.value = ""; document.select.stockCompanyName.value =""; } function updateSubmitCheck() { if(!radioCheck("更新対象をラジオボタンで選択してください。")) return; stockCompanyMasterListUpdateButton(); } function deleteSubmitCheck() { if(!radioCheck("削除対象をラジオボタンで選択してください。")) return; stockCompanyMasterListDeleteButton(); } function stockCompanySearchButton() { var target = document.getElementById("stockCompanyMasterListForm"); target.action = "${pageContext.request.contextPath}/stockcompanymasterlist/select"; target.submit(); } function stockCompanyMasterListDeleteButton() { var target = document.getElementById("stockCompanyMasterListForm"); target.action = "${pageContext.request.contextPath}/stockcompanymasterdelete"; target.submit(); } function stockCompanyMasterListUpdateButton() { var target = document.getElementById("stockCompanyMasterListForm"); target.action = "${pageContext.request.contextPath}/stockcompanymasterupdate"; target.submit(); } function radioCheck(msg) { var flag = false; var elm = document.getElementsByName('selectedKey'); for (i = 0; i < elm.length; i++) { if (elm[i].checked) { flag = true; } } if (!flag) { alert(msg); return false; } return true; } //--> </script> </head> <body> <!-- <!-- ページ見出し --> <div> <h1> 会社マスタ一覧画面</h1> </div> <form:form name="select" modelAttribute="stockCompanyMasterListForm" method="post" action="${pageContext.request.contextPath}/stockcompanymasterlist/select"> <!-- 会社結果一覧表 --> <div class="stockCompanyMasterListTableAll"> <div class="keyleft"> <!-- 検索キー --> <!-- 機構加入者コード --> <div class="searchkey"> <span class="mechSubCodeKey">機構加入者コード</span> <form:input type="search" path="mechSubCode" size="45" /> </div> <!-- 会社名 --> <div class="searchkey"> <span class="stockCompanyNameKey">会社名</span> <form:input type="search" path="stockCompanyName" size="45" /> </div> <!-- Hidden検索キー --> <form:hidden path="mechSubCodeHidden" /> <form:hidden path="stockCompanyNameHidden" /> </div> <div class="keyright"> <!-- 検索ボタン --> <form:button type="submit" name="stockCompanySearchbutton" id="stockCompanySearchbutton" onclick="stockCompanySearchButton()">検索</form:button> <!-- 初期化ボタン --> <form:button type="button" name="stockCompanyclearbutton" id="stockCompanyclearbutton" onclick="stockCompanyclearButton()">初期化</form:button> </div> <div class="stockCompanyMasterListTable"> <table class="stockCompanyMasterListTable"> <thead class="stockCompanyMasterList"> <tr> <th class="radioButton"></th> <th class="mechSubCode">機構加入者コード</th> <th class="stockCompanyName">会社名</th> <th class="stockCompanyNameKana">会社名カナ</th> <th class="effectiveDate">適用開始日</th> <th class="expireDate">適用終了日</th> </tr> </thead> <tbody class="searchListBody"> <c:forEach var="detail" items="${stockCompanyMasterListForm.stockCompanyMasterListDetailFormList}" varStatus="status"> <tr> <td class="radioButton"> <form:radiobutton path="selectedKey" value="${detail.mechanismSubscriberCd},${detail.effectiveDate}" /><br> </td> <td class="mechSubCode"> <c:out value="${detail.mechanismSubscriberCd}"></c:out> </td> <td class="stockCompanyName"> <c:out value="${detail.stockcompany}"></c:out> </td> <td class="stockCompanyNameKana"> <c:out value="${detail.stockcompanyKana}"></c:out> </td> <td class="effectiveDate"> <c:out value="${detail.effectiveDate}"></c:out> </td> <td class="expireDate"> <c:out value="${detail.expireDate}"></c:out> </td> </tr> </c:forEach> </tbody> </table> </div> <div class="left"></div> <div class="right"> <!-- 新規登録ボタン --> <form:button type="button" name="stockCompanyMasterListRegisterbutton" id="stockCompanyMasterListRegisterbutton" onclick="location.href='${pageContext.request.contextPath}/stockcompanymasterregister'">新規登録</form:button> <!-- 更新ボタン --> <form:button type="button" name="stockCompanyMasterListUpdatebutton" id="stockCompanyMasterListUpdatebutton" onclick="updateSubmitCheck()">更新</form:button> <!-- 削除ボタン --> <form:button type="button" name="stockCompanyMasterListDeletebutton" id="stockCompanyMasterListDeletebutton" onclick="deleteSubmitCheck()">削除</form:button> <!-- 戻るボタン --> <form:button type="button" name="stockCompanyMasterListReturnbutton" id="stockCompanyMasterListReturnbutton" onclick="location.href='${pageContext.request.contextPath}/master'">戻る</form:button> </div> </div> </form:form> </body> </html>
07-18
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:cc="http://java.sun.com/jsf/composite" xmlns:lkmcc="http://java.sun.com/jsf/composite/lkmComponent" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" xmlns:c="http://java.sun.com/jsp/jstl/core"> <cc:interface/> <cc:implementation> <style> .form-block { display: flex; align-items: center; margin-bottom: 10px; } .form-block label { font-weight: bold; flex: 0 0 120px; text-align: right; margin-right: 10px; } .form-block input, .form-block select, .form-block textarea { width: 100%; box-sizing: border-box; } .button-block { display: flex; justify-content: flex-end; } .button-block button { margin-left: 10px; } @media (max-width: 768px) { .form-block { flex-direction: column; align-items: flex-start; } .form-block label { margin-bottom: 5px; } .button-block { flex-direction: column; align-items: flex-end; } .button-block button { margin-left: 0; margin-top: 10px; } } </style> <p:outputPanel> <!-- 表单块 --> <div class="form-block"> <label for="create_orderNo">订单号:</label> <p:inputText id="create_orderNo" value="#{unStdOrderBean.createBoardDm.orderNo}" readonly="#{not empty unStdOrderBean.createBoardDm.orderNo}" style="width:100%;" /> </div> <div class="form-block"> <label for="create_partCode">零件编码:</label> <p:inputText id="create_partCode" value="#{unStdOrderBean.createBoardDm.partCode}" style="width:100%;" /> </div> <div class="form-block"> <label for="create_partDesc">零件描述:</label> <p:inputText id="create_partDesc" value="#{unStdOrderBean.createBoardDm.partDesc}" style="width:100%;" /> </div> <div class="form-block"> <label for="create_partName">零件名称:</label> <p:inputText id="create_partName" value="#{unStdOrderBean.createBoardDm.partName}" style="width:100%;" /> <p:ajax event="blur" listener="#{unStdOrderBean.handlePartNameChange}" update="create_steelName" /> </div> <div class="form-block"> <label for="create_diameter">尺寸:</label> <p:inputText id="create_diameter" value="#{unStdOrderBean.createBoardDm.diameter}" type="number" step="1" style="width: calc(50% - 6px);" placeholder="请输入直径"/> <span style="margin: 0 5px;">X</span> <p:inputText id="create_length" value="#{unStdOrderBean.createBoardDm.length}" type="number" step="1" style="width: calc(50% - 6px);" placeholder="请输入长度"/> </div> <div class="form-block"> <label for="create_qty">零件数量:</label> <p:inputText id="create_qty" value="#{unStdOrderBean.createBoardDm.qty}" type="number" step="1" style="width:100%;" /> </div> <div class="form-block"> <label for="create_steelName">钢种:</label> <p:selectOneMenu id="create_steelName" value="#{unStdOrderBean.createBoardDm.steelName}" style="width:100%;"> <f:selectItems value="#{unStdOrderBean.steelOptions}" /> </p:selectOneMenu> </div> <div class="form-block"> <label for="create_processType">加工类型:</label> <p:selectOneMenu id="create_processType" value="#{unStdOrderBean.createBoardDm.processType}" style="width:100%;"> <f:selectItem itemLabel="连体" itemValue="连体" /> <f:selectItem itemLabel="单体" itemValue="单体" /> <f:selectItem itemLabel="双体" itemValue="双体" /> </p:selectOneMenu> </div> <div class="form-block"> <label for="create_remark">备注:</label> <p:inputTextarea id="create_remark" value="#{unStdOrderBean.createBoardDm.remark}" rows="6" cols="50" style="width:100%;" /> </div> <!-- 按钮块 --> <div class="button-block"> <p:commandButton value="提交" actionListener="#{unStdOrderBean.createOrder}" update="@form:orderList:board_page" class="query" ajax="true" /> <p:commandButton value="关闭" onclick="PF('createOrder').hide(); return false;" /> </div> </p:outputPanel> </cc:implementation> </html> 为什么还报错 <p:ajax> Event:blur is not supported.
08-20
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%-- Created by IntelliJ IDEA. User: Administrator Date: 2025/2/28 Time: 15:47 To change this template use File | Settings | File Templates. --%> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>学生列表</title> </head> <body> <h2 style="text-align: center">欢迎您,${name}</h2> <form action="<%=request.getContextPath()%>/student/selectStudentAndGrade" method="post"> 学生姓名:<input type="text" name="studentName" placeholder="请输入要搜索的学生姓名" value="${student.studentName}"> 班级:<select name="gradeId"> <option value=>请输入班级</option> <option value="1"<c:if test="${student.gradeId=='1'}">selected</c:if>>java1班</option> <option value="2"<c:if test="${student.gradeId=='2'}">selected</c:if>>java2班</option> <option value="3"<c:if test="${student.gradeId=='3'}">selected</c:if>>java3班</option> <option value="4"<c:if test="${student.gradeId=='4'}">selected</c:if>>java4班</option> </select> <input type="submit" value="查询"> <input type="button" value="重置" onclick="resetQuery()"> </form> </form> <input type="button" value="新增" onclick="location.href='<%=request.getContextPath()%>/studentAdd.jsp'"> <table> <tr> <td>序号</td> <td>学生姓名</td> <td>年龄</td> <td>出生日期</td> <td>班级</td> </tr> <c:forEach items="${studentList}" var="tea" varStatus="sta"> <tr> <td>${sta.count}</td> <td>${tea.studentName}</td> <td>${tea.age}</td> <%-- <td>${stu.birth}</td>--%> <td><fmt:formatDate value="${tea.birth}" pattern="yyyy-MM-dd"/></td> <td>${tea.grade.gradeName}</td> <%-- <td>${stu.grade.gradeName}</td>--%> <td><a href="<%=request.getContextPath()%>/student/getStudentInfo/${tea.id}">修改</a> <a href="<%=request.getContextPath()%>/student/deleteStudent/${tea.id}" onclick="if (confirm('确认是否删除')==false) {return false;}">删除</a></td> </tr> </c:forEach> </table> </body> <script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.9.1.js"></script> <script> function resetQuery(){ $("input[type=text]").val(""); $('select').prop('selectedIndex',0); } </script> </html>加css样式
06-13
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui" template="/templates/LkmTemplate.jsf" xmlns:f="http://java.sun.com/jsf/core" xmlns:c="http://java.sun.com/jsp/jstl/core"> <ui:param name="pageTitle" value="工程部补录工时"/> <ui:define name="head"></ui:define> <ui:define name="content-introduction"> <h1>工程部补录工时</h1> </ui:define> <ui:define name="content"> <p:growl showDetail="true" id="grlInfo" widgetVar="grlInfo"> <p:autoUpdate/> </p:growl> <p:outputPanel id="title_Bar"> <div class="ui-inputgroup" style="display:-webkit-flex;flex-wrap: wrap;"> <div class="ui-inputgroup"> <span class="ui-inputgroup-addon" style="width:80px;">订单号</span> <p:inputText id="orderNo" style="width:120px" value="#{engWTChangeBean.orderNo}" valueChangeListener="#{engWTChangeBean.orderNoChange}"> <p:ajax event="change" actionListener="#{engWTChangeBean.orderNoChange}" update="q_plateNo"/> </p:inputText> </div> <p:spacer width="10px" height="10px"/> <div class="ui-inputgroup" > <div class="ui-inputgroup"> <span class="ui-inputgroup-addon">板名</span> <p:selectCheckboxMenu id="q_plateNo" multiple="true" emptyLabel="请选择" value="#{engWTChangeBean.addPlateNos}" style="width:130px;"> <f:selectItems value="#{engWTChangeBean.plateList}"/> </p:selectCheckboxMenu> </div> </div> <p:spacer width="10" height="10"/> <div class="ui-inputgroup"> <span class="ui-inputgroup-addon" style="width:80px;">分钟数</span> <p:inputText id="minutes" style="width:120px" value="#{engWTChangeBean.minutes}" type="number" min="1"/> </div> <p:spacer width="10" height="10"/> <div class="ui-inputgroup" style="display:inline-block; "> <div class="ui-inputgroup"> <span class="ui-inputgroup-addon">项目</span> <p:selectOneMenu id="process" label="请选择" value="#{engWTChangeBean.process}" style="width:130px;"> <f:selectItem itemLabel="客户变更补工时" itemValue="客户变更补工时"/> <f:selectItem itemLabel="配合生产调整变更补工时" itemValue="配合生产调整变更补工时"/> </p:selectOneMenu> </div> </div> <p:spacer width="10" height="10"/> <div class="ui-inputgroup"> <span class="ui-inputgroup-addon" style="width:80px;">备注</span> <p:inputText id="remark" style="width:200px" value="#{engWTChangeBean.remark}"/> </div> <p:spacer width="10px" height="10px"/> <p:commandButton styleClass="info-btn" value="提交" onclick="PF('overWeldingStatusDialog').show()" actionListener="#{engWTChangeBean.doSubmit}" update="title_Bar"/> </div> </p:outputPanel> <p:dialog modal="true" id="overWdldingStatusDialog" widgetVar="overWeldingStatusDialog" header="正在处理中....请稍后!" draggable="false" closable="false" resizable="false"> <p:graphicImage value="/quality/img/ajaxloadingbar.gif"/> </p:dialog> </ui:define> </ui:composition> 板名多选就会导致除了项目以外的选项一并把框变大,如何只变大板名选项框
最新发布
11-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值