【发布时间】:2013-07-22 08:24:02
【问题描述】:
我有一个表单,还有一个 TextField。我在表单中添加了按钮,与默认提交不同。单击TextField旁边的按钮后,我想使用Ajaxformcomponentupdatingbehavior从TextField中获取值。
我的代码如下:
private String string;
...
public ..() {
Form form = new Form("form") {
@Override
protected void onSubmit() {
//some code
};
add(form);
TextField textField = new TextField("string", new PropertyModel<String>(this,"string"));
textField.setOutputMarkupId(true);
form.add(textField);
Button button = new Button("evalButton");
form.add(button);
button.add(new AjaxFormComponentUpdatingBehavior("onclick") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
System.out.print(textField.getValue());
}
});
TextField的值为null,第二次点击按钮后,我得到正确的值。一键点击后如何获取TextField的值?
【问题讨论】: