use of org.apache.wicket.Page in project midpoint by Evolveum.
the class WebComponentUtil method theSameForPage.
public static <T extends Component> T theSameForPage(T object, PageReference containingPageReference) {
Page containingPage = containingPageReference.getPage();
if (containingPage == null) {
return object;
}
String path = object.getPageRelativePath();
T retval = (T) containingPage.get(path);
if (retval == null) {
return object;
// throw new IllegalStateException("There is no component like " +
// object + " (path '" + path + "') on " + containingPage);
}
return retval;
}
use of org.apache.wicket.Page in project oc-explorer by devgateway.
the class BasePage method newLanguageMenu.
public NavbarDropDownButton newLanguageMenu() {
final NavbarDropDownButton languageDropDown = new NavbarDropDownButton(new StringResourceModel("navbar.lang", this, null)) {
private static final long serialVersionUID = 319842753824102674L;
@Override
protected List<AbstractLink> newSubMenuButtons(final String buttonMarkupId) {
final List<AbstractLink> list = new ArrayList<>();
for (final Locale l : WebConstants.AVAILABLE_LOCALES) {
final PageParameters params = new PageParameters(BasePage.this.getPageParameters());
params.set(WebConstants.LANGUAGE_PARAM, l.getLanguage());
list.add(new MenuBookmarkablePageLink<Page>(BasePage.this.getPageClass(), params, Model.of(l.getDisplayName())));
}
return list;
}
};
languageDropDown.setIconType(GlyphIconType.flag);
return languageDropDown;
}
use of org.apache.wicket.Page in project wicket by apache.
the class WicketTesterTest method assertComponentOnAjaxResponse_encoding.
/**
* Test that testing if a component is on the ajax response can handle if the response is
* encoded.
*/
@Test
public void assertComponentOnAjaxResponse_encoding() {
final IModel<String> labelModel = new IModel<String>() {
private static final long serialVersionUID = 1L;
private String value;
@Override
public String getObject() {
return value;
}
@Override
public void setObject(String object) {
value = object;
}
};
labelModel.setObject("Label 1");
final Label label = new Label(MockPageWithLinkAndLabel.LABEL_ID, labelModel);
label.setOutputMarkupId(true);
final Page page = new MockPageWithLinkAndLabel();
AjaxLink<Void> ajaxLink = new AjaxLink<Void>(MockPageWithLinkAndLabel.LINK_ID) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
labelModel.setObject("Label which needs encoding: [] ][");
target.add(label);
}
};
ajaxLink.setOutputMarkupId(true);
page.add(ajaxLink);
ajaxLink.add(label);
tester.startPage(page);
// Click the link
tester.clickLink(MockPageWithLinkAndLabel.LINK_ID);
tester.assertComponent(MockPageWithLinkAndLabel.LABEL_PATH, Label.class);
tester.dumpPage();
// This must not fail
tester.assertComponentOnAjaxResponse(MockPageWithLinkAndLabel.LABEL_PATH);
}
use of org.apache.wicket.Page in project wicket by apache.
the class WicketTesterTest method assertComponentOnAjaxResponse.
/**
*/
@Test
public void assertComponentOnAjaxResponse() {
final Page page = new MockPageWithLink();
AjaxLink<Void> ajaxLink = new AjaxLink<Void>(MockPageWithLink.LINK_ID) {
private static final long serialVersionUID = 1L;
@Override
public void onClick(AjaxRequestTarget target) {
// Replace the link with a normal Link
Link<Void> link = new Link<Void>(MockPageWithLink.LINK_ID) {
private static final long serialVersionUID = 1L;
@Override
public void onClick() {
}
};
link.setOutputMarkupId(true);
page.replace(link);
target.add(link);
}
};
ajaxLink.setOutputMarkupId(true);
page.add(ajaxLink);
tester.startPage(page);
// Click the link
tester.clickLink(MockPageWithLink.LINK_ID);
// The link must be a Link :)
tester.assertComponent(MockPageWithLink.LINK_ID, Link.class);
// This must not fail
tester.assertComponentOnAjaxResponse(MockPageWithLink.LINK_ID);
tester.dumpPage();
}
use of org.apache.wicket.Page in project wicket by apache.
the class CookieUtilsTest method test1.
/**
* @throws Exception
*/
@SuppressWarnings({ "unchecked" })
@Test
public void test1() throws Exception {
// How does the test work: Make sure you have a page, form and form component properly set
// up (getRelativePath() etc.). See #before().
final Page page = tester.getLastRenderedPage();
// Get the form and form component created
final TestForm form = (TestForm) page.get("form");
final TextField<String> textField = (TextField<String>) form.get("input");
// Right after init, the requests and responses cookie lists must be empty
assertEquals(0, getRequestCookies().size());
assertEquals(0, getResponseCookies().size());
// Create a persister for the test
final CookieUtils persister = new CookieUtils();
// See comment in CookieUtils on how removing a Cookies works. As no cookies in the request,
// no "delete" cookie will be added to the response.
persister.remove(textField);
assertEquals(0, getRequestCookies().size());
assertEquals(0, getResponseCookies().size());
// Save the input field's value (add it to the response's cookie list)
persister.save(textField);
assertTrue(getRequestCookies().isEmpty());
assertEquals(1, getResponseCookies().size());
assertEquals("test", (getResponseCookies().get(0)).getValue());
assertEquals("form.input", (getResponseCookies().get(0)).getName());
assertEquals(tester.getRequest().getContextPath() + tester.getRequest().getServletPath(), (getResponseCookies().get(0)).getPath());
// To remove a cookie means to add a cookie with maxAge=0. Provided a cookie with the same
// name has been provided in the request. Thus, no changes in our test case
persister.remove(textField);
assertEquals(0, getRequestCookies().size());
assertEquals(1, getResponseCookies().size());
assertEquals("test", (getResponseCookies().get(0)).getValue());
assertEquals("form.input", (getResponseCookies().get(0)).getName());
assertEquals(tester.getRequest().getContextPath() + tester.getRequest().getServletPath(), (getResponseCookies().get(0)).getPath());
// Try to load it. Because there is no Cookie matching the textfield's name the model's
// value remains unchanged
persister.load(textField);
assertEquals("test", textField.getDefaultModelObjectAsString());
// Simulate loading a textfield. Initialize textfield with a new (default) value, copy the
// cookie from response to request (simulating a browser), than load the textfield from
// cookie and voala the textfield's value should change.
// save means: add it to the response
// load means: take it from request
assertEquals("test", textField.getDefaultModelObjectAsString());
textField.setDefaultModelObject("new text");
assertEquals("new text", textField.getDefaultModelObjectAsString());
copyCookieFromResponseToRequest();
assertEquals(1, getRequestCookies().size());
assertEquals(1, getResponseCookies().size());
persister.load(textField);
assertEquals("test", textField.getDefaultModelObjectAsString());
assertEquals(1, getRequestCookies().size());
assertEquals(1, getResponseCookies().size());
// remove all cookies from mock response. Because I'll find the cookie to be removed in the
// request, the persister will create a "delete" cookie to remove the cookie on the client
// and add it to the response. The already existing Cookie from the previous test gets
// removed from response since it is the same.
persister.remove(textField);
assertEquals(1, getRequestCookies().size());
assertEquals(1, getResponseCookies().size());
assertEquals("form.input", (getResponseCookies().get(0)).getName());
assertEquals(0, (getResponseCookies().get(0)).getMaxAge());
}
Aggregations