use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class WebSocketTesterRequestCycleListenerTest method before.
@Before
public void before() {
tester = new WicketTester();
tester.getApplication().getRequestCycleListeners().add(new IRequestCycleListener() {
@Override
public void onBeginRequest(RequestCycle cycle) {
beginRequestCalled.set(true);
}
@Override
public void onEndRequest(RequestCycle cycle) {
endRequestCalled.set(true);
}
@Override
public void onDetach(RequestCycle cycle) {
detachCalled.set(true);
}
});
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class ComponentEventSender method bubble.
/**
* Bubbles the event
*
* @param event
* event
*/
private void bubble(ComponentEvent<?> event) {
IEventSink sink = event.getSink();
boolean targetsComponent = sink instanceof Component;
boolean targetsCycle = targetsComponent || sink instanceof RequestCycle;
boolean targetsSession = targetsCycle || sink instanceof Session;
boolean targetsApplication = targetsSession || sink instanceof Application;
if (!targetsApplication && !targetsComponent) {
dispatcher.dispatchEvent(sink, event, null);
return;
}
if (targetsComponent) {
Component cursor = (Component) sink;
dispatchToComponent(dispatcher, cursor, event);
if (event.isStop()) {
return;
}
cursor.visitParents(MarkupContainer.class, new ComponentEventVisitor(event, dispatcher));
}
if (event.isStop()) {
return;
}
if (targetsCycle) {
dispatcher.dispatchEvent(source.getRequestCycle(), event, null);
}
if (event.isStop()) {
return;
}
if (targetsSession) {
dispatcher.dispatchEvent(source.getSession(), event, null);
}
if (event.isStop()) {
return;
}
if (targetsApplication) {
dispatcher.dispatchEvent(source.getApplication(), event, null);
}
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class ComponentEventSender method depth.
/**
* Depth broadcast
*
* @param event
* event
*/
private void depth(final ComponentEvent<?> event) {
IEventSink sink = event.getSink();
boolean targetsApplication = sink instanceof Application;
boolean targetsSession = targetsApplication || sink instanceof Session;
boolean targetsCycle = targetsSession || sink instanceof RequestCycle;
boolean targetsComponent = sink instanceof Component;
if (!targetsComponent && !targetsCycle) {
dispatcher.dispatchEvent(sink, event, null);
return;
}
Component cursor = (targetsCycle) ? source.getPage() : (Component) sink;
if (cursor instanceof MarkupContainer) {
Visits.visitPostOrder(cursor, new ComponentEventVisitor(event, dispatcher));
} else {
dispatchToComponent(dispatcher, cursor, event);
}
if (event.isStop()) {
return;
}
if (targetsCycle) {
dispatcher.dispatchEvent(source.getRequestCycle(), event, null);
}
if (event.isStop()) {
return;
}
if (targetsSession) {
dispatcher.dispatchEvent(source.getSession(), event, null);
}
if (event.isStop()) {
return;
}
if (targetsApplication) {
dispatcher.dispatchEvent(source.getApplication(), event, null);
}
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class NonResettingRestartException method transferResponseMetaData.
private void transferResponseMetaData() {
RequestCycle cycle = RequestCycle.get();
Response response = cycle.getResponse();
if (response instanceof IMetaDataBufferingWebResponse) {
WebResponse originalResponse = (WebResponse) cycle.getOriginalResponse();
if (originalResponse != response) {
IMetaDataBufferingWebResponse bufferingWebResponse = (IMetaDataBufferingWebResponse) response;
bufferingWebResponse.writeMetaData(originalResponse);
}
}
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class Session method setAttribute.
/**
* Adds or replaces the attribute with the given name and value.
*
* @param name
* The name of the attribute
* @param value
* The value of the attribute
*/
public final Session setAttribute(String name, Serializable value) {
if (!isTemporary()) {
RequestCycle cycle = RequestCycle.get();
if (cycle == null) {
throw new IllegalStateException("Cannot set the attribute: no RequestCycle available. If you get this error when using WicketTester.startPage(Page), make sure to call WicketTester.createRequestCycle() beforehand.");
}
ISessionStore store = getSessionStore();
Request request = cycle.getRequest();
// extra check on session binding event
if (value == this) {
Object current = store.getAttribute(request, name);
if (current == null) {
String id = store.getSessionId(request, false);
if (id != null) {
// this is a new instance. wherever it came from, bind
// the session now
store.bind(request, (Session) value);
}
}
}
// Set the actual attribute
store.setAttribute(request, name, value);
} else {
// session instance gets shared across threads
if (temporarySessionAttributes == null) {
temporarySessionAttributes = new HashMap<>(3);
}
temporarySessionAttributes.put(name, value);
}
return this;
}
Aggregations