XPages EL:向 select 字段名称添加条件
XPages EL: adding a condition to select field name
我正在使用 "Mastering XPages - Second Editon" (chap11e2b.nsf) 一书中的示例数据库,他们在其中创建了一个扩展的富文本编辑器。有一个用于 get/set 字段值的托管 bean。在示例中,自定义控件将其用作
<mxpd2:inputRichText id="inputRichTextExtended"
style="width:100%" htmlFilter="identity"
htmlFilterIn="identity" disableModifiedFlag="false"
htmlConversionWarning="noWarning">
<mxpd2:this.value><![CDATA[#{rteBean['pageDocument.Body']}]]></mxpd2:this.value>
...
我需要检查一个字段以便我知道在控件中使用哪个字段,标准 "Body" 字段或 "BodyHTMLMime" 以防文档有标志(字段称为 "converted") 设置为“1”。
如何用 EL 语言完成,或者如何在 SSJS 中使用 rteBean。['pageDocument.Body']?
最坏的情况是我创建了两个控件并将 eacocrding 隐藏到标志中,但我确信没有必要在数据 属性 级别完成坐下。
谢谢:)
编辑:
我的代码现在是这样的:
<xp:text escape="true" id="BodyFieldName">
<xp:this.value><![CDATA[#{javascript://sessionScope.BodyFieldName = 'pageDocument.Body';
viewScope.BodyFieldName = pageDocument.getItemValueString("v2_convertedtomime") == "1" ? "pageDocument.BodyHTMLMime" : "pageDocument.Body";
viewScope.BodyFieldName; }]]>
</xp:this.value>
</xp:text>
<mxpd2:inputRichText id="inputRichTextExtended"
style="width:100%" htmlFilter="identity" htmlFilterIn="identity"
disableModifiedFlag="false" htmlConversionWarning="noWarning"
value="#{rteBean[viewScope.BodyFieldName]}">
<xp:this.converter>
<xp:converter
converterId="InputRichTextConverter">
</xp:converter>
</xp:this.converter>
...
这是我用这段代码得到的错误:
1/28/16 1:45 PM: Exception Thrown
Context Path: /dev/x_docCLQC.nsf
Page Name: /page.xsp
javax.faces.FacesException: java.lang.StringIndexOutOfBoundsException
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:865)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.extlib.component.layout.UIVarPublisherBase.invokeOnComponent(UIVarPublisherBase.java:155)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIViewRootEx.invokeOnComponent(UIViewRootEx.java:1552)
at com.ibm.xsp.util.AjaxUtilEx.renderAjaxPartialLifecycle(AjaxUtilEx.java:188)
at com.ibm.xsp.webapp.FacesServletEx.renderAjaxPartial(FacesServletEx.java:249)
at com.ibm.xsp.webapp.FacesServletEx.serviceAjaxPartialView(FacesServletEx.java:200)
at com.ibm.xsp.webapp.FacesServletEx.serviceAjaxPartialViewSync(FacesServletEx.java:176)
at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:155)
at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1335)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:853)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1319)
at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662)
at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:357)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:313)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
Caused by: java.lang.StringIndexOutOfBoundsException
at java.lang.String.substring(String.java:1111)
at mxpd2.component.InputRichText.getObjectBinding(InputRichText.java:53)
at mxpd2.component.InputRichText.processAjaxRequest(InputRichText.java:99)
at com.ibm.xsp.util.AjaxUtilEx.invokeContextCallback(AjaxUtilEx.java:194)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:862)
inputRichText 的值必须是 EL,因为它使用了 rteBean 的 getter 和 setter。
计算字段名称并将其放入 viewScope 变量。
在 EL 中使用 viewScope 变量作为字段名称:
<xp:text
escape="true"
id="computedField1">
<xp:this.value><![CDATA[#{javascript:
viewScope.fieldName = document1.getItemValueString("converted") == "1" ? "document1.BodyHTMLMime" : "document1.Body1";
""}]]></xp:this.value>
</xp:text>
<xp:div themeId="container" style="width:800px">
<mxpd2:inputRichText id="inputRichText1"
value="#{rteBean[viewScope.fieldName]}">
我正在使用 "Mastering XPages - Second Editon" (chap11e2b.nsf) 一书中的示例数据库,他们在其中创建了一个扩展的富文本编辑器。有一个用于 get/set 字段值的托管 bean。在示例中,自定义控件将其用作
<mxpd2:inputRichText id="inputRichTextExtended"
style="width:100%" htmlFilter="identity"
htmlFilterIn="identity" disableModifiedFlag="false"
htmlConversionWarning="noWarning">
<mxpd2:this.value><![CDATA[#{rteBean['pageDocument.Body']}]]></mxpd2:this.value>
...
我需要检查一个字段以便我知道在控件中使用哪个字段,标准 "Body" 字段或 "BodyHTMLMime" 以防文档有标志(字段称为 "converted") 设置为“1”。
如何用 EL 语言完成,或者如何在 SSJS 中使用 rteBean。['pageDocument.Body']?
最坏的情况是我创建了两个控件并将 eacocrding 隐藏到标志中,但我确信没有必要在数据 属性 级别完成坐下。
谢谢:)
编辑:
我的代码现在是这样的:
<xp:text escape="true" id="BodyFieldName">
<xp:this.value><![CDATA[#{javascript://sessionScope.BodyFieldName = 'pageDocument.Body';
viewScope.BodyFieldName = pageDocument.getItemValueString("v2_convertedtomime") == "1" ? "pageDocument.BodyHTMLMime" : "pageDocument.Body";
viewScope.BodyFieldName; }]]>
</xp:this.value>
</xp:text>
<mxpd2:inputRichText id="inputRichTextExtended"
style="width:100%" htmlFilter="identity" htmlFilterIn="identity"
disableModifiedFlag="false" htmlConversionWarning="noWarning"
value="#{rteBean[viewScope.BodyFieldName]}">
<xp:this.converter>
<xp:converter
converterId="InputRichTextConverter">
</xp:converter>
</xp:this.converter>
...
这是我用这段代码得到的错误:
1/28/16 1:45 PM: Exception Thrown
Context Path: /dev/x_docCLQC.nsf
Page Name: /page.xsp
javax.faces.FacesException: java.lang.StringIndexOutOfBoundsException
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:865)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.extlib.component.layout.UIVarPublisherBase.invokeOnComponent(UIVarPublisherBase.java:155)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:878)
at com.ibm.xsp.component.UIViewRootEx.invokeOnComponent(UIViewRootEx.java:1552)
at com.ibm.xsp.util.AjaxUtilEx.renderAjaxPartialLifecycle(AjaxUtilEx.java:188)
at com.ibm.xsp.webapp.FacesServletEx.renderAjaxPartial(FacesServletEx.java:249)
at com.ibm.xsp.webapp.FacesServletEx.serviceAjaxPartialView(FacesServletEx.java:200)
at com.ibm.xsp.webapp.FacesServletEx.serviceAjaxPartialViewSync(FacesServletEx.java:176)
at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:155)
at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160)
at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138)
at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1335)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:853)
at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796)
at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565)
at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1319)
at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662)
at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:357)
at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:313)
at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272)
Caused by: java.lang.StringIndexOutOfBoundsException
at java.lang.String.substring(String.java:1111)
at mxpd2.component.InputRichText.getObjectBinding(InputRichText.java:53)
at mxpd2.component.InputRichText.processAjaxRequest(InputRichText.java:99)
at com.ibm.xsp.util.AjaxUtilEx.invokeContextCallback(AjaxUtilEx.java:194)
at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:862)
inputRichText 的值必须是 EL,因为它使用了 rteBean 的 getter 和 setter。
计算字段名称并将其放入 viewScope 变量。
在 EL 中使用 viewScope 变量作为字段名称:
<xp:text
escape="true"
id="computedField1">
<xp:this.value><![CDATA[#{javascript:
viewScope.fieldName = document1.getItemValueString("converted") == "1" ? "document1.BodyHTMLMime" : "document1.Body1";
""}]]></xp:this.value>
</xp:text>
<xp:div themeId="container" style="width:800px">
<mxpd2:inputRichText id="inputRichText1"
value="#{rteBean[viewScope.fieldName]}">