XPages get Value selected from combo box

2019-08-05 02:43发布

问题:

I want to display the selected value from the comboBox into a label.

<xp:label id="label4">

    <xp:this.value><![CDATA[#{javascript:var componenta = Contr.getItemValueString("txt_tipcontractcv");

if (componenta == "")
{ return "void";}

if (componenta !="")
{ return "My value is "+componenta}}]]></xp:this.value>
</xp:label>

The label is on a panel, and I did a partial refresh to the respective panel. My comboBox is binded to a data element.

label4 is always void. Why? Thank you,

Florin

回答1:

I changed code into:

var componenta = getComponent("combo").getValue();

if ((componenta == null) || (null == componenta))
{ return "void";}

else if ((componenta != null) || (null != componenta))
{ return "My value is "+componenta}  

and now it returns : My value is It seems that componenta is an empty string. Why?



回答2:

Try Contr.getValue("txt_tipcontractcv") (assuming that Contr is your datasource).



回答3:

The reason is the value selected is not sent to the server. Could you give us the code for combobox, and panel with label. It will give us clear idea for the cause

  1. Are you using partial execution mode?
  2. Is combo box bind to data source value="Contr.txt_tipcontractcv"?

You may also code the label as below, if that suits

<xp:label id="label4" value="Contr.txt_tipcontractcv" />