-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
@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
Asked: 2013-05-09 08:43:51 +0800
Seen: 29 times
Last updated: Jun 20 '13
Problem binding values to a composite component
How to access static member field of a class in zul without zscript
How can i load a constant in .zul
MVVM Validator: class not found ? [closed]
MVVM tab box - delay @load until tab pane displayed?
mvvm, load or save with after or before for seach command
how to fire an event when a variable value loaded through VM
is there any event trigger from zk component on binding ?
ZK team plans to dispose of Composer EventQueues no longer in scope? [closed]
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 )editCould you provide a sample that can reproduce this issue?
benbai ( 2013-06-20 05:32:52 +0800 )edit