0

If Else in ZUL

asked 2012-03-14 04:58:24 +0800

shukrimb gravatar image shukrimb
24

Good day guys,

How to do a condition in ZUL page. I just want to display textbox if fullfil the condition else displat a label.
Sample JSP is something like this
if(Status.equals('Y'){
<textbox/>
}
else {
<label value='additional information' />
}

How to do in ZUL,

Appreciates ur feedback guys

Thanks

Shuk

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2012-03-14 11:40:13 +0800

mhj gravatar image mhj flag of Brazil
806 1 7

hi shukrimb!
i don't understood very good your problem, maybe the code below can help you...

ZKFiddle-Link

TestComposer.java
package j1m2gpn5$v1;

import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;

public class TestComposer extends GenericForwardComposer{

public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);

}

public void onClick$btn(Event e) throws InterruptedException{
Messagebox.show("Hi btn");
}
}


index.zul
<zk>
<window border="normal" title="hello" apply="j1m2gpn5$v1.TestComposer">
<label id="lbl" visible="false" value="blablablablablablablablabla"/>
<textbox id="tbx" visible="false" value="blablablablablablablablabla"/>
<button label="shows label">
<attribute name="onClick"><![CDATA[
lbl.setVisible(true);
tbx.setVisible(false);
]]>
</attribute>
</button>
<button label="shows textbox">
<attribute name="onClick"><![CDATA[
lbl.setVisible(false);
tbx.setVisible(true);
]]>
</attribute>
</button>
</window>
</zk>

any question, can ask.

link publish delete flag offensive edit

answered 2012-03-14 13:00:19 +0800

shukrimb gravatar image shukrimb
24

Hi mhj,
Really appreciated your respond. Below is my code snippet :

<listitem self="@{each=docs}" value="@{docs}">
<listcell label="@{docs.docId}" />
<listcell label="@{docs.docName}" />
<listcell label="@{docs.docComply}" />
<listcell label="@{docs.docStatus}" />
<listcell>
Here is the problem
Base on the object given (docs.docAdd), I need to display is either textbox or label base on below condition
but, its displayed both
Database records
======================================
doc add = N
doc add = N
doc add = N
doc add = Y
doc add = Y
======================================
My Question is, it is correct to do a if condition like this ?


<textbox if="${docs.docAdd==Y}" value="Please Keyin Data" />
<label if="${docs.docAdd==N}" value="No Info Required"/>

</listcell>
</listitem>

Hope you understand my problem, :D
Many thanks,

Shukrimb

link publish delete flag offensive edit

answered 2013-04-30 14:55:49 +0800

Niltus gravatar image Niltus
10 1

hey did you solve your problem? im trying to do the same

link publish delete flag offensive edit

answered 2013-04-30 15:10:43 +0800

gganassin gravatar image gganassin flag of Luxembourg
540 6
http://www.hybris.com/

updated 2013-04-30 15:15:55 +0800

From what i understood, this scenario better fits to a custom renderer:

Using a ListModel and ListitemRenderer

There are many examples around about renderers... this one is about grids:

dynamic render

in your case... you will be doing something like:

public void render(Listitem item, YourBean bean, int index) throws Exception {
    item.setValue(bean);
    Listcell c1 = new Listcell();
    c1.setParent(item);
    if (bean.isTrue()) {
        new Textbox().setParent(item);
    } else {
        new Label("no need").setParent(item);
    }
}

hope it helps! Giovanni

link publish delete flag offensive edit
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-03-14 04:58:24 +0800

Seen: 730 times

Last updated: Apr 30 '13

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