AbstractPageableView calling IDataProvider.size() when it maybe shouldn't

2016-07-27 Thread Janos Cserep
Hi,

I noticed a possible inefficiency in AbstractPageableView's getItemModels() 
method:

/**
 * This method retrieves the subset of models for items in the current page 
and allows
 * RefreshingView to generate items.
 * 
 * @return iterator over models for items in the current page
 */
@Override
protected Iterator> getItemModels()
{
long offset = getFirstItemOffset();
long size = getViewSize();

Iterator> models = getItemModels(offset, size);

models = new CappedIteratorAdapter(models, size);

return models;
}

The getViewSize() method will issue a getRowCount() call which in DataViewBase 
will call the size() method of the DataProvider: 

public long getViewSize()
{
return Math.min(getItemsPerPage(), getRowCount() - 
getFirstItemOffset());
}

As far as I can see, this happens so that the call to getItemModels(offset, 
size) would not ask for more items, than there is in the underlying provider. 

However, ListDataProvider defends against getting more items than present in 
the list:


@Override
public Iterator iterator(final long first, final long count)
{
List list = getData();

long toIndex = first + count;
if (toIndex > list.size())
{
toIndex = list.size();
}
return list.subList((int)first, (int)toIndex).listIterator();
}

Also databases can handle a LIMIT clause that asks for more rows than present 
in the dataset.

The reason I was looking at this code is a DataView element I'm using on the 
front page of a public web application that fetches and displays the N most 
recent entries from a comment table without any paging components added to the 
DataView and I was seeing a simple "SELECT count(id) FROM comment"-like query 
taking 9% of all sql time according to JavaMelody for the last few days. 

I've changed the implementation by overriding the getItemModels() method to 
call directly getItemsPerPage instead of getViewSize and it got rid of the 
count selects and everything else seems to be working fine.

I'm wondering if there is maybe some other reason why getItemModels() is 
calling getViewSize instead of getItemsPerPage that I've missed. If not should 
I create a ticket in jira? 

Thanks,

Janos

--
pilar.hu




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Link - open modal on left click, new tab/window on right-click/context

2016-07-27 Thread sorinev
Changing the href worked. But it opens the page on both a left click and a
right click -> new tab. This may be related to the second part having no
effect (stopping the propagation), which may in turn be related to the third
part. Since I don't really know javascript, I'm not sure what needs to go
there. 

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Link-open-modal-on-left-click-new-tab-window-on-right-click-context-tp4675216p4675227.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Refreshingview vs ListView

2016-07-27 Thread Entropy
I replaced the RefreshingView with a PropertyListView again, and it fixed the
validation message issue.  All other changes were still there. 
Unfortunately, it also breaks my new feature as the ListView won't update on
Save.

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Refreshingview-vs-ListView-tp4675224p4675226.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Single Page Applications (SPA), Wicket and the history ajax back issue

2016-07-27 Thread Wayne W
Hi Martin,

many thanks for this - I will have a look (just got back from a trip hence
delay!)


On Sun, Jul 17, 2016 at 9:05 AM, Martin Grigorov 
wrote:

> Hi,
>
> You might be also interested in Wicketstuff UrlFragment project (
>
> https://github.com/wicketstuff/core/blob/723bf245a7a9619c670fa493d541fcd9feae92bd/urlfragment-parent/README.md
> )
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Sat, Jul 16, 2016 at 10:31 PM, Martin Grigorov 
> wrote:
>
> > Hi,
> >
> > Here is a small demo application:
> > https://github.com/martin-g/blogs/tree/master/ajax-history
> > It uses HTML5 History API directly, so it won't work on old Internet
> > Explorers!
> > If you need to support old IE, good luck finding a decent JS library.
> > AFAIK https://github.com/browserstate/history.js is one of the best out
> > there, but looking at the number of open issues and PRs I wouldn't use it
> > in my applications.
> >
> > The demo application shows how to support Ajax history for "Ajax menu"
> use
> > case from the earlier mails in this thread. In the past I have used
> > something similar for Ajax pagination functionality.
> > The menu items show how to change the url's path, query string and/or
> > fragment
> > The impl just triggers the respective JS event on the respective Ajax
> > component for the history event. The rest is normal Wicket Ajax request.
> As
> > noted in the previous mail by clicking the browser's back button you will
> > not ask Wicket to load an old version of the page! From Wicket point of
> > view the navigation in the page always goes forward!
> >
> > This implementation is not in Wicket itself because I am sure it is not
> > generic enough for everyone's use cases (and because History API is not
> > available in old IEs!).
> > if you need help with a use case that doesn't work with this impl then
> > please create a demo application and I'll try to help!
> > If one day the implementation is generic enough it may land in Wicket!
> >
> > Have fun!
> >
> > Martin Grigorov
> > Wicket Training and Consulting
> > https://twitter.com/mtgrigorov
> >
> > On Wed, Jul 13, 2016 at 10:55 AM, Wayne W 
> > wrote:
> >
> >> Hi,
> >>
> >> On Thu, Jul 7, 2016 at 11:28 PM, Martin Grigorov <
> >> martin.grigo...@gmail.com>
> >> wrote:
> >>
> >> > Hi,
> >> >
> >> > It seems you use Wicket for several years now and you have no idea how
> >> to
> >> > use it!
> >> >
> >>
> >>
> >> Yes perhaps Martin, I do try but there's a lot too it.
> >>
> >>
> >> >
> >> > I have done this for a client of mine 4 years ago.
> >> > And I have explained how to do it few times in the mailing lists.
> >> > You could use HTML5 History API to manipulate the browser url on each
> >> Ajax
> >> > call. If you need to support old browsers (why?! almost no one does
> >> these
> >> > days) then you should use some JS library that falls back to using the
> >> > location fragment/hash.
> >> > The support of "back/forward" buttons is just registering an
> >> > AjaxEventBehavior that listens for "popState"/"hashchange" event.
> >> >
> >> >
> >> I did some extensive searching and only found a couple of threads about
> >> this:
> >>
> >>
> >>
> http://apache-wicket.1842946.n4.nabble.com/Wicket7-History-API-support-for-navigable-AJAX-pages-components-td4660502.html
> >>
> >>
> >> The main issue seems that the page map is not updated (just overriden)
> for
> >> ajax requests from my reading before. I came to the conclusion trying to
> >> get wicket to support the back button would be difficult and somewhat
> >> hacky. It seems we'd end up with unknown behaviour and issues possibly
> >> occurring and therefore too much of a risk. Hence this thread.
> >>
> >>
> >>
> >> >
> >> > I will try to find time to write a blog article with a demo app at
> >> > wicketinaction.com soon.
> >> >
> >> >
> >>
> >> That would be great.
> >>
> >>
> >>
> >>
> >> >
> >> >
> >>
> >
> >
>


Refreshingview vs ListView

2016-07-27 Thread Entropy
We have a section written by another developer who is gone that I am
attempting to modify.  It was a ListView where items are added via a plus
button, and all items are editable.  A new requirement came down to modify
some text in the fields on save.  

I modified the fields as we saved, then add the container to the target and
made the Listview a RefreshingView.  This gets the behavior I want, but now
our validation messages near the boxes no longer show (the message at the
top saying there ARE error does still show, so the validators are running,
just not showing).  Also, when I modify a box for update, and then hit our
plus button to add a row, the updates revert back to their last saved state.

I double checked, the ListView variant of the page did not have these
issues.  Looking at a beyond compare of the changes, I feel like the change
from listView to RefreshingView was far and away the most significant
change, and that is where I am focusing for now.  I notice his ListView had
setReuseItems(true).  I tried setting the
RefreshingView.setItemReuseStrategy to both the reuse and default strategies
and neither made a difference.

Can anyone give me a pointer?  Does this symptom make you suspect a
particular mistake I might have made?

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Refreshingview-vs-ListView-tp4675224.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: getJsValuesAfterRendering

2016-07-27 Thread Damianos Metallidis

great!thanks!


On 7/27/2016 1:45 PM, Martin Grigorov wrote:

On Wed, Jul 27, 2016 at 12:38 PM, Damianos Metallidis 
wrote:
Hello,

Thanks for the response as this helped a lot to understand.

Now i am doing the following,

On the server-side i have put the below code which gets an
ajaxRequestTarget after the page is loaded:

this.add(new AjaxEventBehavior("load") {
 @Override
 protected void onEvent(AjaxRequestTarget ajaxRequestTarget) {
 StringValue connectEnd =
ajaxRequestTarget.getPageParameters().get("window.performance.timing.connectEnd");
 System.out.println("ConnectEnd equals to : " +
connectEnd.toString());
 }
 });

But the string i get is still null. Should i also pass them somehow
through my .html page?


Yes.
You should send them with something like:
https://github.com/apache/wicket/blob/e79fcb8787187108e8a16b2ae9ababecfcc76cf2/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxNewWindowNotifyingBehavior.java#L97-L98



Any help appreciated :)

Regards,
Damian

On 7/27/2016 10:23 AM, Martin Grigorov wrote:


Hi,

Here is the order:
- Wicket generates the HTML at the server side (onConfigure(),
onBeforeRender(), onRender(), onAfterRender())
- Wicket writes the HTML to the HTTP response
- the HTML is rendered by the browser (i.e. the timings happen at that
phase!)

To get the values at the server you need to add AjaxEventBehavior("load")
to your page, so that it fires when the browser has fully rendered/loaded
the HTML. This behavior should collect the data you need and send it to
the
server.


https://github.com/apache/wicket/blob/e79fcb8787187108e8a16b2ae9ababecfcc76cf2/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxNewWindowNotifyingBehavior.java
is doing something similar. It reads 'window.name' and sends it to the
server to notify the application when the same page instance is loaded in
more than one tabs in the browser. You can use it as inspiration.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Jul 26, 2016 at 9:38 PM, Damianos Metallidis <
metalidi...@gmail.com>
wrote:

Hello to all,

I have used the library of timing.js(
https://github.com/addyosmani/timing.js/) and it's very handy. I want to
ask you although one question.

I am running the above client library the client side of a localhost
webapp. The thing is that i want to get the these javascript values on my
server-side code. I am using wicket in the front-end.
Is it possible to retrieve them? For example to get the
/window.performance.timing.connectEnd

/My problem here is that the page should be rendered to have the values
of
timing available.
Perhaps any suggestion?
I have used the onAfterRender() method but it returns me null:

   @Override
  protected void onAfterRenderChildren()
  {
  super.onAfterRenderChildren();
//StringValue ce =

RequestCycle.get().getRequest().getRequestParameters().getParameterValue("window.performance.timing.connectEnd");

 System.out.println(ce .toString()); // it's null...
}

My best regards,
Damian



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org





-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: getJsValuesAfterRendering

2016-07-27 Thread Martin Grigorov
On Wed, Jul 27, 2016 at 12:38 PM, Damianos Metallidis  wrote:

> Hello,
>
> Thanks for the response as this helped a lot to understand.
>
> Now i am doing the following,
>
> On the server-side i have put the below code which gets an
> ajaxRequestTarget after the page is loaded:
>
> this.add(new AjaxEventBehavior("load") {
> @Override
> protected void onEvent(AjaxRequestTarget ajaxRequestTarget) {
> StringValue connectEnd =
> ajaxRequestTarget.getPageParameters().get("window.performance.timing.connectEnd");
> System.out.println("ConnectEnd equals to : " +
> connectEnd.toString());
> }
> });
>
> But the string i get is still null. Should i also pass them somehow
> through my .html page?
>

Yes.
You should send them with something like:
https://github.com/apache/wicket/blob/e79fcb8787187108e8a16b2ae9ababecfcc76cf2/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxNewWindowNotifyingBehavior.java#L97-L98


> Any help appreciated :)
>
> Regards,
> Damian
>
> On 7/27/2016 10:23 AM, Martin Grigorov wrote:
>
>> Hi,
>>
>> Here is the order:
>> - Wicket generates the HTML at the server side (onConfigure(),
>> onBeforeRender(), onRender(), onAfterRender())
>> - Wicket writes the HTML to the HTTP response
>> - the HTML is rendered by the browser (i.e. the timings happen at that
>> phase!)
>>
>> To get the values at the server you need to add AjaxEventBehavior("load")
>> to your page, so that it fires when the browser has fully rendered/loaded
>> the HTML. This behavior should collect the data you need and send it to
>> the
>> server.
>>
>>
>> https://github.com/apache/wicket/blob/e79fcb8787187108e8a16b2ae9ababecfcc76cf2/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxNewWindowNotifyingBehavior.java
>> is doing something similar. It reads 'window.name' and sends it to the
>> server to notify the application when the same page instance is loaded in
>> more than one tabs in the browser. You can use it as inspiration.
>>
>> Martin Grigorov
>> Wicket Training and Consulting
>> https://twitter.com/mtgrigorov
>>
>> On Tue, Jul 26, 2016 at 9:38 PM, Damianos Metallidis <
>> metalidi...@gmail.com>
>> wrote:
>>
>> Hello to all,
>>> I have used the library of timing.js(
>>> https://github.com/addyosmani/timing.js/) and it's very handy. I want to
>>> ask you although one question.
>>>
>>> I am running the above client library the client side of a localhost
>>> webapp. The thing is that i want to get the these javascript values on my
>>> server-side code. I am using wicket in the front-end.
>>> Is it possible to retrieve them? For example to get the
>>> /window.performance.timing.connectEnd
>>>
>>> /My problem here is that the page should be rendered to have the values
>>> of
>>> timing available.
>>> Perhaps any suggestion?
>>> I have used the onAfterRender() method but it returns me null:
>>>
>>>   @Override
>>>  protected void onAfterRenderChildren()
>>>  {
>>>  super.onAfterRenderChildren();
>>> //StringValue ce =
>>>
>>> RequestCycle.get().getRequest().getRequestParameters().getParameterValue("window.performance.timing.connectEnd");
>>>
>>> System.out.println(ce .toString()); // it's null...
>>> }
>>>
>>> My best regards,
>>> Damian
>>>
>>>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: getJsValuesAfterRendering

2016-07-27 Thread Damianos Metallidis

Hello,

Thanks for the response as this helped a lot to understand.

Now i am doing the following,

On the server-side i have put the below code which gets an 
ajaxRequestTarget after the page is loaded:


this.add(new AjaxEventBehavior("load") {
@Override
protected void onEvent(AjaxRequestTarget ajaxRequestTarget) {
StringValue connectEnd = 
ajaxRequestTarget.getPageParameters().get("window.performance.timing.connectEnd");
System.out.println("ConnectEnd equals to : " + 
connectEnd.toString());

}
});

But the string i get is still null. Should i also pass them somehow 
through my .html page?

Any help appreciated :)

Regards,
Damian
On 7/27/2016 10:23 AM, Martin Grigorov wrote:

Hi,

Here is the order:
- Wicket generates the HTML at the server side (onConfigure(),
onBeforeRender(), onRender(), onAfterRender())
- Wicket writes the HTML to the HTTP response
- the HTML is rendered by the browser (i.e. the timings happen at that
phase!)

To get the values at the server you need to add AjaxEventBehavior("load")
to your page, so that it fires when the browser has fully rendered/loaded
the HTML. This behavior should collect the data you need and send it to the
server.

https://github.com/apache/wicket/blob/e79fcb8787187108e8a16b2ae9ababecfcc76cf2/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxNewWindowNotifyingBehavior.java
is doing something similar. It reads 'window.name' and sends it to the
server to notify the application when the same page instance is loaded in
more than one tabs in the browser. You can use it as inspiration.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Jul 26, 2016 at 9:38 PM, Damianos Metallidis 
wrote:


Hello to all,
I have used the library of timing.js(
https://github.com/addyosmani/timing.js/) and it's very handy. I want to
ask you although one question.

I am running the above client library the client side of a localhost
webapp. The thing is that i want to get the these javascript values on my
server-side code. I am using wicket in the front-end.
Is it possible to retrieve them? For example to get the
/window.performance.timing.connectEnd

/My problem here is that the page should be rendered to have the values of
timing available.
Perhaps any suggestion?
I have used the onAfterRender() method but it returns me null:

  @Override
 protected void onAfterRenderChildren()
 {
 super.onAfterRenderChildren();
//StringValue ce =
RequestCycle.get().getRequest().getRequestParameters().getParameterValue("window.performance.timing.connectEnd");

System.out.println(ce .toString()); // it's null...
}

My best regards,
Damian




-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Link - open modal on left click, new tab/window on right-click/context

2016-07-27 Thread Martin Grigorov
Hi,

You can override onComponentTag() of this AjaxLink and do tag.put("href",
redirectUrl);
In addition you need to stop the propagation of the JS event: override
#updateAjaxAttributes() and do attributes.setEventPropagation(STOP)
One more thing you may need here is a precondition that checks whether it
is a left or right click. For this you can use:
attributes.getAjaxCallListeners().add(new
AjaxCallListener().onPrecondition("someJavaScriptThatUses attrs.event to do
the extra checks"))

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Jul 26, 2016 at 7:51 PM, sorinev  wrote:

> I have an AjaxLink on my page.
>
>
>
> and the modal side of it is:
>
>
>
> And this works just fine. When I click the link, a wicket modal window
> opens
> with the content of that modal being loaded from an external url.
>
> However, a request has been made to change the functionality slightly. When
> left clicking, the behavior should remain as is, but when right clicking on
> the link and choosing open in a new tab or window, it should open a new
> tab/window with that external url instead of popping up the modal. I've
> googled around and haven't found a way to do this.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Link-open-modal-on-left-click-new-tab-window-on-right-click-context-tp4675216.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: getJsValuesAfterRendering

2016-07-27 Thread Martin Grigorov
Hi,

Here is the order:
- Wicket generates the HTML at the server side (onConfigure(),
onBeforeRender(), onRender(), onAfterRender())
- Wicket writes the HTML to the HTTP response
- the HTML is rendered by the browser (i.e. the timings happen at that
phase!)

To get the values at the server you need to add AjaxEventBehavior("load")
to your page, so that it fires when the browser has fully rendered/loaded
the HTML. This behavior should collect the data you need and send it to the
server.

https://github.com/apache/wicket/blob/e79fcb8787187108e8a16b2ae9ababecfcc76cf2/wicket-core/src/main/java/org/apache/wicket/ajax/AjaxNewWindowNotifyingBehavior.java
is doing something similar. It reads 'window.name' and sends it to the
server to notify the application when the same page instance is loaded in
more than one tabs in the browser. You can use it as inspiration.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Jul 26, 2016 at 9:38 PM, Damianos Metallidis 
wrote:

> Hello to all,
> I have used the library of timing.js(
> https://github.com/addyosmani/timing.js/) and it's very handy. I want to
> ask you although one question.
>
> I am running the above client library the client side of a localhost
> webapp. The thing is that i want to get the these javascript values on my
> server-side code. I am using wicket in the front-end.
> Is it possible to retrieve them? For example to get the
> /window.performance.timing.connectEnd
>
> /My problem here is that the page should be rendered to have the values of
> timing available.
> Perhaps any suggestion?
> I have used the onAfterRender() method but it returns me null:
>
>  @Override
> protected void onAfterRenderChildren()
> {
> super.onAfterRenderChildren();
> //StringValue ce =
> RequestCycle.get().getRequest().getRequestParameters().getParameterValue("window.performance.timing.connectEnd");
>
>System.out.println(ce .toString()); // it's null...
> }
>
> My best regards,
> Damian
>