Search code examples
javazk

ZK - org.zkoss.util.IllegalSyntaxException: only allow one string of @command


I have the following zul

<?xml version="1.0" encoding="UTF-8"?>
<zk>
    <window apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('MyViewModel')"> 
        <button onClick="@command('myCommand', value='myValue')" />
    </window>
</zk>

with a button inside which calls a command inside the view model passing a parameter called value

The page returns the following error:

org.zkoss.util.IllegalSyntaxException: only allow one string of @command,but contains ['myCommand', 'myValue'

ZK version: 7.0.4


Solution

  • Please have a look below code,please remove '' from argument it will work

    <button label="MyButton" onClick="@command('myCommand', somevalue=myValue)"/>
    

    Here are some example from documents

    <button label="Save" onClick="@command('saveOrder')" />
    
    <button label="Delete" onClick="@command(empty vm.selected.id?'deleteOrder':'confirmDelete')" />
    
    <button label="Index" onClick="@command('showIndex', index=10, keyword='myKeyword')"/>
    

    More Information you can find

    Notice that value is a reserved word, you should avoid to use it as an arbitraryKey.

    books.zkoss.org/zk-mvvm-book/8.0/syntax/databindingcommand.html