# Using a template.. but I want to load the first page dynamically? [closed]

rickcr
704 7

I'm using a template.zul that is backed by a NavigationComposer. On my index.zul page I want to load the first page - that is I need to look up the last used page from a cookie - the issue is I was hoping I could do this in my NavigationComposer.. but in doAfterCompose the include page id isn't bound yet, so I'm not sure how I can set the source? Maybe there is some other approach to take?

for some reference:

index.zul

<?init class="org.zkoss.zk.ui.util.Composition" arg0="layout/template.zul"?>
<zk>
<include id="mainInclude" self="@define(content)" src=" "/>
</zk>


relevant template.zul ...

<vlayout apply="com.ncs.ncsadmin.web.controller.NavController">

<vlayout id="contentSection" self="@insert(content)"></vlayout>


NavController.. was hoping to do...

@Wire
private Include mainInclude;

@Override
public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);
//logic to get the page from cookie
mainInclude.setSrc(page);

}


Problem is maininclude is "null" in doAfterCompose since the include hasn't been rendered yet (even using mode="instant"

So what's the best way to solve this situation? Do I have wrap my include in a ViewModel/Composer and load the default page from there?

delete retag edit

### The question has been closed for the following reason "the question is answered, right answer was accepted"by rickcr close date 2014-01-02 15:10:18

Sort by » oldest newest most voted

vincentjian
2245 6

Hi,

In your case, <?init?> is executed before rendering page (here is index.zul), therefore mainInclude is null. And also, you cannot wire component that is not belong to the zul page.

I would suggest wrap the include component in a Composer. Here is the simple sample in zkfiddle.

Thanks for the zkfiddle. Really appreciate it. I like how you demonstrated setting the page in desktop scope in the template's composer as well.

( 2014-01-02 15:09:33 +0800 )edit