Example usage of PageCallback:
The Home page ensure a user is authenticated in the validate(IRequestCycle) method. If the user is not authenticated, they are redirected to the Login page, after setting a callback in the Login page.
The Login page formSubmit() IActionListener authenticates the user and then invokes performCallback(IRequestCycle) to the Home page.
public class Home extends BasePage { public void validate(IRequestCycle cycle) { Visit visit = (Visit) getVisit(); if (!visit.isAuthenticated()) { Login login = (Login) cycle.getPage("Login"); login.setCallback(new PageCallback(this)); throw new PageRedirectException(login); } } } public Login extends BasePage { private ICallback _callback; public void setCallback(ICallback _callback) { _callback = callback; } public void formSubmit(IRequestCycle cycle) { // Authentication code .. Visit visit = (Visit) getVisit(); visit.setAuthenticated(true); if (_callback != null) { _callback.performCallback(cycle); } } }
Example usage of PageCallback:
The Home page ensure a user is authenticated in the validate(IRequestCycle) method. If the user is not authenticated, they are redirected to the Login page, after setting a callback in the Login page.
The Login page formSubmit() IActionListener authenticates the user and then invokes performCallback(IRequestCycle) to the Home page.
public class Home extends BasePage { public void validate(IRequestCycle cycle) { Visit visit = (Visit) getVisit(); if (!visit.isAuthenticated()) { Login login = (Login) cycle.getPage("Login"); login.setCallback(new PageCallback(this)); throw new PageRedirectException(login); } } } public Login extends BasePage { private ICallback _callback; public void setCallback(ICallback _callback) { _callback = callback; } public void formSubmit(IRequestCycle cycle) { // Authentication code .. Visit visit = (Visit) getVisit(); visit.setAuthenticated(true); if (_callback != null) { _callback.performCallback(cycle); } } }