Wire Variables"
From Documentation
m (→ID Space) |
|||
Line 31: | Line 31: | ||
<source lang="java" high="2"> | <source lang="java" high="2"> | ||
− | public class PasswordSetter extends | + | public class PasswordSetter extends SelectorComposer { |
− | private User user; | + | @WireXel |
+ | private User user; | ||
+ | @Wire("#password") | ||
private Textbox password; //wired automatically if there is a textbox named password | private Textbox password; //wired automatically if there is a textbox named password | ||
− | public void | + | @Listen("onClick=#submit") |
+ | public void submit() { | ||
user.setPassword(password.getValue()); | user.setPassword(password.getValue()); | ||
} | } |
Revision as of 08:59, 7 December 2011
Wiring Sequence
GenericForwardComposer will wire members defined in the composer. Here is the sequence:
- It searches any setters if its name matches any of the following
- Any fellow with the same name (Component.getFellow(String))
- Any variable defined in Page.addVariableResolver(VariableResolver) with the same name
- Any variable defined in zscript with the same name
- Any implicit object with the same name
- Then, it searches any field to see if it matches any fellow, any variable,... the same as the above.
Wire Components
CSS3 Selectors
Wire Variables defined Variable Resolver
Wire Spring-managed Beans
Because the variable resolver will be checked when wiring a variable, you could wire a managed bean by declaring a built-in variable resolved called DelegatingVariableResolver.
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<window apply="foo.MyComposer">
...
<textbox id="password"/>
...
<button id="submit" label="Change"/>
</window>
Then, if a data member's name matches a Spring-managed bean, it will be wired automatically too. For example,
public class PasswordSetter extends SelectorComposer {
@WireXel
private User user;
@Wire("#password")
private Textbox password; //wired automatically if there is a textbox named password
@Listen("onClick=#submit")
public void submit() {
user.setPassword(password.getValue());
}
}
Wire Variables defined in zscript
Version History
Version | Date | Content |
---|---|---|