To create a session explicitly for first the first time page loads in Grails -


as page loads, renders lot of data , shows on view sort of slows down performance. want restrict , load data when filter applied . need way in session variable can store value on 1st login , no data should loaded in 1st session i.e. when user loads first time using login. below in controller class:

if(session.dtstartdate && session.dtstartdate != '') { simpledateformat nsdf = new simpledateformat('yyyy-mm-dd') date startdatevalue = nsdf.parse(session.dtstartdate.substring(0, session.dtstartdate.lastindexof("t")))     eq("startdate", startdatevalue)//if filter applied } else{     if 1st session startdate should null --> need piece of code replaced here } 

i unsure maybe still have not got have tried ask properly, thought should try answer question how understood problem be.

if take basic filter , add stuff may able wish using better method ? unsure startdate representing if base on if user has hit controller first time or not answer this, replace logic startdate if has other significance:

so adding hashmap arrayset filter gets called before action called when user clicks controller/action:

in conf/myfiters.groovy

class myfilters {   static final set<hashmap<string[],string[]>> usercontrol =  ([:]     set).assynchronized() //where controller  controllername ,  action actionname         def filters = {             mylogger() {                 before = {                   if (verifyclientmaster(session.id string ,controllername)==false) {                      clientmaster.add(session.id string:controllername)                      // here have new user set                       // session value gsp or load                       //according              }else{               // user has hit before else or set else               }                 }             }          }       }     boolean verifyclientmaster(string sessionid,string controller) {      // iterate       boolean found = false      usercontrol.each { k,v -> if (k == sessionid && v == controller) {      found = true      }      }     } 

something , know if user has hit controller or not.. remember session per user. new user has new session entity.

hope of , not off track..

e2a

thinking go down route need keep track of when session expires , remove user clientmaster.. take @ project if did go down route.. simpler this... on rethink...

  class myfilters {         def filters = {             mylogger() {                 before = {                   if (!sessions."${controllername}") {                         sessions."${controllername}"="${controllername}"                      // here have new user set                       // session value gsp or load                       //according                   }else{                      // user has hit before else or set else                    }                 }             }          }       } 

and simple of use intelligence built gsp if load can based on it... (not tested of ha)

<g:if test="${!session."${controllername}"}">          <g:set var="${controllername}" value="${controllername}" scope="session" />           <g:render template="firsttimehitter"/> </g:if> <g:else>          <g:render template="secondtimehitter"/>                 </g:else> 

or controller checks , sets , either renders different or sets gsp picks on..

def mycontroller {   def dosomething() {      boolean firsttime = false     if (!session."${controllername}") {       // first time either render or set firstime      firsttime = true        session."${controllername}" = controllername // or startdate      // render view: 'firsttime, model: [firsttime:firsttime, params:params]    } else{          // render view: 'firsttime, model: [firsttime:firsttime, params:params]   }   // if no render above:   render view: 'dosomething, model: [firsttime:firsttime, params:params]   // in dosomething gsp firsttime:  } 

do something:

<g:if test="${firsttime.tostring().equals('true')}">   <g:render template="firsttimehitter"/> </g:if> <g:else>  <g:render template="secondtimehitter"/> </g:else> 

the possibilities endless, differences being filter 1 fits all, i.e. checking every controller hit each user. in controller , gsp solution have declare needed. have abstract controller other controllers extend repeat check higher class gets called verify, regardless lot more repetitive simple 1 off filter...

final edit give other other alternatives be:

 final set<session> jsessions = ([] set).assynchronized()      jsessions.add('controller1')      jsessions.add('controller2')      jsessions.add('controller3')      jsessions.add(controllername)       println "=== ${jsessions}"      if (jsessions.contains(controllername)) {          println "--- have ${controllername} defined in our session set.... jsessions"      }       arraylist jsessions2 = []      jsessions2.add(controllername)      session.jsessions2 = jsessions2       //repeat on every call       arraylist jsessionsret = session.jsessions2      jsessionsret.add('controller1')       jsessionsret.add('controller2')      jsessionsret.add('controller3')       session.jsessions2 = jsessionsret       if (jsessions2.contains(controllername)) {          println "--- have ${controllername} defined in our session set.... jsessionsret"      }       println "222 --- ${jsessions2}" 

this segment above 2 different implementations of using first session set global , used if not care if controller hit usera userb etc if usera hits userb considered hitting it.. jsessions.

the bottom jsessions2 attempt turn single session key arraylist. rather storing lots of single object i.e. session."${controllername}" per call of controller per user session. have 1 single session key per user append each controller hit to.. , check see if have controller


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -