0

Binder Converter Arguments Pass View Model Property [closed]

asked 2015-05-24 05:19:22 +0800

ghostomg gravatar image ghostomg flag of Indonesia
15 3

updated 2015-05-24 05:23:48 +0800

Hi, I'm using ZK 7.0.2, I'm just wondering If I could pass view model property to programmatically binder's converter arguments. let say I have this property in my View Model class :

private List<Person> personList;
// ... personList setter & getter

When I pass this personList to my custom converter argument by ZUL page, like below snipset, it just work fine (both of coerceToUi & coerceToBean method work fine).

<textbox value="@bind(fx.person) @converter('personConverter', list=vm.personList)" />

But when I used it by programmatically binder (the equivalent purpose). it reach the custom converter class, but just pass plain String object rather than invoked view model object.

String[] beforeCmds = {"saveAction"};
HashMap<String,Object> converterArgs = new HashMap<>();
converterArgs.put("list", "vm.personList");

Textbox txtPerson = new Textbox();
binder.addPropertyLoadBindings(txtPerson, "value", "fx.person", 
    null, null, null, "'personConverter'", converterArgs);
binder.addPropertySaveBindings(txtPerson, "value", "fx.person",
    null, null, null, "'personConverter'", converterArgs, null, null);
binder.addPropertySaveBindings(txtPerson, "value", "fx.person",
    beforeCmds, null, null, "'personConverter'", converterArgs, null, null);

In personConverter class, it received pass args by :

List<Person> list = (List<Person>) bc.getConverterArg("list");

Error appears because can't cast string object "vm.personList" to List<person>. Or indeed it can not be pass view model property by programmatically binder? Please kindly help me. Thank you.

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by cor3000
close date 2015-05-25 10:41:24

Comments

In the map, we put normally the data, as you "translate" the zul, vm.personList is actually the data and not a string. I think this should work : Make a new referenceBinding to a component, and pass that to the converter.

chillworld ( 2015-05-24 08:34:14 +0800 )edit

Hi Chillworld, thanks to your response. ok, I will tried it. and for additional information, it work fine when I pass the List collection not the VM Property String. so: converterArgs.put("list", getPersonList()) is work rather than converterArgs.put("list", "vm.personList").

ghostomg ( 2015-05-25 02:48:38 +0800 )edit

yes that works initially, but once the vm.personList is replaced by another list it will not reload, my suggestion below will reload in such a case if NotifyChange is triggered: so it depends a bit on your requirements

cor3000 ( 2015-05-25 03:26:18 +0800 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2015-05-25 02:36:54 +0800

cor3000 gravatar image cor3000
4332 1 7
ZK Team

There is a util class to parse the values as EL expressions:

e.g.

Map<String,String[]> args = new HashMap<String, String[]>();
args.put("list", new String[] {"vm.personList"});
HashMap<String,Object> parsedArgs =
        BindEvaluatorXUtil.parseArgs(binder.getEvaluatorX(),args);

parsedArgs will then contain an ELExpression ${vm.personList} an not just the string "vm.personList"

simplified from AnnotateBinderHelper.parseConverter(comp, propName) (after preparing the HashMap<string, string[]&gt;="" line="" 725="" calls="" <a="" href="http://grepcode.com/file/repo1.maven.org/maven2/org.zkoss.zk/zkbind/7.0.3/org/zkoss/bind/impl/BindEvaluatorXUtil.java#BindEvaluatorXUtil.parseArgs%28org.zkoss.bind.sys.BindEvaluatorX%2Cjava.util.Map%29">BindEvaluatorXUtil.parseArgs(eval, args))

link publish delete flag offensive edit
0

answered 2015-05-25 08:43:53 +0800

ghostomg gravatar image ghostomg flag of Indonesia
15 3

Hi, Cor3000 thanks a lot for your code example. It have tried it & work fine so far :) Here's is my implementation:

Map<String, String[]> args = new HashMap<String, String[]>();
args.put("list", new String[]{"vm.personList"});                                
Map<String, Object> parsedArgs = BindEvaluatorXUtil.parseArgs(binder.getEvaluatorX(), args);

Textbox txtPerson = new Textbox();
binder.addPropertyLoadBindings(txtPerson, "value", "fx.person", 
    null, null, null, "'personConverter'", parsedArgs);
binder.addPropertySaveBindings(txtPerson, "value", "fx.person",
    null, null, null, "'personConverter'", parsedArgs, null, null);
binder.addPropertySaveBindings(txtPerson, "value", "fx.person",
    beforeCmds, null, null, "'personConverter'", parsedArgs, null, null);
link publish delete flag offensive edit

Comments

thanks for getting back!

cor3000 ( 2015-05-25 10:41:03 +0800 )edit

Question tools

Follow
2 followers

RSS

Stats

Asked: 2015-05-24 05:19:22 +0800

Seen: 15 times

Last updated: May 25 '15

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