![](/img/trans.png)
[英]ImagePagerAdapter - The constructor is never used locally / The value of the field is not used
[英]Wicket issue field value never used
Wicket非常新,但是具有非常基本的Java。 我不了解如何在AjaxButton函數中使用過“結果”,
快速修復程序說要提供一個我已經做過的(現在已經刪除了)吸氣劑和設置器,但是當我單擊“確定”按鈕時仍然沒有任何反應
CalcPage.java:
public class CalcPage extends WebPage{
private int num;
private int result; // error:The value of the field CalcPage.result is not used
private Label r;
public CalcPage() {
Form<Void> f = new Form<Void>("f");
add(f);
f.add(new TextField<Integer>("num", new PropertyModel<Integer>(this, "num")));
AjaxButton ok = new AjaxButton("ok") {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
result = 2 * num;
target.add(r);
}
@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
}
};
f.add(ok);
r = new Label("r", new PropertyModel<Integer>(this, "result"));
add(r);
}
}
CalcPage.html
<html xmlns:wicket="http://wicket.apache.org">
<head>
<meta charset="utf-8" />
<title>Apache Wicket Quickstart</title>
<link href='https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:regular,bold' rel='stylesheet' type='text/css' />
<link rel="stylesheet" href="style.css" type="text/css" media="screen" title="Stylesheet" />
</head>
<body>
<form wicket:id="f">
<input type="text" wicket:id="num"/>
<input type="submit" value="OK" wicket:id="ok"/>
</form>
Result: <span wicket:id="r"></span>
</body>
</html>
希望(根據《用Wicket享受Web開發的樂趣》一書)將輸入加倍,但是當我單擊OK時,什么也沒有發生。
同樣在代碼中,我遇到@Override的編譯錯誤,一旦將其刪除,我就可以編譯並加載網頁。 他們有關系嗎?
Wicket Ajax調試窗口信息:信息:焦點從
INFO:重點放在
信息:焦點從
INFO:重點放在wicketDebugLink上
INFO:焦點從wicketDebugLink中刪除
INFO:重點放在ok2上
信息:收到ajax響應(69個字符)
信息:
INFO:響應已成功處理。
INFO:重新聚焦不需要/不允許的最后一個聚焦組件
ETA我從私有更改為公共,但該錯誤消失了,但單擊“確定”仍然不起作用,並且出現了新錯誤:new AjaxButton(){}類型的onSubmit(AjaxRequestTarget,Form)方法從未在本地使用
如果要通過Ajax更新組件,則需要調用r.setOutputMarkupId(true)
。
1)如果javac(或您的IDE)說@Override
不會覆蓋任何內容,則很可能您在某處輸入錯誤,並且需要對其進行修復,即從super正確覆蓋該方法
2)永遠不要將#onError()
空着。 至少要在其中添加一些基本日志記錄,以通知您存在驗證錯誤。 也許#onSubmit()
沒有調用#onSubmit()
。 最好的辦法是在頁面中添加一個FeedbackPanel,然后您應該在#onError()
中#onError()
更新#onError()
target.add(feedbackPanel)
3)檢查瀏覽器的開發工具控制台是否存在JavaScript錯誤。 我期望Wicket抱怨它由於缺少r.setOutputMarkupId(true)
而找不到ID為rXY
(其中XY
是數字)的HTML元素。
wicket的版本8沒有“ form”參數,因此可以將其刪除:
新密碼
AjaxButton ok = new AjaxButton("ok") {
@Override
protected void onSubmit(AjaxRequestTarget target) {
result= 2*num;
target.add(r);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.