h:message 没有捕获消息。数据表验证,jsf
我对具有动态列的数据表的消息呈现有疑问。 我希望消息显示在数据表上方,但 ids 存在一些问题。
<h:form id="formId">
<!-- Here the jsf has to recognize id column_0 but it doesn't-->
<h:message styleClass="validationError" for="column_0" />
<rich:dataTable id="priorityTable" value="#{bean.matrix}" var="priority">
<rich:columns value="#{bean.ordersOrigin}"
var="ordersOrigin"
index="ind">
<f:facet name="header">
<h:outputText value="#{ordersOrigin}" />
</f:facet>
<!-- Here i have ids from column_0 to column_2-->
<h:inputText value="#{priority[ind].value}" id="column_#{ind}">
<f:validator validatorId="priorityValueValidator"/>
</h:inputText>
<!-- Line * -->
</rich:columns>
</rich:dataTable>
<br/>
<a4j:commandButton value="Apply" action="#{bean.apply}" reRender="formId"/>
</h:form>
问题是 h:message 没有捕获该消息。但如果我将相同的内容放入“Line *”中,一切正常,但看起来很丑。
看来真的很容易解决。你能帮我解决这个问题吗?
I have an issue with message rendering for dataTable with dynamic columns.
I want message to be shown above the datatable but there are some troubles with ids.
<h:form id="formId">
<!-- Here the jsf has to recognize id column_0 but it doesn't-->
<h:message styleClass="validationError" for="column_0" />
<rich:dataTable id="priorityTable" value="#{bean.matrix}" var="priority">
<rich:columns value="#{bean.ordersOrigin}"
var="ordersOrigin"
index="ind">
<f:facet name="header">
<h:outputText value="#{ordersOrigin}" />
</f:facet>
<!-- Here i have ids from column_0 to column_2-->
<h:inputText value="#{priority[ind].value}" id="column_#{ind}">
<f:validator validatorId="priorityValueValidator"/>
</h:inputText>
<!-- Line * -->
</rich:columns>
</rich:dataTable>
<br/>
<a4j:commandButton value="Apply" action="#{bean.apply}" reRender="formId"/>
</h:form>
The problem is that h:message doesn't catch the message. But if i put the same in 'Line *' everything works but looks very ugly.
It seems to be really easy to solve. Could you please help me with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您使用 a4j:commandButton,因此最好使用 richfaces 标签来发送消息。
Rich:消息非常适合您的情况。使用它;)
You use a4j:commandButton, so it's better to use the richfaces tag for message.
Rich:messages work fine for your case. Use it ;)
我认为问题的根本原因是 for="column_0" 和 id="column_#{ind}" 不匹配。
去检查一下。
更改
为
并查看它是否捕获任何消息。
如果出现任何消息,请记下它的 ID,以便与您的组件 ID 进行检查。
编辑:尽量不要在 id 标签中使用下划线“_”。
来自 JBOSS DOC
注意:
自 3.3.0GA 开始,需要为子组件明确定义“id”确保解码过程正常工作。如何为子组件定义唯一“id”的示例:
只有如上所示定义“id”,Ajax 在 onchange 事件之后才会按预期进行处理。
I think root cause of problem is for="column_0" and id="column_#{ind}" does not match.
To check it.
Change
to
and see if it catches any message.
If any message appears, note it's id to check against your components id.
EDIT: Try not to use under score "_" in your id tag.
FROM JBOSS DOC
Note:
Since 3.3.0GA requires explicit definition of "id" for children components to ensure that decode process works properly. The example of how you can define unique "id" for children component:
Only if "id" defined as shown above Ajax after onchange event will be processed as expected.
虽然这个问题很久以前就已经发布了,但我刚刚看到了一种解决方法,将 h:message 包装在 a4j:outputPanel 中并添加 ajaxRendered = true 标签属性。它在我的项目中完美运行。
根据我读到的帖子,原因是,对于 Ajax JSF 内容,当首次加载 jsf 时,它无法识别 h:message 组件。按照建议,a4j:outputPanel 会在组件树中插入不存在的子组件。关于ajaxRendered属性,使用它的原因是它设置outputPanel(及其所有子组件)在每次AJAX请求处理后使用新值呈现。
Although this question has being posted a long time ago, I just saw an workaround wrapping h:message within a4j:outputPanel and adding ajaxRendered = true tag attribute. It worked flawlessly in my project.
According to the post I read, the reason for that is, for a Ajax JSF content, when jsf is first loaded, it doesn't recognize the h:message component. Doing as suggested the a4j:outputPanel inserts non-present child components in the component tree. Regarding ajaxRendered attribute, the reason for use it is because it sets the outputPanel (with all its child components) to be rendered with the new values after each AJAX request processing.