Search code examples
xpages-ssjs

Could not determine the return value type from combobox when it is made blank


I've combo box whose list items are computed using dblookup. I'm inserting blank in the beginning of the list.

I've another computed field to show the value of combo box.

When I create new document computed field coded to show the value of combo box as 'null' and it works.

When I select item from the list in combo box , the computed field shows the value correctly.

When I return back to blank in combo box and refresh document, the computed field does not show any thing. What value type is return back by combo box when set back to blank?

Here is code for computed field:

var comboBox2:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox2");

if(comboBox2.getValue()==null){
  return "null";
  } else {
  return comboBox2.getValue();
  }
if(comboBox2.getValue()==''){
  return "blank";
  } else {
  return comboBox2.getValue();
  }
if(comboBox2.getValue()==""){
  return "quoted blank";
  } else {
  return comboBox2.getValue();
  }

Here is a code for combobox:

<xp:comboBox
                        id="comboBox2"
                        value="#{document1.Sample_Prod1}"
                        style="width:84.0px">
                        <xp:selectItems id="selectItems2">
                            <xp:this.value><![CDATA[#{javascript:var result = [];
var product = @DbLookup("" , "keywords","Product Sample List", 2)
result.push("");
for (var i = 0; i < product.length; i++) {
  var eachName = product[i];
  result.push(eachName);
}
return result;}]]></xp:this.value>
                        </xp:selectItems>
                    <xp:eventHandler event="onchange" submit="true" refreshMode="partial" refreshId="sampleSubmitCheck1" execMode="partial">
                        <xp:this.action>
                            <xp:executeScript>
                                <xp:this.script><![CDATA[#{javascript:var comboBox2:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox2");
var sampleSubmitCheck1:com.ibm.xsp.component.xp.XspInputText = getComponent("sampleSubmitCheck1");
if(comboBox2.getValue()!==null){
    sampleSubmitCheck1.setValue('Selected');
    } 
if(comboBox2.getValue()==null) {
    sampleSubmitCheck1.setValue('');
    }}]]></xp:this.script>
                            </xp:executeScript>
                        </xp:this.action></xp:eventHandler></xp:comboBox>

Solution

  • Here is how you could find out:

    var comboBox2:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox2");
    var cb2value = comboBox2.getvalue();
    return typeof cb2value;
    

    But a better way to do this is to get the data from the bound data source like this:

    var cb2value = document1.getItemValueString("Sample_Prod1");
    return ("".equals(cb2value)) ? "blank" : cb2value;