# From a zul, how to access a component inside an include

WilliamB
1609 1 6

I've the following setup.

Mainzul.zul :

<window>
<include id="myInclude" src="mysubZul.zul" />
<button onClick="@Command('myCmd', subValue=myTextBox.value)" />
</window>


mysubZul.zul

<window>
<textbox id="myTextBox" />
</window>


At the moment I cannot access the component in the include. I know how to wire it in my VM, but I want to avoid that.

Thanks

delete retag edit

did you try to use a transparent component such as a simple <div> instead of the <window> in the mysubZul.zul?

( 2016-02-19 10:24:48 +0800 )edit

@gganassin that doesn't matter the include has the IdSpace interface also so he will hit always a difference IdSpace

( 2016-02-19 10:49:31 +0800 )edit

@chill yep indeed but if you see my reply... he can target the include itself so that's not the issue. Having instead other inner IdSpaces inside the include will then make this goal prohibitive... no?

( 2016-02-19 10:53:12 +0800 )edit

a little more detail about the VM or VM's can be helpfull.

( 2016-02-19 11:04:18 +0800 )edit

@gganassin it makes It a little more difficult because he need to pass the idspace with the window only but it's still possible

( 2016-02-19 11:12:01 +0800 )edit

Sort by » oldest newest most voted

gganassin
540 6
http://www.hybris.com/
...
<include id="myInclude" src="included.zul" />
<button onClick="@command('myCmd', val=myInclude.getFellow('myTextBox').value)" />
...


and

@Command
public void myCmd(@BindingParam(value = "val") String val) {
System.out.println(val);
}


NOTE: the included zul should use transparent components... otherwise you will be forced to know how it is composed (and to articulate even more the myInclude.getFellow('myTextBox'). You should anyway try to do in another way: myInclude.getFellow('myTextBox').value is really weak... as you can see if the inner .zul gets changed over time... it may cause issues.

Gio

That's what I already implemented, but I wanted to know if there was a cleaner syntax like myInclude\$myTextBox for the composer or #myInclude #myTextBox for the VM.

( 2016-02-19 13:18:49 +0800 )edit

chillworld
5322 4 9
https://github.com/chillw...

William,

A MVVM solution could be :

<window>
<textbox id="myTextBox" value="@bind(vm.xxx)/>
</window>


As long your viewmodel have that getter/setter there is no problem.

I'll see for a solution with the id's but for MVVM I do think you need to avoid having id's.

## Edit:

Returns the first textbox under window (no id needed):

myInclude.query("window > textbox").value


Same but on id's : (is faster then previous)

myInclude.query("#win > #myTextBox").value


Thanks Chill, but what I want is a zul way to access the component directly, as I stated above, I already use myInclude.getFellow('myTextBox').value but I wanted to know if there was a cleaner synthax.

( 2016-02-19 13:19:43 +0800 )edit
[hide preview]