当前位置: 首页 > 知识库问答 >
问题:

Wicket组件不会通过AJAX刷新

潘秦斩
2023-03-14

我有一个Wicket页面,其中包含一些应该通过Ajax更新的组件。我有以下AjaxBehavior:

private class MyAjaxBehavior extends AbstractDefaultAjaxBehavior {

        @Override
        public void renderHead(IHeaderResponse response) {
            super.renderHead(response);
            response.renderOnLoadJavascript("wicketAjaxPost(\"" + getCallbackUrl() + "\")");
        }

        @Override
        public void onConfigure(Component component) {
            firstComponent.setOutputMarkupId(true);
            secondComponent.setOutputMarkupId(true);
        }

        @Override
        protected void respond(AjaxRequestTarget target) {
            firstComponent.replaceWith(createFirstComponent());
            target.addComponent(firstComponent);

            secondComponent.replaceWith(createSecondComponent());
            target.addComponent(secondComponent);
        }
    }
Page
- fragment1
  - fragment1-1
    - firstComponent
- secondComponent
        // Initialize temporary variables
        final Page page = component.findParent(Page.class);
        if (page == null)
        {
            // dont throw an exception but just ignore this component, somehow
            // it got
            // removed from the page.
            // throw new IllegalStateException(
            // "Ajax request attempted on a component that is not associated
            // with a Page");
            LOG.debug("component: " + component + " with markupid: " + markupId +
                " not rendered because it was already removed from page");
            return;
        }
<div>
    <div id="generated">new component is added here</div>
    <table>
        ...
        <tr>old component</tr>
    </table>
</div>
<div>
    <table class="summary" style="width: 100%">
        <tr>
            <div wicket:id="firstComponent" />
        </tr>
    </table>
</div>

...

<wicket:fragment wicket:id="firstComponentFragment">
    <th>title</th>
    <td><span wicket:id="someText"></span></td>
</wicket:fragment>

共有2个答案

汪弘毅
2023-03-14
热门标签
艾泽语
2023-03-14
相关问题
 类似资料:
  • 希望你能帮我解决这个问题,因为它已经困扰我几天了。 我对页面的标记:[表] 我的自定义DataTable扩展Java代码(扩展以确保添加了所有outputMarkUp):@override protected void onInitialize(){super.onInitialize();this.addtopToolbar(新的NavigationToolbar(this));this.add

  • 问题内容: 我将用户输入(在这种情况下,只是数量和产品代码)传递给php脚本,以通过ajax存储到会话数组中。我希望,每次用户单击“提交”并进行ajax调用时,数量和产品代码都会添加到会话数组中。但是现在发生的是,每次它更新会话中的现有数据时。因此,仅存在一对数据。 这是我的ajax脚本: 我的PHP sendToCart.php 问题答案: 每次进行ajax调用时,您都会覆盖会话变量。 您需要读

  • 问题内容: 我有一个带有自定义标签的组件。该组件包含(显示标签标题)和(关闭按钮)。当我在停止接收鼠标事件的站点中更改文本时,如果直接单击标签,则无法再选择该选项卡,而如果单击标签周围,则可以选择该选项卡。有任何想法吗? 一段代码: 问题答案: 问题与我进行更多挖掘之后在此处发布的问题有关:setToolTipText消耗鼠标事件的解决方法?

  • 问题内容: 在我的Ajax代码中,我正在向go lang api发送一个关联数组,但是go lang不会接收任何数组。为什么? 为什么这个Ajax不会将数组发送到Go API?在下面的mvc结构中,我想要接收此数据: 问题答案: 您不能直接将数组从客户端发送到服务器,因为数组定义在两侧可能不相同。 有两种解决方法: 一个。您可以在clinet中将数组转换为json字符串,然后将其作为字符串参数发送

  • 问题内容: 我建立了一个复合组件,看起来像这样: 组件正确显示当前标签。 现在,当执行该动作时,什么也不会发生。但是,当我将Postfix添加到组件中的ID时,它可以正常工作(请参见下文)。 并使用后缀在render中定义ID: 有人可以向我解释为什么仅当我在ID中添加后缀时才起作用吗? 问题答案: 这个问题实际上有两个方面。 第一个问题是,实际上指定复合部件的ID 本身 的。默认情况下,HTML

  • 当我点击按钮时: -迭代所有tr并将其所有输入的名称收集到数组(这已经完成了) - 我还从输入和触发名称的两个文本中获取数据 - 通过ajax将所有(一个数组和两个文本)发送到asp.net.cs(不起作用)