Thanks everybody. I finally managed to display the content of an active log
file.
As mentioned in the earlier responses, all you need is two labels.
*Markup*:
<div id="logData" wicket:id="logData"></div>
<div id="nextLog" wicket:id="nextLog"></div>
*Java*:
Create the "logData" label as you would normally create labels and load the
content of the log file.
Something like this:
private MultiLineLabel createLogData()
{
return new MultiLineLabel("logData", new
LoadableDetachableModel<Object>()
{
@Override
protected Object load()
{
try{
return FileUtils.readFiletoString(file);
}catch(Exception ex){}
return "";
}
});
}
And now the interesting component "nextLog". It might look something like
this:
private Label createNextLog()
{
Label nextLog = new Label("nextLog", new
LoadableDetachableModel<Object>()
{
@Override
protected Object load()
{
//use a tailing api like "Tailer" in commons-io or may be
just java.io.RandomAccessFile?
return "your 'tail' content goes here";
}
}){
// This is needed because, wicket created dynamic ids for the
"nextLog" component
@Override
public String getMarkupId(boolean createIfDoesNotExist)
{
return "nextLog";
}
};
nextLog.add(new
AjaxSelfUpdatingTimerBehavior(Duration.seconds(REFRESH_INTERVAL))
{
@Override
protected void onPostProcessTarget(AjaxRequestTarget target)
{
/*
* We are doing the following here:
* - append the content of "nextLog" to "logData"
* - remove "nextLog"
* - insert "nextLog" after "logData".
*/
target.appendJavascript(
"$('#logData').append('<p>' + $('#nextLog').text()
+ '</p>');" +
"$('#nextLog').remove();" +
"$(\"<div
id='nextLog'>\").insertAfter($('#logData'));");
}
});
nextLog.setOutputMarkupId(true);
return nextLog;
}
Thank you once again for each and everyone who took their time to give your
thoughts/suggestions. They were precious and I learned a lot by merely
interacting with this wonderful community.
On Mon, Nov 21, 2011 at 1:53 PM, James <[email protected]> wrote:
> Thanks Igor. You simplified it to the maximum.
> On Nov 21, 2011 1:36 PM, "Igor Vaynberg" <[email protected]> wrote:
>
>> a much simplified version:
>>
>> <div wicket:id="logData">log contents</div>
>> <div wicket:id="nextLog">next log call</div>
>>
>> no panel needed. add self-updating behavior to next log call and in
>> the callback also add
>>
>> target.appendjavascript( "$('#logdata).append($('#nextlog).content());
>> $('#nextlog').remove(); $('#logdata).insertafter($('<div
>> id='nextlog'>));" )
>>
>> im paraphrasing jquery here, but the is that you repaint the nextog
>> div and add javascript that after the repaint you move its contents to
>> the logdata div, and then empty the nextlog div. of course the nextlog
>> div should be hidden via css....
>>
>> -igor
>>
>>
>> On Sun, Nov 20, 2011 at 7:46 PM, Clint Checketts <[email protected]>
>> wrote:
>> > I'd need to look at Tailer to see how it operates. But here is how I'd
>> try
>> > it (it is quick and I don't like the markup, but we'll optimize it
>> later:
>> >
>> > Create a panel that looks like so (we'll call it LoggingPanel):
>> >
>> > <wicket:panel>
>> > <div wicket:id="logData">log contents</div>
>> > <div wicket:id="nextLog">next log call</div>
>> > </wicket:panel>
>> >
>> > Add a self updating timer behavior so the panel check the Tailer for
>> > output, if there is data, then update the logData label with it, make
>> the
>> > nextLog component be another LoggingPanel with a
>> SelfUpdatingTImerBehavior,
>> > and stop the timerbehavior on the current panel.
>> >
>> > Drawbacks are: the divs keep getting nested, so the markup isn't the
>> most
>> > beautiful, so setRenderBodyOnly(true) might make it nicer.
>> >
>> > -Clint
>> >
>> > On Sun, Nov 20, 2011 at 9:27 PM, James <[email protected]>
>> wrote:
>> >
>> >> Thanks Steve. I'll look into the commons-io "Tailer".
>> >> But any idea on how to use this with wicket?
>> >>
>> >> On Mon, Nov 21, 2011 at 11:10 AM, Steve Swinsburg <
>> >> [email protected]
>> >> > wrote:
>> >>
>> >> > I've done something similar to this using the Tailer class from
>> >> commons-io.
>> >> >
>> >> > cheers,
>> >> > Steve
>> >> >
>> >> >
>> >> > On 21/11/2011, at 12:59 PM, James wrote:
>> >> >
>> >> > > Dear wicket community,
>> >> > >
>> >> > > In a project that I'm working on, I need to build a "live log
>> viewer"
>> >> or
>> >> > > "dynamic log viewer" or "refreshable log viewer".
>> >> > > Much like how hudson/jenkins displays the console output.
>> >> > >
>> >> > > The idea is to dynamically display the new data added to a log file
>> >> along
>> >> > > with the existing content.
>> >> > >
>> >> > > How to go about doing this? Please throw some light on this.
>> >> > >
>> >> > > I searched about this in the web, mailing lists but couldn't find
>> what
>> >> I
>> >> > > was looking for, so I'm posting it here.
>> >> > > If this is asked elsewhere, kindly re-direct me to the respective
>> >> > resource.
>> >> > >
>> >> > > --
>> >> > > Thanks & Regards,
>> >> > > James
>> >> > > A happy Wicket user
>> >> >
>> >> >
>> >> > ---------------------------------------------------------------------
>> >> > To unsubscribe, e-mail: [email protected]
>> >> > For additional commands, e-mail: [email protected]
>> >> >
>> >> >
>> >>
>> >>
>> >> --
>> >> Thanks & Regards,
>> >> James
>> >>
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
--
Thanks & Regards,
James