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

Provide some utile APIs to update IComponent Tree

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Normal Normal
    • 10.0.0
    • 10.0.0
    • None
    • Security Level: Jimmy

      User Story

      As a developer, I need to use features from UiAgent.getCurrent() during the initial rendering phase of stateless richlet.

      Expected uses: Update to existing iComponent tree, mapping actions to existing iComponents, triggering async operation

      Acceptance Criteria

      Can obtain UiAgent.getCurrent() during richlet initial rendering phase

      Details

      Uses cases for UiAgent updates during page load:
      
      - Can select and modify iComponents generated from a 3rd party class or library
      example:
      
      /* 	generates iComponents from zul, zul uses the provided IDs for buttons
      	This is easier than mapping the actions in zul
      	Doesn't currently work during richlet "first load", since UiAgent is not available.
      */
      
      	Map argMap = new HashMap<>();
      	argMap.put("addId", addId);
      	argMap.put("submitId", submitId);
      	Iterable<? extends IAnyGroup> zulCreatedComponents = Immutables.createComponents("~./zul/templates/orderButtons.zul",argMap);
      
      	IDiv updatedDiv = IDiv.DEFAULT.withChildren(zulCreatedComponents);
      	
      	IButton addBtn = (IButton)ISelectors.findById(updatedDiv, addId);
      	IButton submitBtn = (IButton)ISelectors.findById(updatedDiv, addId);
      	UiAgent.getCurrent().replaceWith(Locator.ofId(addId), addBtn.withAction(this::addItem));
      	UiAgent.getCurrent().replaceWith(Locator.ofId(submitId), submitBtn.withAction(this::doSubmit));
      
      	UiAgent.getCurrent().replaceWith(Locator.of(div), updatedDiv);
      	
      	
      	
      	
      - Can run async during initial load
      ex:
      
      	Clients.log("render page skeleton and display load indicator");
      	UiAgent.getCurrent().runAsync(u ->{
      		Clients.log("pull large database stuff after initial load");
      		data =  db.loadStuff();
      		u.smartUpdate(...)
      	});
      

       

            jumperchen jumperchen
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: