database - How to share a variable in concurrent JSF queries? -


i have jsf 1.2 / richfaces 3.3 / oracle 10g based application. have <h:inputtext> search query @ database on pressing return key. if multiple queries submitted 1 after another, program fires multiple queries database (which returns list of results). program requires show result of submitted query.

this sample code fired every time enter pressed <h:inputtext>.

public void searchuser() {     resultlist = null;  // getters , setters defined resultlist, resultlist directly accessed in .jsp pages.     resultlist = getuserserviceinterface().getfilteredusers(searchstring);  //results in jpa query database. } 

suppose, if query1 submitted @ t second, , answer arrives @ t+10 seconds.

meanwhile, query2 submitted @ t+2 seconds, , answer arrives @ t+7 seconds.

the .jsp page using resultlist shows result of query2 @ t+7 seconds, , switches result of query1 @ t+10 seconds. want avoid showing result of query1 here.

the approach using ignoring result of non-recent queries, requires able distinguish result of non-recent query recent query using common variable. have noticed each query results in new facescontext , new instances of bean, therefore no common variable shared among concurrent queries. tried managing states of recent query in phaselistener had no success. how have variable in program, atomic during concurrent jsf queries.

it solved ajax request optimization. used separate queue traffic flood protection.

the following code executes fucntion searchuser(), if return key pressed.

<h:inputtext value="#{searchuser.searchstring}">         <a4j:support event="onkeydown" onsubmit="if (event.keycode == 13) {return false;} else {return true;}"/>         <a4j:support event="onkeyup" onsubmit="if (event.keycode != 13) {return false;} else {searchuser(); return false;}"/> </h:inputtext> 

i defined separate queue function , used ignoredupresponses="true", avoids similar requests.

<a4j:jsfunction name="searchuser" eventsqueue="foo" ignoredupresponses="true" requestdelay="1000" action="#{searchuser.searchuser}" rerender="homecontent, userlist2"/> 

more information can found @ following link: https://docs.jboss.org/richfaces/latest_3_3_x/en/devguide/html/architectureoverview.html#queueandtrafficfloodprotection


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -