Create a process in Java bean, get the result and return to the web page

Suppose I have a Java bean named "Mainbean" that is used to process a request from a web page.

I want to create a "proc" process in this component and get the proc output, return it asynchronously to the web page and show it in the inputTextArea in JSF.

Since "proc" can have so many lines of output, I want to return them line by line and in real time, but not show them all after the process ends.

I used the following code to create a process and try to get the output. But it seems that the process failed to terminate normally because the exit value will always be -1.

builder = new ProcessBuilder("java", "-Xms1024m","-Xmx1024m","-Xss65536k","-cp ",spaceMaker,"SmartBridge", solution," ",this.specFile,"1000000");
proc = builder.start();
InputStream is = proc.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
returnValue  = proc.waitFor();

while ((line = br.readLine()) != null) {
    // Outputs your process execution
    System.out.println(line);
    this.metaOutput = this.metaOutput.concat(line);
    exit = proc.exitValue();
    if (exit == 0) {
        // Process finished
        break;
    }
    return output;
}

      

And in the JSF page I am using the following code:

<h:form>
    <h:inputTextarea id="processOutput" value="#{mainBean.metaOutput}" cols="80" rows="20">
        <f:ajax render="processOutput"/>
    </h:inputTextarea>
 </h:form>

      

My question is, how can I use these technologies to meet my high-level requirements? Of course the code examples will definitely help me.

+3


source to share


1 answer


If you are looking for a reverse ajax response type. You can use PRIMEFACES PUSH reverse ajax technology. Link here. PrimPush



+1


source







All Articles