开发者

Error in composite component

开发者 https://www.devze.com 2023-02-22 04:11 出处:网络
i have created an class com.test.test.But public class But extends Bandbox { private Label mc_who; public But() {

i have created an class com.test.test.But

public class But extends Bandbox {
private Label mc_who;
public But() {
Executions.createComponents("/WEB-INF/username.zul", this, null);
Components.wireVariables(this, this, '$', true, true);
Components.addForwards(this, this, '$');
}
public String getWho() {
return mc_who.getValue();
}
public void setWho(String who) {
mc_who.setValue(who);
}

}

and an username.zul

<zk>
<label id="mc_who"></label>
</zk>

and index.zul

<window id="test" >
<bandbox>
<bandpopup>
<username who="Joe"/>
<username who="Hellen"/>
</bandpopup>
</bandbox>

</wind开发者_JAVA百科ow>

and i am getting this exception

org.zkoss.zk.ui.UiException: Unsupported parent for row: <Bandpopup g4HQ2>
org.zkoss.zul.Row.beforeParentChanged(Row.java:264)
org.zkoss.zk.ui.AbstractComponent.setParent(AbstractComponent.java:959)
org.zkoss.zk.ui.impl.AbstractUiFactory.newComponent(AbstractUiFactory.java:91)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:714)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:685)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:629)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:596)
org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.ja


Your example is not complete since I don't see row (and grid) in your sample code, while the exception said there is one. Please make a sample that can reproduce the issue.


I went through several iterations as well, and found that the most reliable way is to use the div tag as follows:

<zk>
<div>
<label id="mc_who"></label>
</div>
</zk>

This is an example of the component being used:

<window id="test" >
<bandbox>
<bandpopup>
<username who="Joe"/>
<username who="Hellen"/>
</bandpopup>
</bandbox>

</window>

And the source code:

package com.pontusnetworks.zkwidgets;

import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.IdSpace;
import org.zkoss.zk.ui.select.Selectors;
import org.zkoss.zk.ui.select.annotation.Wire;
import org.zkoss.zul.Div;
import org.zkoss.zul.Row;
import org.zkoss.zul.Textbox;

public class Username extends Div implements IdSpace {
   @Wire
   private Textbox mc_who; //will be wired when Components.wireVariables is called

   public Username() {
       //1. Render the template
       Executions.createComponents("/composite/username.zul", this, null);

       //2. Wire variables, components and event listeners (optional)
       Selectors.wireVariables(this, this, null);
       Selectors.wireComponents(this, this, false);
       Selectors.wireEventListeners(this, this);
   }
   public String getWho() {
       return mc_who.getValue();
   }
   public void setWho(String who) {
       mc_who.setValue(who);
   }
   //public void onOK() {..} //Add event listeners if required, and wired by Components.addForwards
}
0

精彩评论

暂无评论...
验证码 换一张
取 消