Last active
August 29, 2015 14:19
-
-
Save twendelmuth/f4eb64a99f54d41c8c56 to your computer and use it in GitHub Desktop.
WicketTester StackOverflow problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html xmlns:wicket="http://wicket.apache.org"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Apache Wicket Quickstart</title> | |
<link href='http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:regular,bold' rel='stylesheet' type='text/css' /> | |
<link rel="stylesheet" href="style.css" type="text/css" media="screen" title="Stylesheet" /> | |
</head> | |
<body> | |
<wicket:panel> | |
<div wicket:id="locales"> | |
<a wicket:id="link"><wicket:container wicket:id="label" /></a> | |
</div> | |
</wicket:panel> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.stackoverflow; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Locale; | |
import org.apache.wicket.Session; | |
import org.apache.wicket.ajax.AjaxRequestTarget; | |
import org.apache.wicket.ajax.markup.html.AjaxLink; | |
import org.apache.wicket.markup.html.basic.Label; | |
import org.apache.wicket.markup.html.list.ListItem; | |
import org.apache.wicket.markup.html.list.ListView; | |
import org.apache.wicket.markup.html.panel.Panel; | |
import org.apache.wicket.model.AbstractReadOnlyModel; | |
import org.apache.wicket.model.IModel; | |
import org.apache.wicket.model.StringResourceModel; | |
public class SwitchLocale extends Panel { | |
public SwitchLocale(String id) { | |
super(id); | |
add(new ListView<Locale>("locales", getLocales()) { | |
@Override | |
protected void populateItem(final ListItem<Locale> item) { | |
AjaxLink<Void> link = new AjaxLink<Void>("link") { | |
@Override | |
public void onClick(AjaxRequestTarget target) { | |
Session.get().setLocale(item.getModelObject()); | |
// Add whole page to update instead of single components | |
target.add(getPage()); | |
} | |
}; | |
item.add(link); | |
link.add(new Label("label", new StringResourceModel("lang.${}", item.getModel()))); | |
} | |
}); | |
} | |
private IModel<List<Locale>> getLocales() { | |
return new AbstractReadOnlyModel<List<Locale>>() { | |
@Override | |
public List<Locale> getObject() { | |
return Arrays.asList(Locale.ITALIAN, Locale.ENGLISH, Locale.GERMAN); | |
} | |
}; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lang.it=it default | |
lang.en=en default | |
lang.de=de default | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lang.it=it italian |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.stackoverflow; | |
import org.apache.wicket.util.tester.WicketTester; | |
import org.junit.Before; | |
import org.junit.Test; | |
/** | |
* Simple test using the WicketTester | |
*/ | |
public class SwitchLocaleTester { | |
private WicketTester tester; | |
@Before | |
public void setUp() { | |
tester = new WicketTester(new WicketApplication()); | |
} | |
@Test | |
public void homepageRendersSuccessfully() { | |
tester.startComponentInPage(SwitchLocale.class); | |
tester.assertModelValue("locales:" + 0 + ":link:label", "it default"); | |
tester.clickLink("locales:" + 0 + ":link", true); | |
tester.assertModelValue("locales:" + 0 + ":link:label", "it italian"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment