-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi.
I have a window with a composer and inside the composer I have a getter, say:
public class MainComposer extends GenericComposer {
...
public boolean isUsuarioExterno() {
boolean isUsuarioExterno = false;
UserBean currentUser = ZKHelper.getUserFromSession();
if (currentUser != null) {
isUsuarioExterno = currentUser.isUsuarioExterno();
}
return isUsuarioExterno;
}
}
And in my zul
<window id="mainWindow"
title="Domiciliacion de Pagos"
border="normal"
width="100%"
height="100%"
apply="${mainComposer}">
And I woud like to show/hide options in a tree, say:
<treeitem label="Empresa" value="" open="true" if="!{win$composer.isUsuarioExterno}">
But I am not sure if this syntax is correct... because I saw some samples using "@"
Any hint
I think you need to use EL the "$" symbol:
<treeitem label="Empresa" value="" open="true" if="${win$composer.isUsuarioExterno}">
The data binding - @ symbol - version don't work in if, at least it didn't when I tested. Maybe because the if attribute is evaluated before the binding.
Thanks a lot, Felipe!
I'm curious if this works...if's and EL expressions are evaluated at an early time...I don't think the composer's doAfterCompose() has run yet so the win$composer variable won't exist...I might be wrong, but that's how I remember it...
It didn't work.
Just as Cary said, EL expressions are evaluated before doAfterCompose() method.
Is there an alterantive way to solve this problem ?
what is the name of the method you have written in composer? EL follows strict java bean naming translation. It doesn't call the methods by name it calls methods by corresponding getXXX methods. I'd suggest you to write a method getUsuarioExterno() method and in EL use ${win.$composer.usuarioExterno}. Remember the EL starts with lower case "u" and the method name is getU. It's the rules for java beans get/set methods.
First, try
<treeitem label="Empresa" value="" open="true" if="${win$composer.UsuarioExterno}">
instead of: <treeitem label="Empresa" value="" open="true" if="${win$composer.isUsuarioExterno}">
[EDIT: kesavkolla was faster]
I think, your variant search isIsUsuario....
However, i prefer a other way:
1. extend your Composer with ComposerExt
2. register the composer (or a modelholder) as variable
@Override public void doBeforeComposeChildren(Component cmp) throws Exception { super.doBeforeComposeChildren(cmp); //set the new object to original component's name then we can use it by EL cmp.setVariable(cmp.getId(), this, true); // register with another name cmp.setVariable("controller", this, true);
Don't forget:
EL's are only evaluated during the first-time rendering and support only model --> UI
@Databinding could be evaluated more (binder.loadXX, binder.save..) than once and support both ways model <-> UI
Check this thread for the full exmaple.
/Robert
Hi Robert,
how to do this without the use of setVariable? Right know i am using setVariable, but as far as i know it is depreceated in zk5. Is there a way to use setAttribute (comp.setAttribute("controller",this)) and access this attribute
via EL inside my zul page?
best regards
tomCat
I've taken the syntax from a Composer smalltalk - that's ZK stuff. I do only use a variant.
ZK Team says: use setAttribut instead of setVariable - but this is not working for EL's.
However if post another thread.
/Robert
@robertpic71,
setVariable(key, value, true) in zk3 shall be almost identical to setAttribute(key, value, Component.SPACE_SCOPE) in zk5;
Hi henri,
thanks, yes setAttribute works for EL's in zk5 - i've tested it with zk 3.6.2.
@tomCat
For ZK >= 5 use:
i.e.
cmp.setAttribute("controller", this, Component.COMPONENT_SCOPE);
/Robert
Asked: 2009-12-11 09:09:08 +0800
Seen: 582 times
Last updated: Dec 16 '09