oh excuse me, textbox.getValue(), that's the problem of not having a fiddle and just write code here :)
chillworld ( 2015-03-26 16:26:48 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello,
i have the following problem:
I created a new macro component. It combines a textbox with a popup, that is always shown, when the textbox has focus.
myMacro.zul:
<zk>
<textbox id="textbox" value="${arg.value}" width="${empty arg.width ? '98%' : arg.width}"/>
<popup id="popup" width="200px" />
</zk>
<!-- It is registered in language-addon -->
For this Macro i created a HtmlMacroComponent class:
@ComponentAnnotation("value:@ZKBIND(ACCESS=both,SAVE_EVENT=onEdited)")
public class MyMacro extends HtmlMacroComponent {
private static final long serialVersionUID = 1L;
@Wire
private Textbox textbox;
@Wire
private Popup popup;
private Label label;
public MyMacro() {
label = new Label();
setMacroURI("/zul/components/myMacro.zul");
setStyle("display:block");
afterCompose();
popup.appendChild(label);
}
@Listen("onFocus=#textbox")
public void textboxFocus() {
label.setValue("some Text");
popup.open(textbox, "end_before");
}
}
In the .zul pages where i want to use the macro, i want to use @bind for a bean-field:
somePage.zul:
<myMacro value="@bind(vm.bean.field)" /> <!-- vm is the ViewModel Class -->
The Bean is a straightforward JPA-Entity.
My problem: the text i put into the textbox is not given to the bean (everything else works, the popup is shown and so on).
As an alternative to @ComponentAnnotation i found this: http://zkfiddle.org/sample/6sleo1/2-macro-with-manual-reference (link)
But it only works when using a macro component without a custom class. In my case i get a Property not found exception for the pojo.
I can't use @ref because we don't have PE or EE license.
Can someone help me?
ZK version is 6.5.3.
Hey viachris,
Your doing it quite good but you only make a few small mistakes.
In the zul you have :
<textbox id="textbox" value="${arg.value}"
Don't set the value there.(in the zul)
What you are doing is only a just set the value once and nothing more.
In addition of the first mistake, the value
has to go to the getter and setter of value.
So what you need in the Java class is :
public void setValue(String value) {
textbox.setValue(value);
}
public String getValue() {
return textbox.getValue();
}
@Listen("onChange=#textbox")
public void textboxChange() {
Events.postEvent("onEdited", this, textbox.getValue());
}
And normally this should work.
Hope this can help you further.
Maybe it's possible through the binder or something.
I have to look that up and try and error that.
Easy solution should be :
<myMacro value="@bind(vm.bean.field)" from="bean.field"/>
And in the class you create a getter and setter like :
private String from;
public void setFrom(String from) {
this.from = from;
}
public String getFrom() {
return from;
}
It's surely not the most cleanest way but it's the only way I can say directly without testing some stuff.
Greetz Chill.
oh excuse me, textbox.getValue(), that's the problem of not having a fiddle and just write code here :)
chillworld ( 2015-03-26 16:26:48 +0800 )editAsked: 2015-03-25 14:01:53 +0800
Seen: 38 times
Last updated: Mar 27 '15