0

Why Spring + EL + Annotations doesn't work?

asked 2009-09-21 12:28:59 +0800

tomCat gravatar image tomCat
276 3

updated 2009-09-21 13:22:43 +0800

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

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2009-09-21 13:59:11 +0800

tomCat gravatar image tomCat
276 3

Ok...
i debugged my code some more and annotated-binding for the textbox with use-attribute is completely ignored.
Is this a bug? Any suggestions?

Best regards

tomCat

link publish delete flag offensive edit

answered 2009-09-21 16:52:11 +0800

madruga0315 gravatar image madruga0315 flag of Brazil
937 2 12

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

link publish delete flag offensive edit

answered 2009-09-21 19:44:53 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

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

link publish delete flag offensive edit

answered 2009-09-22 07:14:05 +0800

tomCat gravatar image tomCat
276 3

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

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2009-09-21 12:28:59 +0800

Seen: 387 times

Last updated: Sep 22 '09

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