Search code examples
comboboxxpages

How to set combobox value?


I need to determine the value to be displayed in the menu according to the logged-in user. If there are Ariel, Austin, Jennifer and Ryan in the menu, when I log in as Ariel, the menu will not show Ariel, there will only be Austin, Jennifer and Ryan. How to achieve this requirement?

enter image description here

enter image description here


Solution

  • Get the current logged-in user name with

    var username = session.createName(session.getEffectiveUserName()).getCommon()
    

    and remove the name from the list of users.

    Example:

    <?xml version="1.0" encoding="UTF-8"?>
    <xp:view xmlns:xp="http://www.ibm.com/xsp/core">
        <xp:comboBox id="comboBox1">
            <xp:selectItems>
                <xp:this.value><![CDATA[#{javascript:
                    var names = new java.util.ArrayList();
                    names.add("Ariel A");
                    names.add("Austin B");
                    names.add("Jennifer C");
                    names.add("Ryan D");
                    var username = session.createName(session.getEffectiveUserName()).getCommon();
                    names.remove(username);
                    return names;
                }]]></xp:this.value>
            </xp:selectItems>
        </xp:comboBox>
    </xp:view>