0

Template like functionality for a single value?

asked 2014-07-24 12:56:41 +0800

aznavour gravatar image aznavour
26 3

updated 2014-07-24 13:28:26 +0800

Hi everbody,

I'm rendering a grid, and within a cell, I'd like to render a label or an anchor tag (a link) depending on the current entity rendered.

so that its one time rendered:

<cell><label value="@load(each.prop)" /></label><cell>

and the other time:

<cell><a href="..."><label value="@load(each.prop)" /></label></a><cell>

What is the proposed way to do this? I wonder if there is some template like functionality as it exists for children binding, so I could decide which one to render.

<cell template="@load(... decided what template ...)">
  <template name="withLink">...</template>
  <template name="withOutLink">...</template>
</cell>

Thanks alot, Charles

delete flag offensive retag edit

Comments

how do he decide what template to choose?

chillworld ( 2014-07-27 19:58:22 +0800 )edit

By everthing the EL allows, for ex. ="@load(each.test() ? 'X' : 'Y')" or "@load(each.template)".

aznavour ( 2014-07-28 10:51:53 +0800 )edit

hi Charles, I think "if" will work if the entity won't become to linkable by some interaction. Or I think using visible attribute is a feasible solution.

vincentjian ( 2014-07-31 04:41:53 +0800 )edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2014-07-27 05:11:08 +0800

Darksu gravatar image Darksu
1991 1 4

Hello aznavour,

In order to accomplish your task you have to implement a custom rowRenderer as shown in the link bellow:

http://www.zkoss.org/zkdemo/grid/dynamic_renderer

In detail, you set in your zul script a rowRenderer which targets a implementation of the RowRenderer class.

There you can set the components you wish for each row.

Best Regards,

Darksu

link publish delete flag offensive edit
0

answered 2014-07-27 11:58:02 +0800

aznavour gravatar image aznavour
26 3

Thanks Darksu,

The solution probably works. Though, we'd like to go with zul declaration and data binding as much as possible. An alternative would be to use an <include> and have a dynamic src set. But it feels like a too big overhead to just accomplish this for a single cell and needs putting it in a different file (which makes sense probably, as its reusable - but there might be cases where just define in the one file is fine).

Maybe a feature request for ZK Bind ?

Any other suggestions?

link publish delete flag offensive edit
1

answered 2014-07-27 12:35:28 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

updated 2014-07-28 12:27:27 +0800

Maybe you could use the if (or the visible attribute)?

<cell>
    <label value="@load(each.prop)" if="@load(not each.withLink)"/>
    <a href="..." if="@load(each.withLink)">
        <label value="@load(each.prop)" />
    </a>
</cell>

So the each should give a boolean back with the property "withLink".

Edit :

After reading your 2 comments :

1) You don't have to use each.withLink, but I don't see the difference between ="@load(each.test() ? 'X' : 'Y')" or use the visible attribute.

2) The if can work but indeed you don't have to use @load but :

<label value="@load(each.prop)" if="${not each.withLink}"/>

3) Other (proper) solution :

Create a Taglib (here I call it 'mine-taglib.tld')

<taglib>
    <function>
        <name>instanceXX</name>
        <function-class>be.chillworld.utils.ZkUtils</function-class>
        <function-signature>
            java.lang.Boolean checkInstanceXX(java.lang.Object)
        </function-signature>
        <description>Checks for a specific instance</description>
    </function>
</taglib>

Create java class :

public class ZkUtils {
    public static Boolean checkInstanceXX(Object o) {
        return (o instanceof AtomicInteger);
    }
}

Zul :

<?taglib uri="/WEB-INF/tld/mine-taglib.tld" prefix="mt"?>
.....
<cell>
    <label value="@load(each.prop)" visible="@load(not mt:checkInstanceXX(each))"/>
    <a href="..." visible="@load(not mt:checkInstanceXX(each))">
        <label value="@load(each.prop)" />
    </a>
</cell>

Greetz chill.

link publish delete flag offensive edit

Comments

The "if" is probably not going to work. http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/MVVM/Advanced/Binding_in_Special_Attribute (http://books.zkoss.org/wiki/ZKDeveloper%27sReference/MVVM/Advanced/BindinginSpecial_Attribute) . Using visible could make it look like what I want to achieve. But: not all entities are linkable. We could workaround, sure, but still leaves a bad feeling.

aznavour ( 2014-07-28 10:57:59 +0800 )edit
Your answer
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
1 follower

RSS

Stats

Asked: 2014-07-24 12:56:41 +0800

Seen: 22 times

Last updated: Jul 28 '14

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