简体   繁体   中英

JSF: How to implement an eclipse like console?

I'm trying to set up a console on a jsf webapplication. Currently I'm using a textarea to display the output. I want it to work like the console in eclipse. It should autoscroll down if new lines are added, but it should also be possible to deactivate autoscrolling. And that's the problem. After adding new lines the textarea always jumps up and doesn't stay at its current position.

I also tried to save the current position with scrollTop, but this didn't work out.

What's your suggestion to go on?

Primefaces has a good Terminal component. See the demo on their showcase here: http://www.primefaces.org/showcase/ui/misc/terminal.xhtml

To accomplish my goal I used two textareas. One hidden textarea which is autoupdated by a backingbean and another a visible textarea to which I copy the value by using javascript. The visible textarea may not be autoupdated or rerendered.

xhtml:

<p:inputTextarea 
       id="txtHiddenConsole"
       value="#{consoleLogBean.log}"
       pt:data-autoUpdate="true">
</p:inputTextarea >
<p:inputTextarea id="txtConsole" >

Javascript

log = $('#txtHiddenConsole').val();
$('#txtConsole').val(log);  

By using this workarround the scrollposition of the visible textarea won't be changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM