-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
in the following example-code the binding for the textbox with use-attribute doesn't work.
When i don't use the use-attribute everything works fine.
When i set the use-attribute without using EL everything works... (use="view.MyTextbox").
Can anybody tell me why Spring + EL + Annotations doesn't work?
Here is my example-code:
spring-config.xml:
<beans ...> <bean id="myController" class="ui.impl.MyControllerImpl" scope="prototype"/> <bean id="myTextbox" class="view.MyTextbox" scope="prototype" /> </beans>
index.zul:
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <window title="Hello World!!" border="normal" width="100%" apply="${myController}"> <textbox value="@{person.name}" use="${myTextbox}"/> <textbox value="@{person.surname}" /> <button id="btn_save" label="Save" /> </window>
MyControllerImpl.java:
public class MyControllerImpl extends GenericForwardComposer { private DataBinder binder; private Person test; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); binder = new AnnotateDataBinder(comp); test = new Person("Chuck", "Norris"); binder.bindBean("person", test); binder.loadAll(); } }
Best regards
tomCat
Does MyTextbox implements the clone() method? .
DataBind uses the clone() the create the components, so it might work, never tried this though...
If it work please report back here.
BTW you can't create Person Chuck Norris, Person Chuck Norris created you. =)
Regards
Madruga
do 2 things:
in your zul:
<textbox value="@{win$composer.person.name}" use="${myTextbox}"/> <textbox value="@{win$composer.person.surname}" />
Note: win$composer is a variable added by GenericForwardComposer
in your controller:
public Person getPerson() { return person ; }
personally, rather than creating my binder in doAfterCompose(...), I just put it in the zul:
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" arg0="myWin" ?> <window id="myWin" title="Hello World!!" border="normal" width="100%" apply="${myController}"> <textbox value="@{person.name}" use="${myTextbox}"/> <textbox value="@{person.surname}" /> <button id="btn_save" label="Save" /> </window>
hth,
Cary
Hi caclark & madruga0315,
thanks for your tips
i tried both solutions, neither worked...
@madruga0315
My MyTextbox is quite simple:
MyTextbox.java:
public class MyTextbox extends Textbox { @Override public void setValue(String value) throws WrongValueException { System.out.println("setValue: " + value); super.setValue(value); } @Override public String getValue() throws WrongValueException { System.out.println("getValue..."); return super.getValue(); } }
So there is not much i can implement in the clone method.
I also tried to rename my Person Object to "Bruce Lee" ;)
@caclark
I also tried to define the databinding inside my zul-file, but it didn't helped.
Furthermore i don't think that it is a problem of the way i defined my databinding, cause:
<textbox value="@{person.surname}" /> <-- works
and
<textbox value="@{person.name}" use="${myTextbox}"/> <-- doesn't work
Any more ideas?
Best regards
tomCat
Asked: 2009-09-21 12:28:59 +0800
Seen: 387 times
Last updated: Sep 22 '09