-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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?
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.
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
Asked: 2012-07-26 17:08:57 +0800
Seen: 160 times
Last updated: Jul 27 '12