-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all!
I´m fabricio from cuiabá - mato grosso - brazil i´m new on zk but not so new on java....
i would like to know how do you access your binded spring bean in a composer listener method...
something like this... you´ve a textbox with the value: @{springbean.name, save-when='self.onChange'}" and also a button whith an onClick event, so how to access the springbean instantiated object by the zkoss/spring integration variable resolver in your composer onClick method (or wherever else method if you don´t use a composer to listen de button onClick method) ???? tnx!!!
Resolving (Spring) variables is actually not supported by the @databinding. For EL's (${spring.value}) it's possible.
However i actually use this way:
1. Use the Composer, resolved by EL=Spring
<window apply="${exampleController}"..... (A)
The controller/composer looks like:
@Repository("exampleController") @Scope("prototype") // (B) there is some new under construction: idspace, desktop, page... public class ExampleController extends GenericForwardComposer { ...
2. Register the "dataholder" for the databinder controller and/or a modelclass
binder.bindBean("controller", this);
or
binder.bindBean("model", modelBean);
Note: For small functions, i use the controller as "dataholder". For bigger functions i use an own modelclass.
Your databinding has to be look like this:
<textbox value="@{model.user}"/>
or
<textbox value="@{controller.user}"/>
3. Offer getters (setters) for the binder (in the controller/modelclass)
public String getUser() { return user; }
You need to offer only the first level for the getters. i.E.
<textbox value="@{model.personBean.lastName}"/>
java:
@Autowired PersonBean personBean; // personBean could be injected by Spring or i.e. the PersonDAO public PersonBean getPersonBean() { return personBean; }
AB: Check this thread for some Springextensions "under contruction".
/Robert
BTW: While i wrote the post, i've got an idea how i could get springvariables directly from Spring w/o a getter. Check this post i a few days.
hummm ok thats beautiful
i´m doing rigth now like this:
<?page title="Usuários" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>
<zk>
<zscript>
import org.zkoss.zkplus.spring.SpringUtil;
import br.com.duralexsistemas.controller.UsuarioController;
UsuarioController control = SpringUtil.getBean("usuarioController");
</zscript>
<window title="Usuários" border="normal" width="150" height="150"
position="center">
<label value="Nome:" />
<textbox id="nome"
value="@{control.nome, save-when='self.onBlur'}" />
<label value="CPF:" />
<longbox id="CPF" maxlength="11"
value="@{control.cpf, save-when='self.onBlur'}" />
<label value="Senha:" />
<textbox id="Senha" type="password"
value="@{control.senha, save-when='self.onBlur'}" />
<button label="novo" onClick="control.onClickNovo()" />
</window>
</zk>
with no variable resolver and no composer... and seems to me good.... (until i do not need components informations on my bean). With spring integration improvments i´ll change it.
There are some differences with zscript:
- zscript requires no getter
- easy eventcoding
However, zscript (including the onXXXX-Code will be interpreted) so i don't use zscript for heavy usage functions.
/Robert
i see, but i dont pretend to get the zscript code bigger too.... thats just to declare the bean.. once that variable resolver is not working properly for my needs (like in an event listener method)... mvc is my objective... so, only declaring the controller in a view (even in zscript way) i think it´s ok
Asked: 2009-05-20 13:56:58 +0800
Seen: 461 times
Last updated: May 20 '09