[英]primefaces requiredMessage gets lost when p:autoComplete moved into custom component
I'm using PrimeFaces in a pretty standard Java web app (jsf-2) and am having an issue with my required message displaying when I move ap:autoComplete component into it's own custom component.. 我在漂亮的标准Java Web应用程序(jsf-2)中使用PrimeFaces,并且当我将ap:autoComplete组件移入其自己的自定义组件时,所需的消息显示出现问题。
first, the p:autoComplete when it's on the page itself - this is working fine (simplified): 首先,当p:autoComplete位于页面本身上时-可以正常工作(简化):
<h:panelGrid id="newRoleAdminGrid" >
<p:autoComplete id="newRoleAdminPerson"
style="position: relative; padding-right:5px"
value="#{roleList.newRoleAdminPerson}"
var="personVar"
itemValue="#{personVar}"
itemLabel="#{personVar.fullFamiliarName}"
forceSelection="true"
completeMethod="#{personAutoComplete.byGeneralCriteria}"
converter="PersonConverter"
minQueryLength="3"
maxResults="50"
scrollHeight="400"
size="50"
required="true"
requiredMessage="admin name is requiredd"
title="enter users first name, last name or login" >
</p:autoComplete>
<h:message for="newRoleAdminPerson" class="redError"/>
<p:commandButton value="add" ajax="true"
update="roleAdminTable,newRoleAdminGrid"
id="addRoleAdminBtn"
actionListener="#{roleList.newRoleAdmin}"
style="margin:5px;"
icon="ui-icon-plus"/>
</h:panelGrid>
see that h:message above? 看到上面的h:message吗? that works perfect and displays when the value is blank, or it doesnt pass the PersonConverter... 可以完美工作并在值为空或未通过PersonConverter时显示...
however I have this same component all over my app, so i created a custom component. 但是我在整个应用程序中都具有相同的组件,因此我创建了一个自定义组件。
here's the component: 这是组件:
<cc:interface>
<cc:attribute name="id" type="String" required="true" />
<cc:attribute name="person" type="com.foo.bar.model.Person" required="true" />
<cc:attribute name="size" type="int" required="false" default="50" />
<cc:attribute name="required" type="boolean" required="false" default="false" />
<cc:attribute name="requiredMessage" type="String" required="false" default="required" />
</cc:interface>
<!-- IMPLEMENTATION -->
<cc:implementation>
<p:autoComplete id="#{cc.attrs.id}"
style="position: relative; padding-right:5px"
value="#{cc.attrs.person}"
var="personVar"
itemValue="#{personVar}"
itemLabel="#{personVar.fullFamiliarName}"
forceSelection="true"
completeMethod="#{personAutoComplete.byGeneralCriteria}"
converter="PersonConverter"
minQueryLength="3"
maxResults="50"
scrollHeight="400"
size="#{cc.attrs.size}"
required="#{cc.attrs.required}"
requiredMessage="#{cc.attrs.requiredMessage}"
title="enter users first name, last name or login" >
</p:autoComplete>
<h:message for="#{cc.attrs.id}" class="redError"/>
</cc:implementation>
and here's what code looks like now (that uses the custom component): 这是现在的代码(使用自定义组件):
<h:panelGrid id="newRoleAdminGrid" >
<my:personLookup id="newRoleAdminPerson"
person="#{roleList.newRoleAdminPerson}"
required="true" requiredMessage="#{propUtil.appShortName} Admin Name is required"/>
<h:message for="newRoleAdminPerson" class="redError"/>
<p:commandButton value="add" ajax="true"
update="roleAdminTable,newRoleAdminGrid"
id="addRoleAdminBtn"
actionListener="#{roleList.newRoleAdmin}"
style="margin:5px;"
icon="ui-icon-plus"/>
</h:panelGrid>
when i run it this way, the component works - if the user leaves it blank, or it doenst pass vaildation the primefaces border turns red, but the h:message never displays the actual error (requiredMessage or what is set in the PersonConverter) 当我以这种方式运行它时,该组件正常工作-如果用户将其留空,或者它通过传递验证,则Primefaces边框变为红色,但h:message永远不会显示实际错误(requiredMessage或PersonConverter中设置的内容)
i've tried quite a few different variations of this, such as setting the id only in the implementation or just in the my:personLookup, or both. 我已经尝试了很多不同的变化,例如仅在实现中或仅在my:personLookup中设置ID,或同时在两者中设置ID。
has anyone run across this before? 有人遇到过吗? am i doing or setting something incorrectly? 我在做什么或设置不正确吗? thank you for you time!! 谢谢您的时间!
Thanks to @partlov for the solution. 感谢@partlov提供解决方案。 here is my final code that displays the message correctly - 这是我的最终代码,可以正确显示该消息-
the component: 组件:
<!-- INTERFACE -->
<cc:interface>
<cc:attribute name="person" type="com.foo.bar.model.Person" required="true" />
<cc:attribute name="size" type="int" required="false" default="50" />
<cc:attribute name="required" type="boolean" required="false" default="false" />
<cc:attribute name="requiredMessage" type="String" required="false" default="required" />
</cc:interface>
<!-- IMPLEMENTATION -->
<cc:implementation>
<p:autoComplete id="personAutoComplete"
style="position: relative; padding-right:5px"
value="#{cc.attrs.person}"
var="personVar"
itemValue="#{personVar}"
itemLabel="#{personVar.fullFamiliarName}"
forceSelection="true"
completeMethod="#{personAutoComplete.byGeneralCriteria}"
converter="PersonConverter"
minQueryLength="3"
maxResults="50"
scrollHeight="400"
size="#{cc.attrs.size}"
required="#{cc.attrs.required}"
requiredMessage="#{cc.attrs.requiredMessage}"
title="enter users first name, last name or login" >
</p:autoComplete>
<h:message for="personAutoComplete" errorClass="redError" class="redError"/>
</cc:implementation>
calling in in my xhtml: 在我的xhtml中调用:
<my:personLookup id="newRoleAdminPerson"
person="#{roleList.newRoleAdminPerson}"
required="true" requiredMessage="Admin Name is required"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.