【问题标题】:h:message doesn't catch message. validation for dataTable, jsfh:message 不捕获消息。验证数据表,jsf
【发布时间】:2011-04-19 08:23:04
【问题描述】:

我对带有动态列的 dataTable 的消息呈现有疑问。 我希望消息显示在数据表上方,但 id 存在一些问题。

<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 *”中添加相同的内容,一切正常,但看起来很丑。

这似乎很容易解决。你能帮我解决这个问题吗?

【问题讨论】:

  • 你用rich:messages标签试过了吗?
  • 是的,我做到了,它工作正常。但我认为使用 h:messages 并不是很好的实践,因为它会捕获页面中的所有消息,并且需要添加许多额外的检查。我只是认为使用 h:message 可能会错过一些东西。

标签: jsf richfaces ajax4jsf


【解决方案1】:

你使用a4j:commandButton,所以消息最好使用richfaces标签。

Rich:messages 适用于您的情况。使用它;)

【讨论】:

  • 好的,谢谢。我更改为消息并添加了额外的检查。它有效:)
【解决方案2】:

我认为问题的根本原因是 for="column_0" 和 id="column_#{ind}" 不匹配。

检查一下。

改变

   <h:message  styleClass="validationError"  for="column_0" />

   <h:messages/>

看看它是否捕捉到任何消息。

如果出现任何消​​息,请注意它的 id 以检查您的组件 id。

编辑:尽量不要在你的 id 标签中使用 under score "_"。

来自 JBOSS 文档

注意:

由于 3.3.0GA 需要为子组件明确定义“id”,以确保解码过程正常工作。如何为子组件定义唯一“id”的示例:

<rich:columns value="#{bean.columns}" var="col" index="ind" ... >

        <h:inputText id="input#{ind}" value="">

                <a4j:support id="support#{ind}" event="onchange" reRender="someId" />

        </h:inputText>

</rich:columns> 

仅当“id”定义如上图所示时,onchange 事件后的 Ajax 才会按预期处理。

【讨论】:

  • 我已经检查过了,它们匹配。当我确定一切都适用于 column_0 时,我会做一般情况。
【解决方案3】:

虽然这个问题很久以前就已经发布了,但我刚刚看到一个解决方法,将 h:message 包装在 a4j:outputPanel 中并添加 ajaxRendered = true 标记属性。它在我的项目中完美运行。

根据我阅读的帖子,原因是,对于一个 Ajax JSF 内容,当第一次加载 jsf 时,它无法识别 h:message 组件。按照建议做 a4j:outputPanel 在组件树中插入不存在的子组件。关于 ajaxRendered 属性,使用它的原因是因为它设置 outputPanel(及其所有子组件)在每次 AJAX 请求处理后以新值呈现。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多