Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-3831

initViewModel fails during createComponents on detached parent

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Fixed
    • Affects Version/s: 8.0.4.2, 8.5.0
    • Fix Version/s: 8.5.1
    • Component/s: Databind 2
    • Security Level: Jimmy
    • Labels:
      None

      Description

      Steps to Reproduce

      run the attached example
      vminit-aftercompose.zul

      Current Result

      Exception:

      org.zkoss.zk.ui.UiException: can't find Page to resolve a view model class :'MyVm' at [file:/D:/workspace/projects_idea/support/zksupport8/src/main/webapp/potential/5193-vminit-aftercompose/mvvminc.zul, line:7, nearby column: 43]
      	at org.zkoss.bind.BindComposer.initViewModel(BindComposer.java:254)
      	at org.zkoss.bind.BindComposer.doBeforeComposeChildren(BindComposer.java:150)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.doBeforeComposeChildren(UiEngineImpl.java:997)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:937)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:895)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:777)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:842)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:797)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:740)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.createComponents(UiEngineImpl.java:1150)
      	at org.zkoss.zk.ui.impl.AbstractExecution.createComponents0(AbstractExecution.java:346)
      	at org.zkoss.zk.ui.impl.AbstractExecution.createComponents(AbstractExecution.java:307)
      	at org.zkoss.zk.ui.Executions.createComponents(Executions.java:176)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at bsh.Reflect.invokeMethod(Reflect.java:131)
      	at bsh.Reflect.invokeStaticMethod(Reflect.java:95)
      	at bsh.Name.invokeMethod(Name.java:868)
      	at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:69)
      	at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:96)
      	at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:41)
      	at bsh.BSHBlock.evalBlock(BSHBlock.java:125)
      	at bsh.BSHBlock.eval(BSHBlock.java:75)
      	at bsh.BshMethod.invokeImpl(BshMethod.java:356)
      	at bsh.BshMethod.invoke(BshMethod.java:252)
      	at bsh.BshMethod.invoke(BshMethod.java:180)
      	at bsh.This.invokeMethod(This.java:248)
      	at MyComposer.doAfterCompose(BeanShell Generated via ASM (www.objectweb.org))
      	at org.zkoss.zk.ui.impl.UiEngineImpl.doAfterCompose(UiEngineImpl.java:617)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild0(UiEngineImpl.java:948)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:895)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:777)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreateChild(UiEngineImpl.java:842)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate0(UiEngineImpl.java:797)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execCreate(UiEngineImpl.java:740)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage0(UiEngineImpl.java:461)
      	at org.zkoss.zk.ui.impl.UiEngineImpl.execNewPage(UiEngineImpl.java:369)
      	at org.zkoss.zk.ui.http.DHtmlLayoutServlet.process(DHtmlLayoutServlet.java:211)
      	at org.zkoss.zk.ui.http.DHtmlLayoutServlet.doGet(DHtmlLayoutServlet.java:137)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
      ...
      

      Expected Result

      1. no exception thrown
      2. view model initialization when parent is added to page

      Debug Info

      creating components on a non-attached component causes the issue in initViewModel.

      Workaround

      attaching the newDiv before calling createComponents avoids the problem

      	public void doAfterCompose(Component comp) {
      		Div newDiv = new Div();
      		comp.appendChild(newDiv); //append the newDiv before creating children using MVVM viewModels
      		Executions.createComponents("mvvminc.zul", newDiv, null);
      	}
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                klyvechen klyvechen
                Reporter:
                cor3000 cor3000
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 1 day
                  1d
                  Remaining:
                  Remaining Estimate - 1 day
                  1d
                  Logged:
                  Time Spent - Not Specified
                  Not Specified