-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi to all,
Consider the following simple zul:
<?page title="Welcome" contentType="text/html;charset=UTF-8"?> <?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" root="./winWelcome" ?> <script type="text/javascript"> function checkAttribute(element) { var component = document.getElementById(element.uuid); var attribute = component.getAttribute("MyAttribute"); alert(attribute); } </script> <zk xmlns:w="http://www.zkoss.org/2005/zk/client" xmlns:d="http://www.zkoss.org/2005/zk/client/attribute"> <window id="winWelcome" title="Welcome" border="normal" apply="controllers.WelcomeForm" width="450px" height="100%"> <textbox id="txtLogin" w:onFocus="checkAttribute(this)" /> </window> </zk>
And the composer:
package controllers; public class WelcomeForm extends GenericForwardComposer { private static final long serialVersionUID = 1L; /* * The data binder */ private AnnotateDataBinder binder; /* * Autowired components */ private Window winWelcome; private Textbox txtLogin; public void doAfterCompose(Component window) { try { super.doAfterCompose(window); } catch (Exception e) { e.printStackTrace(); } if (self != null) self.setAttribute("controller", this); txtLogin.setAttribute("d:MyAttribute", "my-attribute"); } public void onCreate$winWelcome(Event event) { binder = (AnnotateDataBinder) event.getTarget().getAttribute("binder", true); binder.loadAll(); } }
As you see what i am trying to do is to set the client-side attribute MyAttribute from the composer to the component txtLogin.
Unfortunately it doesn't work. Is there any other way to do this?
Thank you all
Cary, as you see i have declared the following namespace:
xmlns:d="http://www.zkoss.org/2005/zk/client/attribute"
I supposed that i had to set this attribute using the d prefix to declare it as a client-side attribute. Wrong. I found that it was quite easy to do this by using the following method:
txtLogin.setWidgetAttribute("MyAttribute", "my-attribute");
Thank you
txtLogin.setAttribute("d:MyAttribute", "my-attribute");
What's the "d:" for on the attribute name?
Asked: 2011-05-04 11:51:03 +0800
Seen: 399 times
Last updated: May 05 '11