0

How to @Bind on a list.get(0) method without using model.

asked 2016-03-03 10:29:14 +0800

WilliamB gravatar image WilliamB
1609 1 6

updated 2016-03-03 13:26:19 +0800

I want to bind a field on one list item, something like value="@bind(myObj.listAttr.get(0).myfield)"

But I get a NumberFormatException. It works fine when reading but not when writing.

Is there a way to do it? I do not want to use model. Is there a way to define my value in the zul like on the parent element ?

I cannot use ZKscript though.

EDIT I'm trying to combien forEach and binding with the following code :

<cell forEach="${elemSvc.listTests}" >
    <textbox value="@bind(elemSvc.listTests.get(0).value)"  />
</cell>

The error I get :

Caused by: java.lang.NumberFormatException: For input string: "get" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.7.045] at java.lang.Integer.parseInt(Integer.java:492) ~[na:1.7.045] at java.lang.Integer.parseInt(Integer.java:527) ~[na:1.7.0_45] at org.zkoss.zel.ListELResolver.coerce(ListELResolver.java:167) ~[zel-7.0.6.jar:7.0.6] at org.zkoss.zel.ListELResolver.getValue(ListELResolver.java:51) ~[zel-7.0.6.jar:7.0.6] at org.zkoss.zel.CompositeELResolver.getValue(CompositeELResolver.java:66) ~[zel-7.0.6.jar:7.0.6] at org.zkoss.zel.CompositeELResolver.getValue(CompositeELResolver.java:66) ~[zel-7.0.6.jar:7.0.6] at org.zkoss.xel.zel.XelELResolver.getValue(XelELResolver.java:72) ~[zcommon-7.0.6.jar:7.0.6] at org.zkoss.bind.xel.zel.BindELResolver.getValue(BindELResolver.java:69) ~[zkbind-7.0.6.jar:7.0.6] at org.zkoss.zel.impl.parser.AstValue.getTarget(AstValue.java:123) ~[zel-7.0.6.jar:7.0.6] at org.zkoss.zel.impl.parser.AstValue.setValue(AstValue.java:206) ~[zel-7.0.6.jar:7.0.6] at org.zkoss.zel.impl.ValueExpressionImpl.setValue(ValueExpressionImpl.java:247) ~[zel-7.0.6.jar:7.0.6] at org.zkoss.xel.zel.ELXelExpression.setValue(ELXelExpression.java:50) ~[zcommon-7.0.6.jar:7.0.6] at org.zkoss.bind.impl.BindEvaluatorXImpl.setValue(BindEvaluatorXImpl.java:58) ~[zkbind-7.0.6.jar:7.0.6] ... 77 common frames omitted

delete flag offensive retag edit

Comments

Hello again! Strange i cannot reproduce this: i guess it is related to the other post. Check the forked fiddle here: http://zkfiddle.org/sample/3g28kgj/2-Grid-dynamic-number-of-cells-zul-only-bis no matter if you specify a straight 0 or a better 'c.index' inside the get, everything works fine right?

gganassin ( 2016-03-03 11:05:19 +0800 )edit

Weird, I get that : org.zkoss.zk.ui.UiException: For input string: "get"

In fact it's tied to my other message, I'm trying to cheat the system, i updated the original post with code example.

WilliamB ( 2016-03-03 13:17:43 +0800 )edit

Ah: ZK version DOES matter! Using ZK8 i have no issues but i do with ZK7 - on my example. digging

gganassin ( 2016-03-03 13:45:12 +0800 )edit

William, is the point of getting x times the same value in x cells where x is the amount of items in the list? Try explaining what your requirements are so we can help you correct.

chillworld ( 2016-03-03 14:33:14 +0800 )edit

OK I'm ZK7 still atm, thanks for digging gganassin. I'll do something else than until i migrate my application.

WilliamB ( 2016-03-04 08:38:14 +0800 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2016-03-03 13:49:50 +0800

gganassin gravatar image gganassin flag of Luxembourg
540 6
http://www.hybris.com/

Try with this

<cell forEach="${elemSvc.listTests}" >
    <textbox value="@bind(elemSvc.listTests[0].value)"  />
</cell>

Giovanni

link publish delete flag offensive edit

Comments

the [] notation is part of the standard EL : http://stackoverflow.com/tags/el/info (paragraph on "Brace notation")

cor3000 ( 2016-03-04 01:28:58 +0800 )edit

Great, now how can I retrieve the index of my forEach.

@bind(elemSvc.listTests[forEachStatus.index].value returns a org.zkoss.zk.ui.UiException: null Caused by: java.lang.IllegalArgumentException: null

WilliamB ( 2016-03-07 09:49:27 +0800 )edit

Is there a way for me to declare a variable in my zul that I'll be able to reuse ?

WilliamB ( 2016-03-07 10:01:24 +0800 )edit

there is no need to use the index... just use value="@bind(each.value)" if you want a static index, use [0]

cor3000 ( 2016-03-07 10:10:30 +0800 )edit

Cor I don't think forEach works with @bind, only with ${}

And I need to use forEach instead of children because i want to generate a dynamic number of column : http://forum.zkoss.org/question/100296/grid-dynamic-number-of-cells/

WilliamB ( 2016-03-07 10:27:41 +0800 )edit
0

answered 2016-03-03 10:42:40 +0800

Darksu gravatar image Darksu
1991 1 4

Hello WilliamB,

The question is what type is your field, and what is the test input value you are using to save.

This is because you are getting a NumberFormatException.

Best Regards,

Darksu

link publish delete flag offensive edit

Comments

I'm getting a NumberFormatException on "get" call not on value

WilliamB ( 2016-03-03 10:52:56 +0800 )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
1 follower

RSS

Stats

Asked: 2016-03-03 10:29:14 +0800

Seen: 26 times

Last updated: Mar 03 '16

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