-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I want to hide a component using an "if" like this:
<listitem self="@{each='product'}" value="@{product}">
<listcell label="@{product.name}" if="${1 == 0}" />
</listitem>
This works. But now I want to use a bound value from the model in the if, like this:
<listcell label="@{product.name}" if="${product.name eq 'foo'}" />
which does not work, since product.name has no meaning in EL context. I also tried things like:
if="${self.parent.value.name eq 'foo'}"
But I get the feeling I am going down the wrong path here... Any suggestions?
the issue is that "if" is used in the Render phase only...when you're wanting to use bound values the "if" has been evaluated and won't be again...
I didn't try this code, but perhaps this will work
<listcell label="@{product.name}" visible="@{product.name eq 'foo'}" />
though I don't know if the data binder will evaluate that expression...regardless, use "if" won't work because it's past the rendering phase
Thank you for your prompt reply.
The issue is not just the visibility of the element but rather it's existence depends on a condition.
I have done this with zk jsp tags combined with JSTL, but now I have everything defined in ZUL which is much nicer.
Is it possible to use JSTL in ZK pages?
I appreciate your help.
Rex
Hi Rex,
In Zul page, you cannot use JSTL taglib, because ZK loader doesn't recognize them.
/Jumper
Thank you for all the replies. So what is the equivalent of JSTL <c:if> in zul pages? This is my code:
<listbox id="libraryListBox" multiple="true" checkmark="true" model="@{inodes}" mold="paging" pageSize="10" >
<listheader ...
<listitem height="30px" self="@{each=inode}" value="@{inode}">
<listcell if="${inode.objectType == 'folder'}" context="folderContextMenu">
<listcell if="${inode.objectType == 'document'}" context="documentContextMenu">
</listcell>
As you can see based on 'objectType' the context menu for each element and also (not shown here) the icon for the
row will be different.
Can anyone tell me how am I suppose to do the comparison?
Any help will be greatly appreciated.
Regards,
Rex
The only thing I think of is to implement your own ListitemRenderer and create the listcells with different context attributes depending on the objectType. While ZUL is quite powerful and provides nice separation of view and controller, it doesn't always have quite enough power. And I don't think it's possible for a declarative language to do so. Fortunately, you can make your own view helper in the form of a renderer.
You could achieve this with a type converter, you implement the TypeConverter interface, and in the coerceToUi method you execute the if and change the context.
take a look at the TypeConverter interface
also the user Robert has some good exampls about it in his site
Thank you all for the pointers. What I ended up doing for now, was to set my object property called 'contextMenu' pro grammatically in java to the desired menu context. I looked at Robert page, and those examples are really useful.
Now, I am just wondering why the if, else and loop structures are not available in ZK? I think they add a lot of flexibility unless I am not seeing the big picture.
>> Now, I am just wondering why the if, else and loop structures are not available in ZK?
>> I think they add a lot of flexibility unless I am not seeing the big picture.
There are 2 aproaches:
1. EL's including if, forEach are adopted from other webtools.
They are executed one Time while the first rendering the UI from the xml-source. This is binding is "one way" - you could easily output data, but there is no return for inputdata.
2. @databinding
This binding creates a relation between the UI and the beans. Databinding is executed after rendering the page EL's (1.). The big advantages is that databinding work in both ways: (data)beans to UI-Components and UI-Components to data(beans).
However, the syntax is limited - no evaluation at this time. You could only describe the way to the bean/model. Instead of EL's you could use TypeConverters. This is not so smart as EL's - but you could reuse your typeconverters.
With databinding you could i.e. annotate visible="@{inode.dirType}"
or context="@{inode.objectType, converter=package.yourConverter}"
--> yourConverter returns the name of the contextmenu.
or context="@{inode.objectType}"
--> contextmenu = objectType
or context="@{inode.objectTypeContext}"
--> getObjectTypeContext is a transient getter
Sometimes it is possible to mix EL's with databinding - it depends on the timing. But all model-bindings uses the xml/zul-source as template. So the EL's only interpreted 1xtime (most time with the wrong data) and create the template. So it's no good idea to use EL's inside a Listbox/Grid/x Model.
Maybe newer versions of ZK will support EL's inside Annotations - meanwhile you have to use Typeconverters or model/controller-getters.
Check also this thread for pro's and contras.
/Robert
Thanks so much for your useful comments. Instead of <c:if> I can go forward with introducing getter methods to my object model and is coming along fine. What about a loop structure? I know how to use forEach attribute for listbox and grids. However, if I were to create a 'BreadCrumb' for direcotry browsing, just like Windows Visat explorer. Something like, MyLibrary->Applications->Demo->Planning. So user can click on each section and the UI will refresh the listbox accordingly.
This can be done in JSP like:
<a href="#" onclick="browseRoot()">My Library</a>
<c:forEach var="item" items="${currentFolder.descendants}">
<img src="graphics/forward.gif"/>
<a href="#" onclick="folderBrowse(${item.id})"><c:out value="${item.title}"/></a>
</c:forEach>
In ZK though, I tried something like
<toolbarbutton forEach="@{libraryWin$composer.currentFolder.descendents}"
label="@{inode.title}" forward="onClick=onInodeClick" />
I have no clue as where to put the image that separates each section(link) nor I know which component can be
used to do this task in ZK.
Thanks for all the help.
PS: I think a lot of folks who come from JSP and JSTL backgrounds can benefit greatly off this thread. But it's title is little bit off topic. Is there a way to add keywords to this thread so others can benefit too?
Asked: 2009-07-07 07:46:06 +0800
Seen: 2,605 times
Last updated: Feb 10 '11