You cannot assign to a final variable and only final variables can be referenced from inside the enclosed type. You can however mutate final variables from inside the enclosed type.
If the DataView
is not immediately available you may need a blocking queue which will block until it becomes available:
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
final BlockingQueue<DataView> dataViews = new ArrayBlockingQueue<DataView>();
Form<?> form2 = new Form<Void>("form2") {
@Override
protected void onSubmit() {
...
dataViews.offer(new DataView("listview", new ListDataProvider(list)));
...
}
};
//form is submitted in a different thread somewhere between here and add
...
add(dataViews.take());
Now it is impossible to tell from the context you gave us but the simplest solution, which doesn't require any final variables, would be to just call add(dataView)
inside submit like so:
Form<?> form2 = new Form<Void>("form2") {
@Override
protected void onSubmit() {
...
DataView dataView = new DataView("listview", new ListDataProvider(list));
add(dataView);
...
}
};