在XPages中使用dojox.form.CheckedMultiSelect时无法获取值
在我的XPage中,我将在XPages中使用dojox.form.CheckedMultiSelect时无法获取值,dojo,xpages,Dojo,Xpages,在我的XPage中,我将xp:comboBox和dojoType设置为dojox.form.CheckedMultiSelect。当我尝试使用getComponent(“comboBox1”).getValue()在SSJS中获取其值时,它返回null。如果我删除了dojoType,那么代码就可以工作了 以下是完整的代码: <?xml version="1.0" encoding="UTF-8"?> <xp:view xmlns:xp="http://www.ibm.com/x
xp:comboBox
和dojoType
设置为dojox.form.CheckedMultiSelect
。当我尝试使用getComponent(“comboBox1”).getValue()在SSJS中获取其值时,它返回null
。如果我删除了dojoType
,那么代码就可以工作了
以下是完整的代码:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.resources>
<xp:dojoModule name="dojox.form.CheckedMultiSelect"></xp:dojoModule>
<xp:styleSheet href="/.ibmxspres/dojoroot/dojox/form/resources/CheckedMultiSelect.css"></xp:styleSheet>
</xp:this.resources>
<xp:comboBox id="comboBox1" dojoType="dojox.form.CheckedMultiSelect">
<xp:selectItem itemLabel="Untitled 1"></xp:selectItem>
<xp:selectItem itemLabel="Untitled 2"></xp:selectItem>
<xp:selectItem itemLabel="Untitled 3"></xp:selectItem>
</xp:comboBox>
<xp:comboBox id="comboBox2">
<xp:selectItem itemLabel="Untitled 1"></xp:selectItem>
<xp:selectItem itemLabel="Untitled 2"></xp:selectItem>
<xp:selectItem itemLabel="Untitled 3"></xp:selectItem>
</xp:comboBox>
<xp:button value="Label" id="button1">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:print("============ " + getComponent("comboBox1").getValue());
print("============ " + getComponent("comboBox2").getValue());}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:view>
I上面的代码comboBox1
将dojoType
设置为dojox.form。选中MultiSelect
,而comboBox2
是普通组合框。单击按钮时,comboBox2
的值将打印在控制台上,而对于comboBox1
它将打印空值
为什么会发生这种情况?如何从comboBox1
中获取值?我假设它与dojo如何重写此控件以实现此目的有关。如果查看生成的源代码,组合框如下所示:
<select>
<option></option>
...
</select>
在该div中有许多div,每个选项对应一个div,所选div具有属性aria selected=“true”
,您必须搜索该div并从内部获取值
除非您可以在dojo文档中找到详细说明如何提取值的内容(我不能)
2012年6月29日更新(纳维):
谢谢西蒙,你对Dojo重写的看法完全正确。我能够使用客户端javascript通过以下代码获得所选值:
dijit.byId("#{id:comboBox1}").get("value")
我使用onClick
事件将所选值放入字段中,然后在服务器端javascript中获取该字段值。我知道一件简单的事情需要做很多工作,但它很有效。如果你有更好的解决方案,那就分享吧。你提到的dojoType还没有SS getValue()。但是,使用dijit.byId(“id”).getValue()获取值CS相当简单。在隐藏输入的帮助下,您有了解决方法。我粘贴了下面的示例:
<xp:comboBox id="comboBox1" dojoType="dojox.form.CheckedMultiSelect">
<xp:selectItem itemLabel="Untitled 1"></xp:selectItem>
<xp:selectItem itemLabel="Untitled 2"></xp:selectItem>
<xp:selectItem itemLabel="Untitled 3"></xp:selectItem>
</xp:comboBox>
<xp:inputHidden id="inputHidden1"></xp:inputHidden>
<xp:button value="Label" id="button5">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:
print("Submitting: " + getComponent("inputHidden1").getValue());
}]]></xp:this.action>
<xp:this.script><![CDATA[dojo.byId("#{id:inputHidden1}").value = dijit.byId("#{id:comboBox1}").getValue();]]></xp:this.script>
</xp:eventHandler>
</xp:button>
我注意到您自己已经找到了答案:)一个改进(如我的示例所示)可能是通过按钮设置并获取submitEvent中“helperField”的值。如果用户未单击任何单选按钮且未设置默认值,则不会在“helperField”中设置任何数据(即使选择了一个),因为onClick事件未触发。
<xp:comboBox id="comboBox1" dojoType="dojox.form.CheckedMultiSelect">
<xp:selectItem itemLabel="Untitled 1"></xp:selectItem>
<xp:selectItem itemLabel="Untitled 2"></xp:selectItem>
<xp:selectItem itemLabel="Untitled 3"></xp:selectItem>
</xp:comboBox>
<xp:inputHidden id="inputHidden1"></xp:inputHidden>
<xp:button value="Label" id="button5">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:
print("Submitting: " + getComponent("inputHidden1").getValue());
}]]></xp:this.action>
<xp:this.script><![CDATA[dojo.byId("#{id:inputHidden1}").value = dijit.byId("#{id:comboBox1}").getValue();]]></xp:this.script>
</xp:eventHandler>
</xp:button>