:form prependId = false

理解JSF中表单ID前缀问题及解决方法
本文深入探讨了JSF中表单ID前缀的原理及其可能带来的问题,提供了如何给表单赋予有意义ID的建议,并讨论了禁用此功能的后果。同时强调了自定义验证消息的重要性,以及正确设置字段名以避免重复验证信息的方法。

f you care to see the HTML source from your browser, you will find out that the id of your input field is <form-id>+":"+<input-field-id>, in your case, j_idt7:UserId:. Try to give your<h:form> some meaningful id in order to make some sense out of it. You can read about JSF IDs here. In case you don't like it, you can turn it off by modifying your form tag to something like this,

<h:form prependId = false> // its true by default.

But that might turn out to be problematic, as pointed out by BalusC here.

Furthermore, it seems like you have never configured any validation messages yourself. Which in turn ends up with this message. Hence, a message.properties file is needed to have a control over message and show something more appropriate. Even then the field name should not be the part of the message, to make those validation message generic to avoid repetition. See BalusC's answer regarding the use of label attribute inside the <h:inputText>.

 

http://stackoverflow.com/questions/4385118/jsf-2-why-the-form-id-prefix-in-the-hmessage-output/4390231

<?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="change" listener="#{unStdOrderBean.handlePartNameChange}" update="create_steelName" /> </p:inputText> </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="" noSelectionOption="true" /> <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="#{unStdOrderBean.updateTargetComponent}" class="query" ajax="true" process="@form" /> <p:commandButton value="关闭" onclick="PF('createOrder').hide(); return false;" /> </div> </p:outputPanel> </cc:implementation> </html> 我碎片页这样写的
08-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值