XPages EL:添加条件以选择字段名称

时间:2016-01-27 20:25:54

标签: xpages xpages-ssjs

我正在使用“Mastering XPages - Second Editon”(chap11e2b.nsf)一书中的示例数据库,他们在这里创建了一个扩展的富文本编辑器。有一个托管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”,以防文档有一个标志(字段称为“转换”)设置为“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$1.invokeContextCallback(AjaxUtilEx.java:194)
    at javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:862)

1 个答案:

答案 0 :(得分:1)

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]}">