elzkzul

ZK - concatenate a variable with a constant string in a map key in ZUL EL


A have a custom translator object implementing java.util.Map in the page scope un I use it like

<checkbox id="cbCopy" label='${translator.copy}' />

It works fine also for hierarchical keys using the more complex map syntax of EL:

<checkbox id="cbCopy" label='${translator['hierarchical.key.copy']}' />

It also works when I have the key in a variable:

<zscript>
    desktopScope.put("someKey",sessionScope.get("customerCompany")+".copy");
</zscript>
<checkbox id="cbCopy" label='${translator[someKey]}' />

My problem is to compose the hierarchical key in the EL expression concetanating a variable and a constant string:

<zscript>
    desktopScope.put("customerCompany",sessionScope.get("customerCompany")+".");
</zscript>
<checkbox id="cbCopy" label='${translator[customerCompany+'copy']}' /> <!-- DOES NOT WORK!!! -->

Ist it somehow possible?

The reason is that several (but not all) ZUL GUI component on the page needs this kind of composite i18n keys.


Solution

  • Since ZK 8, you can concatenate a string with +=:

    ${translator[customerCompany+='copy']}

    Ref: https://github.com/zkoss/zkbooks/blob/master/developersreference/developersreference/src/main/webapp/uiComposing/elExpression.zul

    In previous version, you can use tag library, cat.