【问题标题】:Why is my JSF 2.0 custom component rendered several times when using ajax?为什么我的 JSF 2.0 自定义组件在使用 ajax 时会渲染多次?
【发布时间】:2013-07-31 13:45:09
【问题描述】:

我为特殊的用户输入小部件创建了一个自定义 jsf 2.0 组件。

<cc:interface>
    <cc:attribute name="value"></cc:attribute>
    <cc:attribute name="editmode" default="true" type="java.lang.Boolean"></cc:attribute>
</cc:interface>

<cc:implementation>
 ....
</cc:implementation>

该组件包含一些标准输入组件并利用 jsf 2.0 ajax 行为。 我的组件中的一切工作正常,我在我的应用程序中多次使用它。

现在我在使用带有 f:ajax 区域的组件时遇到了一个奇怪的问题。

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:marty="http://java.sun.com/jsf/composite/marty"
    xmlns:h="http://java.sun.com/jsf/html">
    <!-- Ajax region -->
    <f:ajax>
        <h:panelGroup id="timesheet_panel" binding="#{timesheetListComponent}">

        .....
    <!-- my custom component ->
        <marty:userInput value="#{workitem.item['nammanager']}" editmode="true" />
        ....
       <h:commandButton value="#{message.search}"
            action="/pages/workitems/workitem"
            actionListener="#{timesheetController.reset}">
            <f:ajax render="timesheet_panel" onevent="updateTimesheetPanel" />
       </h:commandButton>
     ....
     </f:ajax>
</ui:composition>

现在奇怪的是,当单击命令按钮并触发 ajax 请求时,我的自定义组件在我的表单中出现了 3 次。

谁能解释为什么会这样?

【问题讨论】:

    标签: ajax jsf jsf-2 custom-component


    【解决方案1】:

    我找到了奇怪行为的原因。这是一个 JavaScript 问题。 我的组件包含 jquery 脚本来隐藏组件的某些部分。 ajax 调用完成后,没有触发 jquery 脚本,因此组件的布局已损坏。所以这是一个 javaScript 问题,而不是我最初认为的 jsf 组件的问题。抱歉问错了问题。

    【讨论】:

      猜你喜欢
      • 2011-12-12
      • 2011-03-06
      • 1970-01-01
      • 2023-03-25
      • 2020-09-07
      • 2022-10-02
      • 1970-01-01
      • 2021-01-06
      相关资源
      最近更新 更多