简体   繁体   English

为什么在使用Ajax时会多次渲染我的JSF 2.0定制组件?

[英]Why is my JSF 2.0 custom component rendered several times when using ajax?

I have created a custom jsf 2.0 component for a special userinput widget. 我为特殊的userinput小部件创建了一个自定义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>

The component contains some standard input components and makes use of jsf 2.0 ajax behavior. 该组件包含一些标准输入组件,并利用jsf 2.0 ajax行为。 Everything in my component works fine, and I use it multiple times in my application. 组件中的所有内容均正常运行,并且在应用程序中多次使用了它。

Now I run into a strange problem when I am using the component with af:ajax region. 现在,当我将组件与af: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>

The stange thing now is that when the command button was clicked and the ajax request was fired my custom component appears 3 times in my form. 现在的问题是,当单击命令按钮并且触发了ajax请求时,我的自定义组件在我的表单中出现了3次。

Can anybody explain Why this happens? 谁能解释为什么会这样?

I found the reason for the strange behavior. 我发现了这种奇怪行为的原因。 It was a JavaScript problem. 这是一个JavaScript问题。 My component contains jquery scripts to hide some parts of the component. 我的组件包含jquery脚本以隐藏组件的某些部分。 After the ajax call was completed the jquery scripts was not triggered so the layout of the component was corrupted. 在ajax调用完成之后,没有触发jquery脚本,因此组件的布局已损坏。 So it was a javaScript problem and not a problem with my jsf component as I thought first. 因此,这是一个JavaScript问题,而不是我首先想到的jsf组件问题。 Sorry for the wrong question. 对不起,错误的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM