1 Reply Latest reply on Nov 30, 2012 6:42 AM by rush_pawan

    How i can check whether a component is being placed or it's being rendered during page load...

    Shankar Arumugam Level 1



      I have a piece of code which needs to be triggered only when the component gets rendered.. and at the same time it shouldn't get trigerred when author places it in the page...


      For an example, Consider i have a component called samplecomponent. Also i have a piece of code in samplecomponent.jsp which should get triggered only when the component is being rendered during page load and if author places that component in the page (ofcourse the samplecomponent.jsp will get triggered but my particular piece of code should not get triggered.. Is there any condition to check that..?




      Shankar .A

        • 1. Re: How i can check whether a component is being placed or it's being rendered during page load...
          rush_pawan Level 4

          Hello Shankar,


          I think this is very straight forward and you can set this condition based on any of the property of your component via check null/empty condition because when you will drop your component the properties of your component will be not initialized and you can check for at (let say you have a property which is mandetory so to instantiate that component you have to have at least that property)


          And let say if above option doesn't work for you then there is one more option of checking the edit mode of the page and based on that you can differ your code. But edit mode code will not work until you will see the page in edit mode, the code will only work when you switch to preview mode (publish mode) of page from edit mode (from sidekick at bottom you have option to go to edit and preview mode).


          WCMMode mode = WCMMode.fromRequest(request);

              if (!mode.equals(WCMMode.EDIT) && !mode.equals(WCMMode.DESIGN)) {

               //this part of code never execute when your page is in edit mode (dropped content or load the page in edit mode). but this part of code will run when you switch from edit mode to previe mode (in author node) or on  publish instance of Server because there will be no edit mode there.



          Let me know if you need more information or it doesn't help you.