Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating text area with wicket
    primarykey
    data
    text
    <p>I'm attempting to create something like a read-only console window using apache wicket. Essentially the users submits a form to kick off a server-side operation. Then can then track the job output on the page.</p> <p>I'm currently displaying the output as shown below:</p> <pre><code>public class ConsoleExample extends WebPage { protected boolean refreshing; private String output = ""; public void setOutput(String newOutput) { synchronized (this) { output = newOutput; } } public void appendOutput(String added) { synchronized (this) { this.output = output+added; } } public ConsoleExample() { Form&lt;ConsoleExample&gt; form = new Form&lt;ConsoleExample&gt;("mainform"); add(form); final TextArea&lt;String&gt; outputArea = new TextArea&lt;String&gt;("output", new PropertyModel&lt;String&gt;(this, "output")); outputArea.setOutputMarkupId(true); // A timer event to add the outputArea to the target, triggering the refresh outputArea.add(new AbstractAjaxTimerBehavior(Duration.ONE_SECOND){ private static final long serialVersionUID = 1L; @Override protected void onTimer(AjaxRequestTarget target) { synchronized (this) { if(refreshing ){ target.focusComponent(null); target.addComponent(getComponent()); } } } }); add(outputArea); form.add(new AjaxSubmitLink("run") { private static final long serialVersionUID = 1L; @Override public void onSubmit(final AjaxRequestTarget target, Form&lt;?&gt; form) { setOutput(""); new Thread(new Runnable() { @Override public void run() { try { refreshing = true; ProcessBuilder pb = new ProcessBuilder(Collections.singletonList("execute")); pb.redirectErrorStream(true); String line; BufferedReader br = new BufferedReader(new InputStreamReader(pb.start().getInputStream())); while ((line = br.readLine()) != null) { appendOutput("\n" + line); } } catch (IOException e) { //... } finally { //... refreshing = false; } } }).start(); } }); } </code></pre> <p>The problem with this solution is that each time the AjaxTimerBehaviorRuns the refresh resets the text area properties, namely, cursor position and scroll position. Therefore as the output increases the user can't track the output as the textarea jumps back to start every second.</p> <p>Is there a better way to achieve this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload