0

EL Expression and Databiding

asked 2012-07-26 17:08:57 +0800

wlainer gravatar image wlainer
36

Hi everyone,

I´m trying hide a element inside a <listitem> using this code:

<image id="bloqueado" src="/imagens/stock_lock.png" width="23px" height="23px" if="@{objeto.stRegistro == 1}"/>

but it didn´t work. i also tried in this way

<image id="bloqueado" src="/imagens/stock_lock.png" width="23px" height="23px" visible="@{objeto.stRegistro eq 0}"/>

and it still did not work.

Anyone can help?

delete flag offensive retag edit

6 Replies

Sort by » oldest newest

answered 2012-07-26 18:42:08 +0800

jj gravatar image jj
638 3

Did you try ${objecto.stRegistro...}, I remember that binding doesn't happen at the rendering step.

link publish delete flag offensive edit

answered 2012-07-26 18:52:59 +0800

wlainer gravatar image wlainer
36

Yes, i had tried this but didn´t work.

I´m using the version 5.0.11 of ZK, because they use this version in project.

link publish delete flag offensive edit

answered 2012-07-26 18:57:27 +0800

jj gravatar image jj
638 3

I am certain that the ${} syntax should work in ZK5. Maybe your bean doesn't have the value you expected.
Just to make sure, put an expression inside ${} that you are sure that is false (e.g. ${false}), and see if it works.

link publish delete flag offensive edit

answered 2012-07-26 19:26:42 +0800

wlainer gravatar image wlainer
36

should i put the syntax ${} with "if" or "visible"?

link publish delete flag offensive edit

answered 2012-07-26 23:42:39 +0800

twiegand gravatar image twiegand
1807 3

updated 2012-07-26 23:52:40 +0800

wlainer,

You'll save yourself a lot of grief if you don't try to mix EL and databinding.  The issue is one of timing - EL gets evaluated very early in the life cycle and only once whereas databinding happens late in the process and can be used multiple times.

However, if the value of objeto.stRegistro is known before the page is rendered, you can do it with the following two examples.

Here is an extremely simple example without a composer:

<zk>
	<zscript>
		String displayFlag = "Y";
	</zscript>
	<window>
		<listbox>
			<listitem>
				<listcell>
					<image src="http://www.zkoss.org/zksandbox/img/Centigrade-Widget-Icons/Globe-128x128.png" height="50px" if="${displayFlag=='Y'}" />
				</listcell>
			</listitem>
		</listbox>
	</window>
</zk>

If you are using a composer, you'll need to set the value (in my example the variable named displayFlag) very early.  You can do this by taking advantage of the doBeforeCompose method - like this:

<zk>
	<zscript>
		import org.zkoss.zk.ui.util.GenericForwardComposer;
		import org.zkoss.zk.ui.util.ComposerExt;
		import org.zkoss.zk.ui.metainfo.ComponentInfo;
		
		public class MyController extends GenericForwardComposer {
			
			public ComponentInfo doBeforeCompose(Page page, Component parent, ComponentInfo compInfo) throws Exception {
				String displayFlag = "Y";
				page.setAttribute("displayFlag", displayFlag);
				return super.doBeforeCompose(page, parent, compInfo);
			}
			
			public void doBeforeComposeChildren(Component cmp) throws Exception {
				super.doBeforeComposeChildren(cmp);
			}
			
			public void doAfterCompose(Component comp) throws Exception {
				super.doAfterCompose(comp);
			}			
		}
	</zscript>
	<window id="win" apply="MyController">
		<listbox>
			<listitem>
				<listcell>
					<image src="http://www.zkoss.org/zksandbox/img/Centigrade-Widget-Icons/Globe-128x128.png" height="50px" if="${displayFlag=='Y'}" />
				</listcell>
			</listitem>
		</listbox>
	</window>
</zk>

 
If you don't have knowledge of the value of objeto.stRegistro prior to screen rendering, you can use databinding to handle it.

One way would be to have your objeto.stRegistro wired into your composer as a boolean and then reference it in the <image> like this:

<image src="http://www.zkoss.org/zksandbox/img/Centigrade-Widget-Icons/Globe-128x128.png" height="50px" visible="@{objeto.stRegistro}" />

Lastly, one of my favorite ways to do what you ask uses databinding and a Type Converter.  You can see an example I wrote previously here.

Regards,

Todd

link publish delete flag offensive edit

answered 2012-07-27 11:15:09 +0800

wlainer gravatar image wlainer
36

thanks, i followed the example that you posted in about Type Converter and now it works.

thanks a lot.

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: 2012-07-26 17:08:57 +0800

Seen: 160 times

Last updated: Jul 27 '12

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