0

Reloading Includes

asked 2009-09-17 09:46:01 +0800

zedkey gravatar image zedkey
138 1 1 3

Hi,
I have a page which has a few Include components on it. I would like to reaload these. It works if I call the following code:

myInclude.invalidate();

The only problem what I have is that it leads to a recreation of whatever has been included. For example I have a page included which has a ZK window on it. The ZK window has its use attribute specifying my class to be instantiated. Whenever this is reloaded, I see that a new instance of my class is created. Is there a way to reload parts of pages without this side effect?

Thanks a lot in advance,
Zed

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2009-09-17 10:36:51 +0800

Arsen gravatar image Arsen
383 4

Call method invalidate() of controller of that window.

link publish delete flag offensive edit

answered 2009-09-17 15:46:19 +0800

zedkey gravatar image zedkey
138 1 1 3

Hi,
this does not seem to work (maybe I'm doing it wrong). Here is the code:

public class Hello extends Window implements AfterCompose {

   private int invocations = 0;
   
   public void onIncrement(Event evt) {
      invocations++;
      invalidate();
   }

   public int getInvocations() {
      return invocations;
   }
   // ...
}

Here is the UI code:

<zk>
<window border="none" id="mypage" use="com.foo.Hello">
Invocations: ${mypage.invocations}

<toolbarbutton label="Increment" forward="onIncrement" /> 
</window>
</zk>

Thanks a lot!
Zed.

link publish delete flag offensive edit

answered 2009-09-17 16:31:29 +0800

zedkey gravatar image zedkey
138 1 1 3

and one more thing... of course it would be important that the expression ${mypage.invocations} gets evaluated each time. :)

link publish delete flag offensive edit

answered 2009-09-18 09:07:42 +0800

zedkey gravatar image zedkey
138 1 1 3

maybe this is not possible?
:)

link publish delete flag offensive edit

answered 2009-09-18 10:24:08 +0800

Arsen gravatar image Arsen
383 4
Cann't you use binding instead of invalidate. Here's example. Hope it'll help you
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="./mypage"?>
<zk xmlns="http://www.zkoss.org/2005/zul">
    <window border="none" id="mypage" use="com.foo.Hello">
        <label value="@{mypage.invocations}"/>

        <toolbarbutton label="Increment" onClick="mypage.onIncrement()" />
    </window>

</zk>
public class Hello extends Window implements AfterCompose {

    private int invocations = 0;

    public void onIncrement() {
        invocations++;
        AnnotateDataBinder binder = (AnnotateDataBinder) getVariable("binder", false);
        binder.loadAll();
    }

    public int getInvocations() {
        return invocations;
    }

    public void afterCompose() {
    }
    // ...
}
link publish delete flag offensive edit

answered 2009-09-18 12:11:47 +0800

zedkey gravatar image zedkey
138 1 1 3

Thanks very much, it looks promising, I'll try when I'll have a bit of time :) Cheers,Zed.

link publish delete flag offensive edit

answered 2009-09-18 14:45:22 +0800

zedkey gravatar image zedkey
138 1 1 3

Hi Arsen,

It works smoothly! Now my next concern is if the two approaches are idempotent or not :) Hm, I can think of a problematic use. If the UI page would contain conditional structures (like show this part if a variable is set, otherwise show something else), in this case binder.loadAll would cause a re-rendition of the page? Because what I'm working on is a general possibility to be able to reload included ZK pages, and if Binder is limited in its use, then I have to look for the kill'em all invalidate :)

Thanks again!
Cheers,
Zed.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-09-17 09:46:01 +0800

Seen: 255 times

Last updated: Sep 18 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More