-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have 2 page and each one have its controller i am including subnavigation.zul in index.zul and show me this error "Only one child is allowed"
this is the code:
index.zul
<?xml version="1.0" encoding="UTF-8"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <div id="root" align="center" apply="${index}" xmlns="http://www.zkoss.org/2005/zul" > <div width="1200px" height="800px" style="border: 1px blue double"> <borderlayout > <north> <toolbar id="mainmenu"></toolbar> </north> <center flex="true" > <include id="submenu" height="100%" /> </center> <south style="border: 1px orange double" size="10%"> <div>AQUI VA LOS PIES</div> </south> </borderlayout> </div> </div>
subnavegation.zul
<?xml version="1.0" encoding="UTF-8"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?> <?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <div id="subpages" height="100%" apply="${content}" xmlns="http://www.zkoss.org/2005/zul"> <borderlayout > <west title="SubMenu" size="200px" splittable="tue" flex="true" collapsible="true" > <toolbar orient="vertical" id="menupage"></toolbar> </west> <center > este s el center <include id="contenido" height="100%" /> </center> </borderlayout> </div>
indexController
@Component(value = "index") @Scope(value = "prototype") public class IndexController extends GenericForwardComposer { Toolbar mainmenu; Toolbarbutton boton; Include submenu; MakeMenu mm; List<Menu> menus; public IndexController() { menus = mm.getAllmenus(); } @Override public void doAfterCompose(org.zkoss.zk.ui.Component comp) throws Exception { super.doAfterCompose(comp); for (Menu menu : menus) { boton = new Toolbarbutton(menu.getNombreMenu()); boton.setImage(menu.getImg()); boton.setAttribute("menu", menu); boton.setParent(mainmenu); boton.addEventListener("onClick", new EventListener() { public void onEvent(Event event) throws Exception { loadSubmenu((Menu)boton.getAttribute("menu")); } }); } } public void loadSubmenu(Menu menu) { submenu.setAttribute("menu", menu); submenu.setSrc("WEB-INF/pagenavegacion/subnavegation.zul"); } }
subnavigationCOntroller
@Component(value = "content") @Scope(value = "prototype") public class SubNavegation extends GenericForwardComposer { Menu menuPrinc; Toolbar menupage; Toolbarbutton boton; Include contenido; @Override public void doAfterCompose(org.zkoss.zk.ui.Component comp) throws Exception { super.doAfterCompose(comp); menuPrinc = (Menu) requestScope.get("menu"); List<Menu> menus = menuPrinc.getSubmenus(); for (Menu menu : menus) { boton.setImage(menu.getImg()); boton.setLabel(menu.getNombreMenu()); boton.setAttribute("menu", menu); boton.addEventListener("onClick", new EventListener() { public void onEvent(Event event) throws Exception { navega((Menu) boton.getAttribute("menu")); } }); boton.setParent(menupage); } } public void navega(Menu menu) { contenido.setSrc(menu.getSrc()); } }
This is where your problem is:
<center> este s el center <include id="contenido" height="100%" /> </center>
You have the text "este s el center" and an include component inside a center component. The text is converted into a label component, so the result will be the same as this:
<center> <label value="este s el center" /> <include id="contenido" height="100%" /> </center>
As you can see, center has two child elements. By design, center elements support only a single child component. If you want to preserve the label, you'll have to wrap those components into a single parent component. For example you can use a div:
<center> <div> este s el center <include id="contenido" height="100%" /> </div> </center>
Your both ZUL files are using AnnotateDataBinderInit which by default covers the whole page. So you cannot have two on the same ZK page.
And even though you are using include components, all your components will end up in one ZK page.
You can fix this by setting AnnotateDataBinderInits to handle only specific components on your ZUL pages. Your both ZUL pages already have a top-level component with an id so this is quite simple to do:
index.zul:
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" root="root"?>
subnavegation.zul:
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" root="subnavegation"?>
Hi gekkio
In my case, i am not using include to show the center area, i am using as follows
String zulFilePathName;
Borderlayout bl = (Borderlayout) Path.getComponent("/main1/mainlayout1");
/* get an instance of the searched CENTER layout area */
Center center = bl.getCenter();
/* clear the center child comps */
center.getChildren().clear();
Messagebox.show("inside" + event.getTarget().getId());
zulFilePathName = event.getTarget().getId() + ".zul";
/* create the page and put it in the center layout area */
Executions.createComponents(zulFilePathName, center, null);
But if the target zul file contains style tag, it showing the same error. If i remove the style tag, then it is fine.
Why this
hI Stephan
Problem SOLVED. I did'nt know that i can put style tag inside the window tag.
Thanks a lot
hi have a problem of "Only one child is allowed" kind. But using jsp tags. I have only one page with this code
<%-- Document : index Created on : 24/08/2012, 11:20:36 AM Author : jason --%> <%@page import="java.sql.Connection"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@taglib prefix="z" uri="http://www.zkoss.org/jsp/zul" %> <%@page contentType="text/html" pageEncoding="UTF-8"%> <% String resultado = (String)session.getAttribute("resultado"); Connection connection = (Connection)session.getAttribute("connection") ; int timeout =0; boolean conexionDBValida = false; if(connection!=null){conexionDBValida = true;} %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <% request.setAttribute(org.zkoss.zk.ui.sys.Attributes.NO_CACHE, Boolean.TRUE); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Pragma" content="no-cache" /> <meta http-equiv="Expires" content="-1" /> <title>consultas</title> </head> <body> <div> <p>Estado de la conexion a base de datos: <%= conexionDBValida?"conectado":"desconectado" %> </p> </div> <z:page> <z:window border="normal" width="100%" height="100%"> <z:borderlayout> <z:center title="Consultas" border="0"> <div id="PrdoDiv"> </div> </z:center> <z:east title="Conexion" size="30%" splittable="true" collapsible="true"> //here is the org.zkoss.zk.ui.UiException: Only one child is allowed: <East wEEP4> <div vflex="1" style="background:#D9E5EF;"> <form action="conexion?accion=conexionNueva" method="post"> <z:grid hflex="1"> <z:auxhead> <z:auxheader colspan="2" label="Formulario de conexion" style="font-size:16px" image="../images/picture.png"/> </z:auxhead> <z:columns/> <z:rows> <z:row> servidor: <z:textbox id="servidor" name="servidor" hflex="1" constraint="no empty" ></z:textbox> </z:row> <z:row> base de datos: <z:textbox id="basedatos" name="basedatos" hflex="1" constraint="no empty" ></z:textbox> </z:row> <z:row > usuario <z:textbox id="usuario" name="usuario" hflex="1" constraint="no empty" ></z:textbox> </z:row> <z:row spans="2" align="center" > password <z:textbox id="password" name="password" hflex="1" constraint="no empty" ></z:textbox> </z:row> <z:row spans="2" align="right"> <z:hlayout> <z:button id="resetButton" label="Reset" /> <z:button id="submitButton" type="submit" label="Submit" disabled="true"/> </z:hlayout> </z:row> </z:rows> </z:grid> </form> </div> </z:east> <z:south title="Resultado" size="250px" border="0" splittable="true" collapsible="true" style="overflow:scroll"> <div vflex="1"> </div> </z:south> </z:borderlayout> </z:window> </z:page> </body> </html>
can you help me please ?
Asked: 2011-04-12 13:04:54 +0800
Seen: 1,885 times
Last updated: Sep 20 '12