java - Wicket 口更换 "only on component added to parent"

标签 java wicket

我从 Wicket 1.4.11 阅读时遇到异常:

2010-11-03 17:44:51,971 [http-8080-1] ERROR org.apache.wicket.RequestCycle - Method onFormSubmitted of interface org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = customer]] threw an exception
org.apache.wicket.WicketRuntimeException: Method onFormSubmitted of interface
org.apache.wicket.markup.html.form.IFormSubmitListener targeted at component [MarkupContainer [Component id = customer]] threw an exception at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:193)
...
Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...
Caused by: java.lang.IllegalStateException: This method can only be called on a component that has already been added to its parent.
at org.apache.wicket.Component.replaceWith(Component.java:2804)
at no.magge.iumb.web.crm.customers.PrivateCustomerTab$1.onSubmit(PrivateCustomerTab.java:34)
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1565)

当我在选项卡面板中的选项卡面板中单击面板中表单的 cancel_btn 时,就会发生这种情况...以下是 cancel_btn 的代码:

public class PrivateCustomerTab extends Panel {

 private static final long serialVersionUID = 16L;

 protected Panel getCurrentPanel() {
  return this;
 }

 public PrivateCustomerTab(String id, long customerId, final Panel backPanel) {
  super(id);

  final PrivateCustomerForm form = new PrivateCustomerForm("customer", customerId) {
   private static final long serialVersionUID = 4L;
   @Override
   protected void onSubmit() {
    System.out.println("\n\n(formsubmit) HELLO THERE MY PARENT IS: " + getParent() + "\n\n");
    if (customerId!=0) {
     PrivateCustomerTab.this.replaceWith(new PrivateCustomerTab("panel", customerId, backPanel));
    }
   }
  };
  add(form);

  Button cancelButton = new Button("cancel_btn", new ResourceModel("cancel")) {
   private static final long serialVersionUID = 18L;
   @Override
   public void onSubmit() {
    System.out.println("\n\n(cancelsubmit) HELLO THERE MY PARENT IS: " + getParent() + "\n\n");
    if (backPanel!=null) {
     // PrivateCustomerTab.this.replace(backPanel);
     getCurrentPanel().replaceWith(new CustomerListTab("panel"));

    }
   }
  };
  cancelButton.setVisible(backPanel!=null);
  form.add(cancelButton);
        }
}

我一直在尝试各种方法来获取当前面板,即我想要替换的面板。一种方法是使用 getCurrentPanel() 方法,该方法仅从面板类返回 this。另一种方法是执行 PrivateCustomerTab.this.replaceWith(...),我也尝试过 getParent().getParent().replaceWith(...)。这些都向我传达了这样的信息:我无法替换未添加到其父级的内容。

我想我一定误解了这里的一些关键概念。也许在我的面板添加到其父面板之前处理了表单,这意味着我无法替换 cancel_btnonSubmit() 中的面板?

我尝试用谷歌搜索我的方式,并在我的Wicket in Action副本中寻找相关内容。请帮助我理解...谢谢!

最佳答案

这并不是真正要找到合适的面板。 看来没问题。 所有三个调用似乎都找到了同一个面板。

它是关于面板本身被添加到的。要将其自身替换为 els ,组件需要询问父组件是否将其添加到其中。 然后它要求其父组件忘记自己并选择给定的组件作为子组件。

所以 wicket 基本上提示面板没有添加到任何组件中。

组件层次结构是否同时发生变化?

关于java - Wicket 口更换 "only on component added to parent",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4089679/

相关文章:

java - 如何用Java创建平铺 map ?

java - 使用 Java Conf 而不是 xml 配置 Spring Wicket

forms - 禁用 Wicket 口中的嵌套表单验证

javax.ejb.EJBException : javax. ejb.CreateException:无法创建无状态 EJB junit

java - Maven编译找不到src/main/resources目录

java - Spring Reactive Router Path - 带排除的通配符

stream - wicket:如何从数据库中流式传输资源

java - Apache Wicket 与 Apache Click

java - Wicket - 当值为空时提交按钮功能出现问题

java - 如何用两种颜色填充 JavaFX 球体