Refreshing a wicket Panel in browser refresh

牧云@^-^@ 提交于 2019-12-06 13:05:22

You have to use dynamic models. E.g., if you use something like

add(new Label("name", Model.of(person.getName()));

you will always have the same string displayed: you provide the label with the result of person.getName(). Instead you have to use a model implementation that calculates the value for each render request, for example PropertyModel or AbstractReadOnlyModel with getObject() overridden.

Wicket creates the components on your page only once and with each request asks the components to render themselves. I guess you code does not get called because it is in the constructor or onInitialze() of the component (page, panel).

If this is not clear enough, please post some code on what you are doing.

Edit: As guessed, you are using static Models (models, that have a fixed value, as opposed to models that calculate their value on each render request). I don 't see in your code where emailFanCount and openCount come from, but assuming that these get calculated somehow. Try using a PropertyModel on either one of you Objects (client,..) or, add a public String getXXX() {} to you panel and construct your label similar to this:

Label label = new Label("someID", new PropertyModel(this, "XXX"));

where this is the Panel.

Have a look in in the Wicket Wiki for an explanation

In your HTML, Add these lines in <head> tag :

  <meta http-equiv="cache-control" content="no-cache"/>
  <meta http-equiv="pragma" content="no-cache" />
  <meta http-equiv="expires" content="-1" />

This will force browser to retrieve details from server. You also may implement url rewriting to get data from server every time you refresh the page. Hope this helps.

The use of meta tags don't ensure you that an intermediate proxy won't cache the page. Try to use the "Cache-Control" header in combination with "Expires" that is a HTTP 1.0 header and all the browsers and proxies support.

From Wikipedia:

This header field (Cache-Control) is part of HTTP version 1.1, and is ignored by some caches and browsers. It may be simulated by setting the Expires HTTP version 1.0 header field value to a time earlier than the response time.

Here you have a good tutorial about HTTP caching.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!