I am using a sample database from the book "Mastering XPages - Second Editon" (chap11e2b.nsf), where they created an extended rich text editor. There is a managed bean that is used to get/set the field value. In the sample, the custom control is using this as
<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>
...
I need to check a field so I know which field to use in the control, the standard "Body" field or the "BodyHTMLMime" in case the document has a flag (field called "converted") set to "1".
How can that be done in EL language, or how can I use the rteBean.['pageDocument.Body'] in SSJS?
Worst case I create two controls and hid eacocrding to the flag, but I'm sure that is not necessary a sit can be done at the data property level.
Thanks :)
EDIT:
My code is now this:
<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>
...
Here is the error I get with this code:
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)