< h:消息>无法在< ui:repeat>中找到组件 [英] <h:message> unable to find component in <ui:repeat>

查看:48
本文介绍了< h:消息>无法在< ui:repeat>中找到组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用< ui:repeat>建立表格标签,并且它的长度是动态的.每行都有一个< h:inputText>场地.提交表单后,它将表单中的值设置为哈希表.除了验证之外,其他所有功能都很好.我需要告诉< h:message>它使用"for"属性属于哪个输入.我试图根据用于创建行的项目的名称为每行创建一个唯一的ID.但是< h:message>当我提交无效的输入时,标记保持为空,并且在服务器日志(JBoss 7.1)上获得以下输出:

I am building a table using a <ui:repeat> tag, and its length is dynamic. Each row has a <h:inputText> field. When the form is submitted, it sets the values from the form into a hashmap. That all works great, except for the validation. I need to tell the <h:message> which input it belongs to using the "for" attribute. I've tried to create a unique ID per row, based on the name of the item being used to create the row. But the <h:message> tag remains empty when I submit an invalid input, and I get the following output on the servers log (JBoss 7.1):

[javax.enterprise.resource.webcontainer.jsf.renderkit]
Unable to find component with ID nTAS in view.

这是XHTML:

<ui:repeat var="item" ...>
...
<h:inputText value="#{bean.chosenItems[item.name]}" id="n#{item.name}" >
    <f:validateLongRange minimum="0" maximum="10" />
</h:inputText>
<h:message for="n#{item.name}" />
...
</ui:repeat>

为了至少在浏览器中获得某种错误消息,我还在页面顶部附近添加了此消息,并且它的工作原理是:

In order to at least get some kind of error message in the browser, I also added this near the top of my page, and it works:

<h:messages styleClass="error" />

它显示以下消息:

j_idt13:j_idt17:1:n: Validation Error: Value is not of the correct type.

这表明问题的一部分,因为ID是消息开头的那个奇怪的代码,并且以"n"开头,但不包含项目的名称.如果我在浏览器中查看源代码,则ID实际上是: id ="j_idt13:j_idt17:1:nTAS"

And that kind of shows part of the problem, since the ID is that strange code at the start of the message, and it starts with "n", but doesn't contain the item's name. If I look at the source in the browser, the ID is actually: id="j_idt13:j_idt17:1:nTAS"

如果我查看表外的其他组件,它们也具有明显由JSF生成的隐式ID.

If I look at other components, outside of the table, they also have cryptic IDs, apparently generated by JSF.

真正奇怪的是,当我第二次输入"asdf"并重新提交表单时,它将在bean上调用action方法,而不是在验证阶段再次失败!怎么可能?!

And what is really weird is that when I input "asdf" a second time, and re-submit the form, it then calls the action method on the bean, instead of again failing during validation phase!! How can that be?!

感谢您的任何提示,约翰

Thanks for any hints, John

推荐答案

您不能使用el表达式动态创建ID.如果您不为组件分配ID,则jsf确实会生成隐式" ID.

You cannot create IDs dynamically with el expressions. And the "cryptic" IDs are indeed generated by jsf if you don't assign an ID to a component.

但是您不必关心 ui:repeat 中ID的唯一性.JSF为您做到这一点(生成的ID字符串中的"1"是您重复的组件的计数器).只需给您的输入字段一个固定" ID,并在您的h:message:

But you don't need to care for the uniqueness of your ids in ui:repeat. JSF does it for you (the "1" in the generated id string is the counter for your repeated component). Just give your input field a "fixed" id and reference it in your h:message:

<h:inputText value="#{bean.chosenItems[item.name]}" id="myID" >
    <f:validateLongRange minimum="0" maximum="10" />
</h:inputText>
<h:message for="myID" />

这篇关于&lt; h:消息&gt;无法在&lt; ui:repeat&gt;中找到组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆