store the value on the session? make it a static member  variable or store
it at application level? it all depends on what you want: the value to
change independently for each user or be the "same" for all users...
Ernesto

On Thu, Nov 20, 2008 at 11:30 AM, Singh Mukesh <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I am using wicket. I have a page with one links which increase the counter
> value based on user click on the link, for all these actions I am using
> Ajax. For instance user click 5 times on link the counter shows value 5. It
> is ok but if I click on browsers refresh button all changes are lost and it
> shows the counter value 0 instead of 5. How to handle the refresh button?
>
> Please find the code below.
>
> TestPage.java
>
> import org.apache.wicket.PageParameters;
> import org.apache.wicket.ajax.AjaxRequestTarget;
> import org.apache.wicket.ajax.markup.html.AjaxLink;
> import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.markup.html.basic.Label;
> import org.apache.wicket.model.IModel;
> import org.apache.wicket.model.Model;
>
> public class TestPage extends WebPage {
>
>        public TestPage(PageParameters parameters) {
>                super(parameters);
>                final Model<Integer> modell = new Model<Integer>(new
> Integer(0));
>                // Slik at telleverdien legges i session
>                setDefaultModel(modell);
>                final Label telleLabel = new Label("teller", modell);
>                telleLabel.setOutputMarkupId(true);
>                final Label hashcodeLabel = new Label("hashcode", new
> IModel<String>() {
>                        private static final long serialVersionUID = 1L;
>
>                        public String getObject() {
>                                return
> String.valueOf(System.identityHashCode(TestPage.this));
>                        }
>
>                        public void setObject(String object) {
>                                /* NOOP */
>                        }
>
>                        public void detach() {
>                                /* NOOP */
>                        }
>
>                });
>                hashcodeLabel.setOutputMarkupId(true);
>                add(telleLabel);
>                add(new AjaxLink<Integer>("link", modell) {
>                        private static final long serialVersionUID = 1L;
>
>                        @Override
>                        public void onClick(AjaxRequestTarget target) {
>                                // Øk det delte modellobjektet
>                                Integer tall = getModelObject();
>                                int verdi = tall.intValue() + 1;
>                                tall = new Integer(verdi);
>                                setModelObject(tall);
>                                // Fortell klienten hvilken komponent som
> skal oppdateres
>                                target.addComponent(telleLabel);
>                                target.addComponent(hashcodeLabel);
>                        }
>                });
>                add(hashcodeLabel);
>                add(new AjaxCheckBox("versioned", new
> Model<Boolean>(Boolean.TRUE)) {
>                        private static final long serialVersionUID = 1L;
>
>                        @Override
>                        protected void onUpdate(AjaxRequestTarget target) {
>
>  setVersioned(this.getModelObject().booleanValue());
>                        }
>
>                });
>                setVersioned(true);
>        }
>
>
>
>
> }
>
>
>
> TestApplication.java
>
> import org.apache.wicket.Page;
> import org.apache.wicket.Request;
> import org.apache.wicket.Response;
> import org.apache.wicket.Session;
> import org.apache.wicket.protocol.http.WebApplication;
>
> public class TestApplication extends WebApplication {
>
>        @Override
>        public Class<? extends Page> getHomePage() {
>                return TestPage.class;
>        }
>
> }
>
> TestPage.html
>
> <html
>      xmlns="http://www.w3.org/1999/xhtml";
>      xmlns:wicket="http://wicket.apache.org/";>
> <!-- Basis-side som inneholder navigasjonssti -->
>        <head>
>        <title>Testside</title>
> </head>
> <body>
>        <a href="#" style="font: bold 12pt 'Arial'"
> wicket:id="link">+</a>&nbsp;<span wicket:id="teller">0</span>
>        <p class="portlet-font">Denne portleten har hashCode lik <b
> wicket:id="hashcode">34563</b>.</p>
>        <p class="portlet-font"><input type="checkbox"
> class="portlet-form-field" wicket:id="versioned"> <span
> class="portlet-form-label">Versjonert</span></p>
> </body>
> </html>
>
>
> Please suggest me the way how to handle the refresh button problem.
>
> Please do the needful.
>
>
> Med vennlig hilsen
>
> MUKESH SINGH
> CAPGEMINI Consultant
> Arrive AS
> T (+47) 46 47 90 16
> E-post: [EMAIL PROTECTED]
> http://servicedesk.arrive.no
>
>
>

Reply via email to