Xpages 自定义控件:将复合数据值放入 SSJS 函数 [英] Xpages Custom Control: Putting compositeData value in an SSJS Function
问题描述
我正在发布用于解决此问题的代码.感谢 Per、Eric McCormick 和 Paul Withers.
<xp:this.value><![CDATA[$(document).ready(功能() {x$("#{javascript:return getComponent(compositeData.fieldName).getClientId(facesContext);}").select2({占位符:选择一名员工",允许清除:真,最小搜索结果:3})});]]></xp:this.value></xp:scriptBlock>
对我的上一个问题的回答非常有用.我正在制作一个 Select2 自定义控件,需要在 SSJS 函数中使用动态生成的 ID
我通过给它 fieldName 动态创建自定义控件中字段的 id,如下所示:
id="${javascript:compositeData.fieldName}"
在我的 CC 的其他部分,我使用该计算来访问 ID 号,例如:
</xp:message>
但是在构建我的 Select2 CC 时,我需要在脚本中添加一些 SSJS,如下所示:
<xp:this.value><![CDATA[$(文件).准备好(功能() {x$("#{id:[compositeData.fieldName]}").select2({占位符:选择一个员工",允许清除:真});});]]></xp:this.value></xp:scriptBlock>
但这行不通.我不知道如何动态生成 ID.
x$("#{id:[compositeData.fieldName]}")<?xml version="1.0" encoding="UTF-8"?><xp:查看xmlns:xp="http://www.ibm.com/xsp/core"id="view1"><xp:scriptBlock id="scriptBlock2"><xp:this.value><![CDATA[$(文件).准备好(功能() {x$("#{id:[compositeData.fieldName]}").select2({占位符:选择一个员工",允许清除:真});});]]></xp:this.value></xp:scriptBlock><xp:div><xp:this.styleClass><![CDATA[#{javascript:"form-group" + (getComponent(compositeData.fieldName).isValid() ? "" : " has-error")}]]></xp:this.styleClass><xp:标签styleClass="控制标签"for="#{javascript:compositeData.fieldLabel}"value="${compositeData.fieldLabel}"/><div class=""><xp:comboBoxid="${javascript:compositeData.fieldName}"value="#{compositeData.dataSource[compositeData.fieldName]}"required="${compositeData.required}"><xp:selectItemsvalue="${javascript:'#{CacheBean.'+compositeData.cacheItem+'}'}"></xp:selectItems><xp:this.validators><xp:validateRequired message="#{javascript:compositeData.fieldLabel + ' is required'}"></xp:validateRequired></xp:this.validators></xp:comboBox><xp:脚本块id="scriptBlock1"><xp:this.value><![CDATA[x$("#{id:comboBox5}").select2({minimumResultsForSearch:5});]]></xp:this.value></xp:scriptBlock><xp:文本逃脱=真"id="computedField1"styleClass="帮助块"value="${compositeData.helpText}"><xp:this.rendered><![CDATA[#{javascript:(getComponent(compositeData.fieldName).isValid()) &&CompositeData.helpText != null}]]></xp:this.rendered></xp:text><xp:消息id="message1"for="#{javascript:compositeData.fieldName}"styleClass="help-block"></xp:message>
</xp:div><xp:text escape="true" id="computedField2"value="${javascript:'#{id.'+compositeData.fieldName+'}'}"></xp:text></xp:view>
您可以使用 SSJS 函数 getClientId()
从客户端 JS(使用 SSJS)获取动态生成的 id.所以在你的情况下,它与 x$ 函数结合起来看起来像这样:
x$('#{javascript:getClientId(compositeData.fieldName)}')
I am posting the code that I used to solve this. Thanks to Per and Eric McCormick and Paul Withers.
<xp:scriptBlock id="scriptBlock2">
<xp:this.value><![CDATA[$(document).ready(
function() {
x$("#{javascript:return getComponent(compositeData.fieldName).getClientId(facesContext);}").select2({
placeholder : "Choose an employee",
allowClear: true,
minimumResultsForSearch : 3
})
}
);
]]>
</xp:this.value>
</xp:scriptBlock>
The answer to my previous question was incredibly useful. I am making a Select2 custom control and need to use the dynamically generated ID in an SSJS function
I am dynamically creating the id of the field in the custom control by giving it the fieldName, like so:
id="${javascript:compositeData.fieldName}"
In other parts of my CC I use that computation to access the id number, for example:
<xp:message
id="message1"
for="#{javascript:compositeData.fieldName}"
styleClass="help-block">
</xp:message>
However in building my Select2 CC I need to add some SSJS in script, like so:
<xp:scriptBlock id="scriptBlock2">
<xp:this.value><![CDATA[
$(document).ready(
function() {
x$("#{id:[compositeData.fieldName]}").select2({
placeholder: "Select An Employee",
allowClear: true
});
}
);
]]></xp:this.value>
</xp:scriptBlock>
But this doesn't work. I cannot figure out how to dynamically generate the ID.
x$("#{id:[compositeData.fieldName]}")
<?xml version="1.0" encoding="UTF-8"?>
<xp:view
xmlns:xp="http://www.ibm.com/xsp/core"
id="view1">
<xp:scriptBlock id="scriptBlock2">
<xp:this.value><![CDATA[
$(document).ready(
function() {
x$("#{id:[compositeData.fieldName]}").select2({
placeholder: "Select An Employee",
allowClear: true
});
}
);
]]></xp:this.value>
</xp:scriptBlock>
<xp:div>
<xp:this.styleClass><![CDATA[#{javascript:"form-group" + (getComponent(compositeData.fieldName).isValid() ? "" : " has-error")}]]></xp:this.styleClass>
<xp:label
styleClass="control-label"
for="#{javascript:compositeData.fieldLabel}"
value="${compositeData.fieldLabel}" />
<div class="">
<xp:comboBox
id="${javascript:compositeData.fieldName}"
value="#{compositeData.dataSource[compositeData.fieldName]}"
required="${compositeData.required}">
<xp:selectItems
value="${javascript:'#{CacheBean.'+compositeData.cacheItem+'}'}">
</xp:selectItems>
<xp:this.validators>
<xp:validateRequired message="#{javascript:compositeData.fieldLabel + ' is required'}"></xp:validateRequired>
</xp:this.validators>
</xp:comboBox>
<xp:scriptBlock
id="scriptBlock1">
<xp:this.value>
<![CDATA[x$("#{id:comboBox5}").select2({minimumResultsForSearch:5});]]>
</xp:this.value>
</xp:scriptBlock>
<xp:text
escape="true"
id="computedField1"
styleClass="help-block"
value="${compositeData.helpText}">
<xp:this.rendered><![CDATA[#{javascript:(getComponent(compositeData.fieldName).isValid()) && compositeData.helpText != null}]]></xp:this.rendered>
</xp:text>
<xp:message
id="message1"
for="#{javascript:compositeData.fieldName}"
styleClass="help-block">
</xp:message>
</div>
</xp:div>
<xp:text escape="true" id="computedField2"
value="${javascript:'#{id.'+compositeData.fieldName+'}'}">
</xp:text>
</xp:view>
You can get the dynamically generated id from client side JS (using SSJS) by using the SSJS function getClientId()
. So in your case it will look like this combined with the x$ function:
x$('#{javascript:getClientId(compositeData.fieldName)}')
这篇关于Xpages 自定义控件:将复合数据值放入 SSJS 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!