Example #1
0
  public void afterComponentAttached(Component comp, Page page) {
    if (comp.getDesktop() != null) {
      // check if this component already binded
      Binder selfBinder = BinderUtil.getBinder(comp);
      if (selfBinder == null) {
        // check if parent exists any binder
        Binder parentBinder = BinderUtil.getBinder(comp, true);

        // post event to let the binder to handle binding later
        if (parentBinder != null && (parentBinder instanceof BinderImpl)) {
          // ZK-603, ZK-604, ZK-605
          // register internal ON_BIND_INIT event listener to delay the timing of init and loading
          // bindings
          comp.addEventListener(
              10000,
              BinderImpl.ON_BIND_INIT,
              new EventListener<Event>() {
                @Override
                public void onEvent(Event event) throws Exception {
                  final Component comp = event.getTarget();
                  comp.removeEventListener(BinderImpl.ON_BIND_INIT, this);
                  // ZK-611 have wrong binding on a removed treecell in a template
                  // if it was detached, ignore it
                  if (comp.getPage() == null) {
                    return;
                  }

                  final Binder innerBinder = BinderUtil.getBinder(comp);
                  if (innerBinder
                      != null) { // it was already handled by innerBinder, ignore it
                    return;
                  }

                  // ZK-1640 command send 2 wrong ViewModel
                  // check if there any parent binder again, don't use out-side parentBinder, it is
                  // not correct
                  Binder binder = BinderUtil.getBinder(comp, true);
                  if (binder == null) {
                    return;
                  }

                  if (binder instanceof AnnotateBinder) {
                    new AnnotateBinderHelper(binder).initComponentBindings(comp);
                  }

                  binder.loadComponent(comp, true);

                  // [Dennis,20120925], this code was added when fixing issue zk-739,
                  // but , inside binder.initComponentBindings, it shall do this already, I am not
                  // sure why.
                  if (comp.getAttribute(BinderImpl.VAR) != null)
                    BinderUtil.markHandling(comp, binder);
                }
              });
          // post ON_BIND_INIT event
          Events.postEvent(new Event(BinderImpl.ON_BIND_INIT, comp));
        }
      }
    }
  }
Example #2
0
 private static boolean isObsolete(AuRequest request) {
   final Component comp = request.getComponent();
   if (comp != null) {
     final Desktop dt = comp.getDesktop();
     return dt != null && dt != request.getDesktop();
     // Since 3.5.0, we allow a component to process events even
     // if it is detached (due to implementation of EventQueue)
   }
   return false;
 }
Example #3
0
  /** @param comp the component. Its desktop must be either null or the same as desktop. */
  public EventProcessor(Desktop desktop, Component comp, Event event) {
    if (desktop == null || comp == null || event == null)
      throw new IllegalArgumentException("null");

    final Desktop dt = comp.getDesktop();
    if (dt != null && desktop != dt)
      throw new IllegalStateException("Process events for another desktop? " + comp);

    _desktop = desktop;
    _comp = comp;
    _event = event;
  }
  @Override
  public void doAfterCompose(Component comp) throws Exception {
    super.doAfterCompose(comp);

    this.selectedObject = (User) comp.getDesktop().getAttribute("SELECTED_OBJECT");

    if (this.selectedObject != null) {
      this.username.setValue(this.selectedObject.getUsername());
      this.firstName.setValue(this.selectedObject.getFirstName());
      this.lastName.setValue(this.selectedObject.getLastName());
      this.password.setValue(this.selectedObject.getPassword());
      this.email.setValue(this.selectedObject.getEmail());
    }
  }
  @Override
  public void doAfterCompose(Component comp) throws Exception {
    super.doAfterCompose(comp);

    GenericValue userLogin =
        (GenericValue) comp.getDesktop().getSession().getAttribute("userLogin");

    GenericDelegator delegator = (GenericDelegator) userLogin.getDelegator();
    if (delegator == null) GenericDelegator.getGenericDelegator("default");

    GenericValue person = userLogin.getRelatedOne("Person");

    Map<String, Object> allFields = person.getAllFields();

    int count = 0;

    Collection<Component> leftHalf = new LinkedList<Component>();
    Collection<Component> rightHalf = new LinkedList<Component>();
    Label label = null;
    Label labelDesc = null;
    for (String key : allFields.keySet()) {

      Object obj = allFields.get(key);
      label = new Label();
      labelDesc = new Label();
      labelDesc.setValue(key);
      label.setValue(obj != null ? obj.toString() : "");
      Hbox hbox = new Hbox(new Component[] {labelDesc, label});
      if (count % 2 == 0) {
        leftHalf.add(hbox);
      } else {
        rightHalf.add(hbox);
      }
      count++;
    }

    Vbox vbox_1 = new org.zkoss.zul.Vbox(leftHalf.toArray(new Component[leftHalf.size()]));
    Vbox vbox_2 = new org.zkoss.zul.Vbox(rightHalf.toArray(new Component[rightHalf.size()]));
    comp.appendChild(vbox_1);
    comp.appendChild(vbox_2);
  }
Example #6
0
  public void afterComponentAttached(Component comp, Page page) {
    if (comp.getDesktop() != null) {
      // check if this component already binded
      Binder selfBinder = BinderUtil.getBinder(comp);
      if (selfBinder == null) {
        // check if parent exists any binder
        Binder parentBinder = BinderUtil.getBinder(comp, true);

        // post event to let the binder to handle binding later
        if (parentBinder != null && (parentBinder instanceof BinderImpl)) {
          // ZK-603, ZK-604, ZK-605
          // register internal ON_BIND_INIT event listener to delay the timing of init and loading
          // bindings
          comp.addEventListener(
              10000,
              BinderImpl.ON_BIND_INIT,
              new EventListener<Event>() {

                public void onEvent(Event event) throws Exception {
                  final Component comp = event.getTarget();
                  comp.removeEventListener(BinderImpl.ON_BIND_INIT, this);
                  // ZK-611 have wrong binding on a removed treecell in a template
                  // if it was detached, ignore it
                  if (comp.getPage() == null) {
                    return;
                  }

                  final Binder innerBinder = BinderUtil.getBinder(comp);
                  if (innerBinder
                      != null) { // it was already handled by innerBinder, ignore it
                    return;
                  }

                  // ZK-1640 command send 2 wrong ViewModel
                  // check if there any parent binder again, don't use out-side parentBinder, it is
                  // not correct
                  Binder binder = BinderUtil.getBinder(comp, true);
                  if (binder == null) {
                    return;
                  }

                  // ZK-1699 Performance issue ZK-Bind getters are called multiple times
                  // check if it is handling, if yes then skip to evaluate it.
                  if (getExtension().isLifeCycleHandling(comp)) {
                    return;
                  }

                  if (binder instanceof AnnotateBinder) {
                    new AnnotateBinderHelper(binder).initComponentBindings(comp);
                  }

                  // ZK-1699, mark the comp and it's children are handling.
                  // note:mark handing before load, because of some load will change(create or
                  // reset) the children structure
                  // (consider F00769.zul if you bind to tree open , it will load children in
                  // loadComponent)
                  getExtension().markLifeCycleHandling(comp);

                  binder.loadComponent(comp, true);

                  // [Dennis,20120925], this code was added when fixing issue zk-739,
                  // but , inside binder.initComponentBindings, it shall do this already, I am not
                  // sure why.
                  if (comp.getAttribute(BinderImpl.VAR) != null)
                    BinderUtil.markHandling(comp, binder);
                }
              });
          // post ON_BIND_INIT event
          Events.postEvent(new Event(BinderImpl.ON_BIND_INIT, comp));
        }
      }
    }
  }