1
votes

I have built a search function in an xpage, where the user can choose values from list boxes and combo boxes, and the ftsearch query is composed from these values. So when I change the value of a combo box, the onChange event is triggered and a partial update to the view of the results occurs. The problem is that the view displays the results according to the previous value of the combo box before the onChange. It's like the results in the view are always one change behind.

I added try/catch to the event, but no exception occurs. It seems a really strange behaviour. Has anyone experienced anything like this before?

I would appreciate any ideas and directions, as I am stuck right now about what the problem might be.

Thanks a lot in advance!

1
Can you create a sample XPage and post the code.Simon O'Doherty
to detail Simon's comment: how do you pass the ftsearch string into the view's search property? Are you using a view panel at all?Lothar Mueller
Yes, I am using a view panel and I pass the ftsearch string to the search property of it. The ftsearch string is composed by getting the values from the list boxes and the combo boxes. @SimonO'Doherty I'm afraid that the code is quite complicated to be easily read from here.kmak
Don't need the full code. try to create a sample in a blank nsf and see what happens.Simon O'Doherty
This is common problem when you use stored value before submitted value is applied to model. More info in JSF lifecycle. You can try to get "submitted value" instead of "value". Or change the way you do the search, it seems you do it in wrong order.Frantisek Kossuth

1 Answers

2
votes

I just gave it a shot in a very simple way, and it works for me. Here's what I have:

  1. make sure my database is ft indexed!!
  2. create a viewPanel with an id = "viewPanel1"
  3. link viewPanel to a view datasource
  4. create a computed search property for my viewPanel with the following code:

    requestScope.get("fts");

  5. create a comboBox (above) the view panel

  6. bind the combo to my requestScope variable "fts"
  7. fill the combo's option list with appropriate values
  8. have the combo's onchange event perform a partial update and link this to my viewPanel (ID: viewPanel1)

In my case I have test documents in my view with a subject field that has values like "sub 1", "sub 2", ... , "sub 6". So I made my combo offer me options "1" ... "6".

If I want to be more specific with my ft search string I can build it like this in the viewPanel's search property (step 4):

if(requestScope.containsKey("fts") && requestScope.get("fts")!=""){
    "Sub " + requestScope.get("fts");
}

That's it - works.

If I got your problem wrong let us know. In that case you'd need to be more specific regarding what you are trying to do and what you tried so far.

EDIT:
following your comment I added a listBox to my combo. I see that the listBox itself doesn't do anything bad, but of course I have to take care that the two don't get into each other's way. So here's what I did to resolve that:

  1. bound my comboBox to a different requestScope var called "ftsCombo"
  2. bound my listBox accordingly to "ftsList"
  3. both controls have the same option list (see above; of course you can use different options, I just was to lazy to think of different values...), and they are performing a partial update onchange
  4. to be able to control the results I created a named panel around my viewPanel (id = "tgtPanel") and changed the partial update rule to target the panel
  5. inside the panel above the view I created 2 computed fields, each bound to one of my requestScope variables (ftsCombo / ftsList) so that I see what's in the scope after onchange has been triggered
  6. in both onchange events I also wrote a short snippet of SSJS code to clear "the other" variable so that the two don't get in each other's way:

(onchange of combo:)

requestScope.remove("ftsList");  

(onchange of list:)

requestScope.remove("ftsCombo"); 

finally changed the view's computed search property to be like this:

if(requestScope.containsKey("ftsCombo") && requestScope.get("ftsCombo")!=""){
return "Sub " + requestScope.get("ftsCombo");
}
if(requestScope.containsKey("ftsList") && requestScope.get("ftsList")!=""){
 return "Sub " + requestScope.get("ftsList");
}

So now I can either use the combo or the list to apply a filter