use of org.apache.wicket.request.component.IRequestableComponent in project wicket by apache.
the class ListenerRequestHandler method invoke.
/**
* Invokes a given interface on a component.
*
* @param rcomponent
* The component
*
* @throws ListenerInvocationNotAllowedException
* when listener invocation attempted on a component that does not allow it
*/
private final void invoke(final IRequestCycle requestCycle, RedirectPolicy policy, boolean ajax, final IRequestableComponent rcomponent) {
// we are in Wicket core land
final Component component = (Component) rcomponent;
if (!component.canCallListener()) {
// just return so that we have a silent fail and just re-render the
// page
LOG.info("component not enabled or visible; ignoring call. Component: " + component);
throw new ListenerInvocationNotAllowedException(component, null, "Component rejected interface invocation");
}
internalInvoke(requestCycle, policy, ajax, component, component);
}
use of org.apache.wicket.request.component.IRequestableComponent in project wicket by apache.
the class ListenerRequestHandler method respond.
@Override
public void respond(final IRequestCycle requestCycle) {
final IRequestablePage page = getPage();
final boolean freshPage = pageComponentProvider.doesProvideNewPage();
final boolean isAjax = ((WebRequest) requestCycle.getRequest()).isAjax();
IRequestableComponent component;
try {
component = getComponent();
} catch (ComponentNotFoundException e) {
// either the page is stateless and the component we are looking for is not added in the
// constructor
// or the page is stateful+stale and a new instances was created by pageprovider
// we denote this by setting component to null
component = null;
}
if ((component == null && !freshPage) || (component != null && component.getPage() != page)) {
throw new ComponentNotFoundException("Component '" + getComponentPath() + "' has been removed from page.");
}
if (page instanceof Page) {
// initialize the page to be able to check whether it is stateless
((Page) page).internalInitialize();
}
RedirectPolicy policy = page.isPageStateless() ? RedirectPolicy.NEVER_REDIRECT : RedirectPolicy.AUTO_REDIRECT;
boolean blockIfExpired = component != null && !component.canCallListenerAfterExpiry();
boolean lateComponent = component == null && freshPage;
if ((pageComponentProvider.wasExpired() && blockIfExpired) || lateComponent) {
if (LOG.isDebugEnabled()) {
LOG.debug("An IRequestListener was called but its page/component({}) couldn't be resolved. " + "Scheduling re-create of the page and ignoring the listener interface...", getComponentPath());
}
if (isAjax) {
policy = RedirectPolicy.ALWAYS_REDIRECT;
}
requestCycle.scheduleRequestHandlerAfterCurrent(new RenderPageRequestHandler(new PageProvider(page), policy));
return;
}
invokeListener(requestCycle, policy, isAjax);
}
use of org.apache.wicket.request.component.IRequestableComponent in project wicket by apache.
the class ListenerRequestHandler method invoke.
/**
* Invokes a given interface on a component's behavior.
*
* @param rcomponent
* The component
* @param behavior
* @throws ListenerInvocationNotAllowedException
* when listener invocation attempted on a component that does not allow it
*/
private final void invoke(final IRequestCycle requestCycle, RedirectPolicy policy, boolean ajax, final IRequestableComponent rcomponent, final Behavior behavior) {
// we are in Wicket core land
final Component component = (Component) rcomponent;
if (!behavior.canCallListener(component)) {
LOG.warn("behavior not enabled; ignore call. Behavior {} at component {}", behavior, component);
throw new ListenerInvocationNotAllowedException(component, behavior, "Behavior rejected interface invocation. ");
}
internalInvoke(requestCycle, policy, ajax, component, behavior);
}
use of org.apache.wicket.request.component.IRequestableComponent in project wicket by apache.
the class BookmarkableMapperTest method encode7.
/**
*/
@Test
public void encode7() {
MockPage page = new MockPage(15);
page.getPageParameters().set(0, "i1");
page.getPageParameters().set(1, "i2");
page.getPageParameters().set("a", "b", INamedParameters.Type.QUERY_STRING);
page.getPageParameters().set("b", "c", INamedParameters.Type.QUERY_STRING);
// shouldn't make any difference for BookmarkableListenerRequestHandler,
// as this explicitly says the url must be bookmarkable
page.setCreatedBookmarkable(false);
IRequestableComponent c = page.get("foo:bar");
PageAndComponentProvider provider = new PageAndComponentProvider(page, c);
IRequestHandler handler = new BookmarkableListenerRequestHandler(provider, 4);
Url url = encoder.mapHandler(handler);
assertEquals("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/i1/i2?15-0.4-foo-bar&a=b&b=c", url.toString());
}
use of org.apache.wicket.request.component.IRequestableComponent in project wicket by apache.
the class CryptoMapperTest method additionalParameters.
/**
* Additional parameters, WICKET-4923
*/
@Test
public void additionalParameters() {
MockPage page = new MockPage();
IRequestableComponent c = page.get("foo:bar");
PageAndComponentProvider provider = new PageAndComponentProvider(page, c);
IRequestHandler handler = new ListenerRequestHandler(provider);
Url url = mapper.mapHandler(handler);
url.addQueryParameter("q", "foo");
Request request = getRequest(url);
IRequestHandler requestHandler = mapper.mapRequest(request);
assertThat(requestHandler, instanceOf(RequestSettingRequestHandler.class));
assertEquals("foo", ((RequestSettingRequestHandler) requestHandler).getRequest().getUrl().getQueryParameterValue("q").toString());
}
Aggregations