Let me try to rephrase the basic issue. I suspect that I am not using the correct pattern or syntax in the render method for this use case. Hope this attempt makes it clearer.
There are 2 different scenarios: (1) Ajax form is loaded for the first time and (ii) We are already in the page and Ajax button is submitted (possibly multiple times, each time for a new result)
Let us assume that the target element ( has "result" id) is where the results are displayed. The result happens to be bootstrap formatted table populated using a selector.
Now the render method returns a CssSel which is made of a number of CssSel connected with &. Among these are 2 of interest in this case.
Line 1: "#result" #> resultmethod // resultmethod generates a NodeSeq by accessing a map where the last result is stored for a particular user. Ideally this CssSel should only fire for page load or page reload and not for Ajax submits
and the actual submit button CssSel
Line 2: "type=submit" #> ajaxSubmit("Query", process)
process is a method that uses SetHtml to change the content of the result div. So it returns a JsCmd. This will only fire when the Ajax button is submitted. Not only does it change the result div, it also updates the map where the user last result is stored.
The problem is that I do not know how to ensure that the first line does not execute or influence the result div for Ajax button submits. Depending on how result method is written it overwrites or appends to the content of result (which has already been populated by process); So either I end up seeing the old table or the new table followed by the old table in the div (odd side comment: I get 2 tables if I write code to generate the NodeSeq, newer table from SetHtml of process followed by older table from the resultmethod; I just get the old table if I use css selector in resultmethod to generate NodeSeq). The weird thing is that on the very first access of the page (first load) I do not see this behavior. When I navigate away and reload and then do Ajax button submits, I do see this behavior. This overwriting etc. would not be an issue if the Map were already updated before the resultmethod executed (apparently it is frozen and has the older value from the Map at the time when the page is loaded). So the fix is to somehow make Line 1 execute only for page loads and reloads and not for Ajax button submits. How would one do this conditional behavior inside the render method? A fix that I do not know how to make.
General comment: Even if the documentation in Lift is incomplete or outdated, it would help newbies to get the right mental model of how Lift works, using current features and syntax. I am sure this can be accomplished in under 10 pages with reference to the key types and sequencing of operations. My present mental model is this: Lift is not just about strings but manipulates the DOM using properly vetted NodeSeqs (by a html5 parser) which are generated by css selectors in the backend. Are the css selectors at the end of the render method evaluated just once on page load or each time one submits the Ajax button? Is there any order to how the cssSelectors are evaluated (in linear order)? Is there a way inside render to tell if this is a page reload or an Ajax submit?