0
votes

[22 Feb 2016 update]

Regarding my previous questions about list box, I can move values between two listboxes and save values after I receive useful answers.

However, if I retrieve those saved values, the listboxes can display the proper values but I cannot move those values and get exception message.

I can only move values between two listboxes if I don't save them.

Therefore, I am planning to have another button for delete listboxes values. I am not sure this is a good practice/design in xpages but I don't have a better method solve the exception.

I am sorry if I caused any inconvenience in this question. Thank you.

[23 Feb 2016 update]

According to the latest comments and answer, I notice that I made a big mistake because I mixed the document and value together.

I decide to break the design into few steps to find the problem occurs.

Due to I can move values between two listboxes and save them. I use another listbox test whether I can retrieve those saved values or not.

The third list box, I use View Scope Variable(similar to listbox B) but I use another variable name to avoid vague.

Here is my code of the third listbox:

var item = getComponent("comboBox4").getValue();

if ((item == null) || (null == item))
{ 
    return "void";
}
else if ((item != null) || (null != item))
{ 
    var lookupItem = @DbLookup(@DbName(),"ViewName", item,3  )
    return  lookupItem;
}
if (!viewScope.totalItems) 
{
    viewScope.totalItems = [lookupItem];
 }
 return viewScope.totalItems;

In the combo box, I use onchange partial update and apply to the third list box . When I run the program, I select a value from the combo box, the third listbox can display the relevant values that I saved before.

That part is fine, so I keep the third listbox for testing. And I put some dummy but unique data (to prevent confusion) related to the combo box.

Here is my first attempt: I choose a value from a combo box, the third listbox can display the relevant values that I saved. I move one value from listbox A to listbox B and click save. The third list box can reflect the value that I save.

In my second attempt: after the first attempt, listbox B still contains the value from listbox A, so this time, I move that value back to listbox A and click save. In the result, in the third list box, I see that value disappear.

At this moment, there is no value in listbox B and I add another two button and write similar code to pretend move values between the third list box and listbox B.

I test it, I select the value from the combo box, the third list box shows the proper values. But when I select a value from the third list box and click the button to move it to listbox A. I think that value will move to the listbox A but the result is nothing happens.

I try the other way, I select a value from listbox A and click the button to move it to the third button. Again the result is nothing happens.

After those fail attempts, I think the problem occurs in the buttons.

Here are the code of the two buttons

Button 1 (move value to the third listbox):

if (viewScope.ALstBoxItem) {
                        var sel = [].concat(viewScope.ALstBoxItem);
                        for (var i = 0; i < sel.length; i++) {
                            viewScope.totalItems.add(sel[i]); 
                            viewScope.AselectItems.remove(sel[i]);
                        }
                        viewScope.totalItems.sort(); 
                        viewScope.ALstBoxItem = "";
                    }

Button 2 (move value to the listbox A):

if (viewScope.TotalItemsVariable) {
                        var sel = [].concat(viewScope.TotalItemsVariable);
                        for (var i = 0; i < sel.length; i++) {
                            viewScope.AselectItems.add(sel[i]);                     
                            viewScope.totalInItem.remove(sel[i]); 
                        }        
                        viewScope.AselectItems.sort();                         
                        viewScope.TotalItemsVariable = "";
                    }

Recall to comments in the question, I guess I should focus on the values in the listbox, not the button. I search on the internet about hide selected value and find these websites almost can give me the idea to solve the problem:

xpages hiding/showing fields based on a combobox value

Hiding based on previous combo box choice in xpages?

https://www-10.lotus.com/ldd/ddwiki.nsf/dx/dynamical_elements_on_xpages.htm

I try to apply those summary to suit my case but I still cannot move values after I save.

Grateful if someone can give advice please. Thank you very much.

1
You are talking about deleting values from a list box but you are trying to do this by deleting documents. You should not be looking at deleting documents. - Per Henrik Lausten
@PerHenrikLausten, thanks you comment. May I ask a question about documents and values please? I think I mixed them up in my original question. - Learner
For example, there is a raw data, called "abc", if I put it in the list box, should I say that "abc" is a list box value? Even I write some code in the listbox, that "abc" is still a list box value? If I saved "abc", so that raw data becomes a document? - Learner
I don't see any reference to a document data source - only viewScope values. - Per Henrik Lausten
I read this website XPages - How to pass a Document Data Source to a Custom Control. So in my case, do I need to create a custom control for document data source? - Learner

1 Answers

0
votes

Please step back and think about what you are building. You have two list boxes. They contain values, not documents, so a deleteSelectedDocument simple action can't work. Similarly, access to delete documents isn't relevant.

Also, from previous questions of this topic, I don't think you are setting values in the listboxes, you are using the events to set options, i.e. the options are not highlighted and so selected in the listbox, they are just sitting in the listboxes as options available for selection. Look at the code you're using to add options to the listboxes and use the corresponding code to remove the options.

I've added an image that corresponds to what I think you're trying to build, and the difference between "value" and "option", except in your example it sounds like you're moving the option from ListBox 1 to ListBox 2 as soon as it's selected, not using an "Add" button. Or to break the process down further, it sounds like, when an option in ListBox 1 is selected, you are looking to remove it from the list of options in ListBox 1 and add it to the list of options in ListBox 2. On your save, it sounds like you're wanting to store the options into a NotesDocument and, when you return, set the options for your ListBoxes based on what is stored in the NotesDocument.

If so, the questions and answers on this topic have given you everything you need to code those steps in the process.

ListBox example