JSF 标签h:panelGrid

本文介绍了一个使用JSF框架实现的简单登录表单示例。通过<h:panelGrid>组件布局,实现了用户名与密码输入框及对应提示信息的功能。此示例有助于理解JSF中表单元素的基本用法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<f:view>
<h:panelGrid column="3">
      <h:outputText value="用户名"/>
      <h:inputText value="" />
      <h:message for="" />
      <h:outputText value="密码"/>
      <h:inputText value=""/>
      <h:message for="" />
      <h:commandButton value="" />
</h:panelGrid>
</f:view>

 

<h:panelGrid> 用于摆放组件,column的值确定每一行可以放多少个组件。

<?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> .ui-panel .ui-panel-content { border: none !important; padding: 0.571em 0em !important; } .no-border { border: none !important; } .no-border td{ vertical-align: top; } .no-border .ui-panelgrid-cell { border: none !important; padding: 5px !important; } </style> <p:outputPanel> <h:panelGrid columns="2" styleClass="no-border"> <p:outputPanel style = "display: flex;flex-wrap: wrap;"> <h:panelGrid columns="1" styleClass="no-border"> <h:panelGrid columns="1" responsive="true" styleClass="no-border"> <p:outputLabel value="编号:" /> <p:inputText id="create_studentNo" style="width:250px" value="#{studentBean.createBoardDm.studentNo}"/> <p:outputLabel value="姓名:" /> <p:inputText id="create_name" style="width:250px" value="#{studentBean.createBoardDm.name}"/> <p:outputLabel value="年龄:" /> <p:inputText id="create_age" style="width:250px" value="#{studentBean.createBoardDm.age}"/> <p:outputLabel value="家庭地址:" /> <p:inputTextarea id="create_homeAddress" value="#{studentBean.createBoardDm.homeAddress}" rows="6" cols="50" /> <p:outputLabel value="有效状态:" /> <p:selectOneMenu id="create_validStatus" value="#{studentBean.createBoardDm.validStatus}" style="width:250px"> <f:selectItem itemLabel="有效" itemValue="Y" /> <!-- 默认选中有效 --> <f:selectItem itemLabel="无效" itemValue="N" /> </p:selectOneMenu> </h:panelGrid> </h:panelGrid> </p:outputPanel> </h:panelGrid> <h:panelGrid columns="1" responsive="true" styleClass="no-border"> <p:commandButton value="提交" actionListener="#{studentBean.createStudent}" update="@form:tabView:studentList:board_page" class="query" ajax="true" style="width:80px;" oncomplete="if (!args || !args.validationFailed) { PF('createStudent').hide(); }" /> <p:commandButton value="关闭" style="width:80px;" onclick="PF('createStudent').hide(); return false;" /> </h:panelGrid> </p:outputPanel> </cc:implementation> </html>帮我插入一个字段为入学日期enrollmentDate,只可以选择年月日
07-15
<?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> .ui-panel .ui-panel-content { border: none !important; padding: 0.571em 0em !important; } .no-border { border: none !important; } .no-border td{ vertical-align: top; } .no-border .ui-panelgrid-cell { border: none !important; padding: 5px !important; } </style> <p:outputPanel> <h:panelGrid columns="2" styleClass="no-border"> <p:outputPanel style = "display: flex;flex-wrap: wrap;"> <h:panelGrid columns="1" styleClass="no-border"> <h:panelGrid columns="2" responsive="true" styleClass="no-border"> <h:form id="yourFormId" novalidate="novalidate"> <p:outputLabel value="编号:" /> <p:inputText id="create_studentNo" style="width:250px" value="#{studentBean.createBoardDm.studentNo}" readonly="#{not empty studentBean.createBoardDm.studentNo}" required="true" requiredMessage="请输入编号" /> <p:message for="create_studentNo" style="color:red;" /> <p:outputLabel value="姓名:" /> <p:inputText id="create_name" style="width:250px" value="#{studentBean.createBoardDm.name}" required="true" requiredMessage="请输入姓名" /> <p:message for="create_name" style="color:red;" /> <p:outputLabel value="年龄:" /> <p:inputText id="create_age" style="width:250px" value="#{studentBean.createBoardDm.age}" required="true" requiredMessage="请输入年龄" type="number" min="0" max="150" step="1" /> <p:message for="create_age" style="color:red;" /> </h:form> <p:outputLabel value="家庭地址:" /> <p:inputTextarea id="create_homeAddress" value="#{studentBean.createBoardDm.homeAddress}" rows="6" cols="50" /> <p:outputLabel value="入学日期:" /> <p:calendar id="create_enrollmentDate" value="#{studentBean.createBoardDm.enrollmentDate}" pattern="yyyy-MM-dd" inputStyle="width:150px"></p:calendar> <p:outputLabel value="有效状态:" /> <p:selectOneMenu id="create_validStatus" value="#{studentBean.createBoardDm.validStatus}" style="width:150px"> <f:selectItem itemLabel="有效" itemValue="Y" /> <f:selectItem itemLabel="无效" itemValue="N" /> </p:selectOneMenu> </h:panelGrid> </h:panelGrid> </p:outputPanel> </h:panelGrid> <h:panelGrid columns="2" responsive="true" styleClass="no-border"> <p:commandButton value="提交" actionListener="#{studentBean.createStudent}" update="@form:tabView:studentList:board_page" class="query" ajax="true" style="width:80px;" oncomplete="if (!args || !args.validationFailed) { PF('createStudent').hide(); }" /> <p:commandButton value="关闭" style="width:80px;" onclick="PF('createStudent').hide(); return false;" /> </h:panelGrid> </p:outputPanel> </cc:implementation> </html>帮我优化下点击提交按钮才验证必填
07-16
<?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> .ui-panel .ui-panel-content { border: none !important; padding: 0.571em 0em !important; } .no-border { border: none !important; } .no-border td{ vertical-align: top; } .no-border .ui-panelgrid-cell { border: none !important; padding: 5px !important; } </style> <p:outputPanel> <h:panelGrid columns="2" styleClass="no-border"> <p:outputPanel style = "display: flex;flex-wrap: wrap;"> <h:panelGrid columns="1" styleClass="no-border"> <h:panelGrid columns="3" responsive="true" styleClass="no-border"> <p:outputLabel value="编号:" /> <p:inputText id="create_studentNo" style="width:250px" value="#{studentBean.createBoardDm.studentNo}" readonly="#{not empty studentBean.createBoardDm.studentNo}" required="true" requiredMessage="请输入编号" /> <p:message for="create_studentNo" style="color:red;" /> <p:outputLabel value="姓名:" /> <p:inputText id="create_name" style="width:250px" value="#{studentBean.createBoardDm.name}" required="true" requiredMessage="请输入姓名" /> <p:message for="create_name" style="color:red;" /> <p:outputLabel value="年龄:" /> <p:inputText id="create_age" style="width:250px" value="#{studentBean.createBoardDm.age}" required="true" requiredMessage="请输入年龄" type="number" min="0" max="150" step="1" /> <p:message for="create_age" style="color:red;" /> </h:panelGrid> <h:panelGrid columns="2" responsive="true" styleClass="no-border"> <p:outputLabel value="家庭地址:" /> <p:inputTextarea id="create_homeAddress" value="#{studentBean.createBoardDm.homeAddress}" rows="6" cols="50" /> <p:outputLabel value="入学日期:" /> <p:calendar id="create_enrollmentDate" value="#{studentBean.createBoardDm.enrollmentDate}" pattern="yyyy-MM-dd" inputStyle="width:150px"></p:calendar> <p:outputLabel value="有效状态:" /> <p:selectOneMenu id="create_validStatus" value="#{studentBean.createBoardDm.validStatus}" style="width:150px"> <f:selectItem itemLabel="有效" itemValue="Y" /> <f:selectItem itemLabel="无效" itemValue="N" /> </p:selectOneMenu> </h:panelGrid> </h:panelGrid> </p:outputPanel> </h:panelGrid> <h:panelGrid columns="2" responsive="true" styleClass="no-border"> <p:commandButton value="提交" actionListener="#{studentBean.createStudent}" update="@form:tabView:studentList:board_page" class="query" ajax="true" style="width:80px;" oncomplete="if (!args || !args.validationFailed) { PF('createStudent').hide(); }" /> <p:commandButton value="关闭" style="width:80px;" onclick="PF('createStudent').hide(); return false;" /> </h:panelGrid> </p:outputPanel> </cc:implementation> </html> 如何提交的时候才验证必填
07-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值