0

zk6.x - lang-addon annotation - Array of attribute values not allowed

asked 2013-05-09 08:43:51 +0800

jayzk gravatar image jayzk
37 3

updated 2013-05-09 08:47:01 +0800

Hi,

I am upgrading my project from zk5.x to zk6.x. I have extended the zk component and adding my converter to the lang-addon.xml. As per documentation, zk should override the previous one, rather, it seems to be creating an array and throws an error that array is not allowed. This was working fine in zk5.x

As per documentation:

converter. You can specify the class name of the converter that implements the TypeConverter interface. It is used to convert the value between component attribute and bean field. Multiple definition is NOT allowed and the later defined would override the previous defined one.

Here is my lang-addon.xml definition:

<component>
    <component-name>combobox</component-name>
    <extends>combobox</extends>
    <annotation>
        <annotation-name>default-bind</annotation-name>
        <property-name>selectedItem</property-name>
        <attribute>
            <attribute-name>converter</attribute-name>
            <attribute-value>com.mycompany.MyComboboxConverter</attribute-value>
        </attribute>        
             </annotation>
</component>

I get the following error: org.zkoss.zk.ui.UiException: Array of attribute values not allowed, [org.zkoss.zkplus.databind.SelectedComboitemConverter, com.mycompany.MyComboboxConverter]

As you can see, I am adding only my converter MyComboboxConverter, the other converter seems to be added by zk.

Please help.

Regards, Jay

delete flag offensive retag edit

Comments

This new code check in DataBinder.java is causing the issue.

In zk 6.5.1 String tag = entry.getKey(); String[] tagval = entry.getValue(); String tagExpr; if (tagval.length != 1) throw new UiException("Array of attribute values not allowed, "+Objects.toStr

jayzk ( 2013-05-10 11:47:51 +0800 )edit

Could you provide a sample that can reproduce this issue?

benbai ( 2013-06-20 05:32:52 +0800 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-06-20 05:52:34 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

@Jay,

The sample below works well for me in ZK 6.5.1

test.zul

<zk>
    <window apply="org.zkoss.bind.BindComposer"
        viewModel="@id('vm') @init('test.TestVM')">
        <combobox model="@load(vm.model)"
            selectedItem="@bind(vm.selectedItem)" />
        <combobox model="@load(vm.model)"
            selectedItem="@bind(vm.selectedItem)" />
    </window>
</zk>

TestVM.java

package test;

import java.util.ArrayList;
import java.util.List;

import org.zkoss.zul.ListModelList;

/**
 * tested with ZK 6.5.1
 * 
 * @author benbai
 *
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public class TestVM {
    private ListModelList _model;
    private String _selectedItem;
    public ListModelList getModel () {
        if (_model == null) {
            List l = new ArrayList();
            l.add("item 1");
            l.add("item 2");
            l.add("item 3");
            _model = new ListModelList(l);
        }
        return _model;
    }
    public void setSelectedItem (String selectedItem) {
        System.out.println("setSelectedItem");
        _selectedItem = selectedItem;
    }
    public String getSelectedItem () {
        System.out.println("getSelectedItem");
        return _selectedItem;
    }
}

TestComboboxSelectedItemConverter.java

package test;

import org.zkoss.bind.BindContext;
import org.zkoss.bind.converter.sys.ComboboxSelectedItemConverter;
import org.zkoss.zk.ui.Component;

public class TestComboboxSelectedItemConverter extends ComboboxSelectedItemConverter {

    private static final long serialVersionUID = -2681108761775546276L;
    public Object coerceToUi(Object val, Component comp, BindContext ctx) {
        System.out.println("TestComboboxSelectedItemConverter#coerceToUi");
        return super.coerceToUi(val, comp, ctx);
    }
    public Object coerceToBean(Object val, Component comp, BindContext ctx) {
        System.out.println("TestComboboxSelectedItemConverter#coerceToBean");
        return super.coerceToBean(val, comp, ctx);
    }
}

zk.xml

<zk>
    <language-config>
        <addon-uri>/WEB-INF/lang-addon.xml</addon-uri>
    </language-config>
</zk>

lang-addon.xml

<language-addon>
    <addon-name>testaddon</addon-name>
    <language-name>xul/html</language-name>
    <component>
        <component-name>combobox</component-name>
        <extends>combobox</extends>
        <annotation>
            <annotation-name>ZKBIND</annotation-name>
            <property-name>selectedItem</property-name>
            <attribute>
                <attribute-name>SAVE_EVENT</attribute-name>
                <attribute-value>onChange</attribute-value>
            </attribute>
            <attribute>
                <attribute-name>LOAD_EVENT</attribute-name>
                <attribute-value>onAfterRender</attribute-value>
            </attribute>
            <attribute>
                <attribute-name>ACCESS</attribute-name>
                <attribute-value>both</attribute-value>
            </attribute>
            <attribute>
                <attribute-name>CONVERTER</attribute-name>
                <attribute-value>test.TestComboboxSelectedItemConverter</attribute-value>
            </attribute>
        </annotation>
    </component>
</language-addon>

Regards,

Ben

link publish delete flag offensive 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
2 followers

RSS

Stats

Asked: 2013-05-09 08:43:51 +0800

Seen: 28 times

Last updated: Jun 20 '13

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