You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Singh Mukesh <Mu...@nsb.no> on 2008/11/20 11:30:01 UTC

page refresh cleans my page state

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: mukeshs2@nsb.no
http://servicedesk.arrive.no



SV: page refresh cleans my page state

Posted by Singh Mukesh <Mu...@nsb.no>.
Hi 

I have gone through the HybridUrlCodingStrategy. The HybridUrlCodingStrategy is working porperly in WebApplication but not in portal environment. In WebApplication it retain the page state but not in portal environment.

Please suggest what should I do in portal environment.

Thanks in advance.
 


Med vennlig hilsen

MUKESH SINGH
CAPGEMINI Consultant
Arrive AS
T (+47) 46 47 90 16
E-post: mukeshs2@nsb.no



-----Opprinnelig melding-----
Fra: jWeekend [mailto:jweekend_forums@cabouge.com] 
Sendt: 20 November 2008 14:25
Til: users@wicket.apache.org
Emne: Re: page refresh cleans my page state


Singh,

Take a look at  http://cwiki.apache.org/WICKET/url-coding-strategies.html
HybridUrlCodingStrategy .

Regards - Cemal
http://www.jWeekend.co.uk http://jWeekend.co.uk 


Singh Mukesh 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>
> 	 # + &nbsp;0
> 	<p class="portlet-font">Denne portleten har hashCode lik 34563.</p>
> 	<p class="portlet-font"><input type="checkbox" class="portlet-form-field"
> wicket:id="versioned"> Versjonert</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: mukeshs2@nsb.no
> http://servicedesk.arrive.no
> 
> 
> 
> 

--
View this message in context: http://www.nabble.com/page-refresh-cleans-my-page-state-tp20598492p20601031.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


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


Re: page refresh cleans my page state

Posted by jWeekend <jw...@cabouge.com>.
Singh,

Take a look at  http://cwiki.apache.org/WICKET/url-coding-strategies.html
HybridUrlCodingStrategy .

Regards - Cemal
http://www.jWeekend.co.uk http://jWeekend.co.uk 


Singh Mukesh 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>
> 	 # + &nbsp;0
> 	<p class="portlet-font">Denne portleten har hashCode lik 34563.</p>
> 	<p class="portlet-font"><input type="checkbox" class="portlet-form-field"
> wicket:id="versioned"> Versjonert</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: mukeshs2@nsb.no
> http://servicedesk.arrive.no
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/page-refresh-cleans-my-page-state-tp20598492p20601031.html
Sent from the Wicket - User mailing list archive at Nabble.com.


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


Re: page refresh cleans my page state

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
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 <Mu...@nsb.no> 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: mukeshs2@nsb.no
> http://servicedesk.arrive.no
>
>
>