what Bas said .. also i think it will be better to load data lazily instead of using listener for performance ,pseudocode below just call LazyLoad.getData(cycle,mailId) when there is a need .. public class LazyLoad implements Serializable{
public static final MetaDataKey<UserData> KEY= new MetaDataKey<UserData>() {}; public static UserData getData(RequestCycle cycle,String mailId){ UserData data=cycle.getMetaData(KEY); if(data!=null){ return data; } data=service.loadData(mailId) ; cycle.setMetaData(KEY,data ); return data; } } On Thu, Apr 25, 2013 at 3:42 AM, Bas Gooren <b...@iswd.nl> wrote: > Andre, > > Your listener will also be called for resources served by wicket, so my > guess is you have 1-7 resources on your page which are served by wicket. > E.g. resources you store next to your pages (inside the same java package). > > So my guess is that you're not seeing multiple hits to onBeginRequest for > a single request, but simply multiple requests to wicket. > > If you only want to handle requests to pages inside your listener, you can > do so by overriding onRequestHandlerResolved instead: > > void onRequestHandlerResolved(**RequestCycle cycle, IRequestHandler > handler) { > if(handler instanceof IPageClassRequestHandler) { > // This is a request to a page, or a component on a page > } > } > > Met vriendelijke groet, > Kind regards, > > Bas Gooren > > Op 24-4-2013 22:34, schreef Andre Schütz: > > Hello, >> >> thank you for the answers. >> >> I created my own RequestCycleListener and have another question. >> >> public MyRequestCycleListener extends AbstractRequestCycleListener { >> public onBeginRequest(RequestCycle cycle) { >> super.onBeginRequest(cycle); >> >> MyAuthenticatedSession session = (MyAuthenticatedSession)** >> Session.get(); >> if (session.isSignedIn()) { >> System.out.println("Is signed in"); >> // this is planned >> // String email = session.getAuthenticatedMail()**; >> // ObjectId userID = userDAO.getUserID(email); >> // cycle.setMetaData("userID", userID); >> } >> else { >> System.out.println("Is not signed in"); >> } >> } >> } >> >> public MyApplication extends AuthenticatedWebApplication { >> public void init() { >> super.init(); >> IRequestCycleListener cycle = new MyRequestCycleListener(); >> getRequestCycleListener().add(**cycle); >> } >> } >> >> public MyPage extends WebPage() { >> public MyPage ... >> } >> >> My question is as follows: >> >> I load "MyPage" and the onBeginRequest method is called multiple times >> during the load of the page (between 2 and 8 times) and displays the lines >> "Is signed in". >> I planned to store the email ID of the User in the session and load the >> User data in the onBeginRequest function of the RequestCycleListener. But >> ... I only want to load the User data once per request. >> >> What do I wrong? Any help? >> Thanks, >> Andre >> >> >> On Mon, 22 Apr 2013 11:03:43 +0530 >> vineet semwal <vineetsemwa...@gmail.com> wrote: >> >> yes,you can store some key in session like emailId and then retrieve and >>> store the user and related data in request cycle metadata ,as you are >>> storing in requestcycle metadata ,scope of the data will be for the whole >>> request only . >>> no need to create your own requestcycle for that,create your requestcycle >>> listener which onbeginrequest stores the user related data in >>> requestcycle >>> metadata >>> >>> >>> On Mon, Apr 22, 2013 at 1:55 AM, Andre Schütz <andre-p...@gmx.de> wrote: >>> >>> I plan to implement a project with AuthenticatedWebApplication. The >>>> users >>>> have to sign up for an account. My question is regarding the user data >>>> that >>>> I have to load during each request of the single pages. >>>> >>>> The project will be as follows: >>>> (1) User logs into the system >>>> (2) The dashboard will be loaded >>>> (3) The user clicks the menu and gets a different representation of the >>>> information >>>> >>>> I would like to know the following two things: >>>> >>>> (a) The user registers with his email and a password (The email is >>>> unique >>>> in the database). I wanted to store the email in the >>>> AuthenticatedWebSession and load the desired user data during each >>>> request >>>> of a WebPage. Would that be a good idea? >>>> >>>> (b) I read in the documentation about the WebRequestCycle. Would it be >>>> useful to implement an own WebRequestCycle for the loading of the user >>>> data? >>>> >>>> I hope to hear some opinions. Thanks in advance. >>>> Andre >>>> >>>> ------------------------------**------------------------------** >>>> --------- >>>> To unsubscribe, e-mail: >>>> users-unsubscribe@wicket.**apache.org<users-unsubscr...@wicket.apache.org> >>>> For additional commands, e-mail: users-h...@wicket.apache.org >>>> >>>> >>>> >>> -- >>> regards, >>> >>> Vineet Semwal >>> >> >> > -- regards, Vineet Semwal