Reputation: 157
Very new to Wicket but have very basic Java. I am not understanding how "result" is not been used as I have used it in an AjaxButton function
The quickfix says to provide a getter and setter, which I did (have removed now) but still nothing happened when I click the OK button
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>
Hoping (according to book Enjoying web development with Wicket) to double the input but when I click on OK and nothing happens.
Also in code I am getting a compile error with @Override, once this is removed I can compile and load webpage. Are they related??
Wicket Ajax Debug window info: INFO: focus removed from
INFO: focus set on
INFO: focus removed from
INFO: focus set on wicketDebugLink
INFO: focus removed from wicketDebugLink
INFO: focus set on ok2
INFO: Received ajax response (69 characters)
INFO:
INFO: Response processed successfully.
INFO: refocus last focused component not needed/allowed
ETA I changed from private to public and that error is gone but clicking ok still doesn't work and new error has come: The method onSubmit(AjaxRequestTarget, Form) from the type new AjaxButton(){} is never used locally
Upvotes: 1
Views: 429
Reputation: 157
Version 8 of wicket doesn't have the "form" parameter so it can be deleted:
new code
AjaxButton ok = new AjaxButton("ok") {
@Override
protected void onSubmit(AjaxRequestTarget target) {
result= 2*num;
target.add(r);
}
Upvotes: -1
Reputation: 17533
You need to call r.setOutputMarkupId(true)
if you want to update a Component via Ajax.
1) if javac (or your IDE) says that @Override
does not override anything then most probably you have a typo somewhere and you need to fix it, i.e. to properly override the method from super
2) never leave #onError()
empty. As a minimum add some basic logging in it to notify you that there is a validation error. Maybe #onSubmit()
is not called at all. The best would be to have a FeedbackPanel in the page and you should update it in #onError()
- target.add(feedbackPanel)
3) Check the browser's Dev tools Console for JavaScript errors. I'd expect Wicket complaining that it cannot find an HTML element with id rXY
(where XY
is a number) because of the missing r.setOutputMarkupId(true)
Upvotes: 2