/** Creates a shadow element based on this info (never null). * It is the same as newInstance(page, null). * * <p>If the implementation class doesn't have any EL expression, * or its EL expression doesn't have reference to the self variable, * the result is the same. * * <p>This method is preserved for backward compatibility. * It is better to use {@link #newInstance(Page, Component)}. */ public Component newInstance(Page page) { return newInstance(page, null); }
public Component newComponent(Page page, Component parent, ShadowInfo compInfo, Component insertBefore) { final Component comp = compInfo.newInstance(page, parent); Utils.setShadowInfo(comp, compInfo); Object currentInfo = ShadowElementsCtrl.getCurrentInfo(); if (currentInfo instanceof ShadowElement && ((ShadowElementCtrl) currentInfo).getShadowHostIfAny() == parent) { ((Component) currentInfo).insertBefore(comp, insertBefore); } else if (parent instanceof ShadowElement) { parent.insertBefore(comp, insertBefore); } else if (parent != null) { ((ShadowElementCtrl) comp).setShadowHost(parent, insertBefore); } else { //ZK-2955: Shadow element could be used in root element <zk> Component emptyRoot = null; String clsnm = Library.getProperty("org.zkoss.zk.ui.ShadowDefaultHost.class"); if (clsnm != null) { try { emptyRoot = (Component) Classes.newInstanceByThread(clsnm); emptyRoot.setPage(page); ((ShadowElementCtrl) comp).setShadowHost(emptyRoot, insertBefore); } catch (Throwable ex) { log.warn("Unable to load " + clsnm, ex); } } } if (comp instanceof BeforeCompose) ((BeforeCompose) comp).beforeCompose(); compInfo.applyProperties(comp); //include comp's definition Utils.setShadowInfo(comp, null); return comp; }