在浏览器刷新中刷新wicket面板 [英] Refreshing a wicket Panel in browser refresh

查看:174
本文介绍了在浏览器刷新中刷新wicket面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在付费角色系统上工作,一旦用户刷新浏览器,我需要刷新该页面中可用的统计数据(统计数据应该从数据库和显示中获取)。但是现在它无法正常工作,在页面刷新中,不会调用java代码,而是使用以前的数据加载缓存页面。
我尝试修复它添加下面的代码,但它不起作用。

Im working on a pay-role system, and once the user refreshes the browser i need to refresh the statistics available in that page (the stats should be taken from the DB and display). But right now it doesn't work properly, cos in page refresh the java code doesn't get invoked but loads the cached page with the previous data. I tried fixing it adding the below code but it didn't work as well.

@Override
protected void setHeaders(WebResponse response) { 
    response.setHeader("Cache-Control",
            "no-cache, max-age=0,must-revalidate, no-store");
}

任何人都知道修复此问题?
谢谢!


这是初始代码


ManageCredits.html

Anyone knows the fix for this? Thanks!
This was the initial code

ManageCredits.html

 <wicket:head>
  <wicket:link>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
  </wicket:link>
</wicket:head>
<wicket:panel xmlns:wicket="http://wicket.apache.org/">
        <div class="offercount-container round-border">
        <div class="manage-credits-lbl"><span>Manage Credits</span></div>

                <div>
                <ul>
                     <li>Balance amout:<span wicket:id="balanceAmtLbl" >0</span></li>
                     <li>Number if transactions<span wicket:id="transactionLbl" >0</span></li>
                   </ul>
                </div>
        </div>
</wicket:panel>


ManageCredits.java


ManageCredits.java

    import com.payrole.service.Offer;
import com.payrole.service.OfferService;
import com.payrole.service.ServiceLocator;
import com.payrole.wicket.PayroleLabel;
import java.text.Format;`enter code here`
import org.apache.wicket.markup.html.panel.Panel;

public class OfferFanSummaryPanel extends Panel{      
        private long balance;
        private long transactionCount;

        public OfferFanSummaryPanel(String id){
            super(id);
        }
        public OfferFanSummaryPanel(String id, Offer offer) {
                super(id);
                balance = (client.getBalance()==null) ? 0 : client.getBalance();
                transactionCount = (client.getTransactionCount()==null) ? 0 : client.getTransactionCount();
                initTransactionSummary();              
        }
        private void initTransactionSummary(){
                PayroleLabel balanceAmtLbl = new PayroleLabel("balanceAmtLbl", String.valueOf(balanceAmt), PayroleLabel.NUMBER);
                add(balanceAmtLbl);
                PayroleLabel transactionLbl = new PayroleLabel("transactionLbl", String.valueOf(transaction), PayroleLabel.NUMBER);
                add(transactionLbl);                
        }     
}


推荐答案

你必须使用动态模型。例如,如果您使用类似

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

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

您将始终显示相同的字符串:您为标签提供<$的结果c $ c> person.getName()。而是必须使用模型实现来计算每个渲染请求的值,例如 PropertyModel AbstractReadOnlyModel getObject()重写。

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在页面上只创建一次组件,并且每个请求都要求组件自行呈现。我猜你的代码不会被调用,因为它在构造函数中或 onInitialze()组件(页面,面板)。

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.

编辑:正如猜测的那样,您使用的是静态模型(具有固定值的模型,而不是在每个渲染上计算其值的模型)请求)。我在你的代码中没有看到emailFanCount和openCount来自哪里,但假设这些以某种方式计算。尝试在其中一个对象(客户端,...)上使用PropertyModel,或者向您的面板添加 public String getXXX(){} 并构建与此类似的标签:

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"));

其中是Panel。

看看中的nofollow>获得解释

Have a look in in the Wicket Wiki for an explanation

这篇关于在浏览器刷新中刷新wicket面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆