0

trouble with composer and El

asked 2009-12-11 09:09:08 +0800

YamilBracho gravatar image YamilBracho
1722 2

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

delete flag offensive retag edit

13 Replies

Sort by ยป oldest newest

answered 2009-12-11 10:00:36 +0800

fmcypriano gravatar image fmcypriano
612 1 7
http://felipecypriano.com...

updated 2009-12-11 10:00:59 +0800

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.

link publish delete flag offensive edit

answered 2009-12-11 12:25:11 +0800

YamilBracho gravatar image YamilBracho
1722 2

Thanks a lot, Felipe!

link publish delete flag offensive edit

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

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

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...

link publish delete flag offensive edit

answered 2009-12-14 10:05:55 +0800

YamilBracho gravatar image YamilBracho
1722 2

It didn't work.
Just as Cary said, EL expressions are evaluated before doAfterCompose() method.

Is there an alterantive way to solve this problem ?

link publish delete flag offensive edit

answered 2009-12-14 14:34:12 +0800

kesavkolla gravatar image kesavkolla
180 3

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.

link publish delete flag offensive edit

answered 2009-12-14 16:37:04 +0800

robertpic71 gravatar image robertpic71
1275 1

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);
[3. register databinding with the same name - if you use databinding]
4. Use the same name for @databinding and $EL @controller/@model vs. $controller/$model

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

link publish delete flag offensive edit

answered 2009-12-15 01:57:42 +0800

tomCat gravatar image tomCat
276 3

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

link publish delete flag offensive edit

answered 2009-12-15 09:48:23 +0800

robertpic71 gravatar image robertpic71
1275 1

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

link publish delete flag offensive edit

answered 2009-12-15 19:10:24 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

updated 2009-12-15 19:18:23 +0800

@robertpic71,

setVariable(key, value, true) in zk3 shall be almost identical to setAttribute(key, value, Component.SPACE_SCOPE) in zk5;

link publish delete flag offensive edit

answered 2009-12-16 06:17:45 +0800

robertpic71 gravatar image robertpic71
1275 1

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);

instead of setVariable

/Robert

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-12-11 09:09:08 +0800

Seen: 582 times

Last updated: Dec 16 '09

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