1

I am working in XPages (JSF View controller). In my DataTable, I want to create a html attribute data-dmrkey="##"

Here is the XML Markup on the page. Builds fine.

<xp:attr name="data-dmrkey" value="#{rowData.dmrkey}"></xp:attr>

At runtime I get this message

javax.faces.FacesException: java.lang.ClassCastException: java.lang.Long incompatible with java.lang.String javax.faces.component.UIComponent.invokeOnComponent(UIComponent.java:865) com.ibm.xsp.component.UIDataPanelBase.invokeOnComponent(UIDataPanelBase.java:416)

Is there a Expression Language way to convert this primitive type to a String?

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
xpagesbeast
  • 776
  • 1
  • 10
  • 21
  • The current work around is adding a method getDisplayDmrkey() and binding to rowData.displayDmrkey in the wrapper class. – xpagesbeast Jan 26 '17 at 15:18

2 Answers2

4

I know this question has been out here a while, but this will work:

value="0#{rowData.drmKey}"

This takes advantage of the way java auto-converts numbers to string when concatenating. When calculating that value it returns "0"+rowData.drmKey, which converts it to a String with a leading zero - which can then be parsed back into a Long (or Integer, etc.)

Gary Forbis
  • 868
  • 1
  • 8
  • 19
  • 1
    this works avoiding the exception error, but warning that it concatenates a zero to whatever the object returns. You may have to strip off the leading '0' if that causes issues matching. – xpagesbeast Dec 28 '18 at 04:05
2

Not sure about converting to String in EL, but if you change the expression to JavaScript, the attribute works OK:

<xp:attr name="someAttr" value="#{javascript:rowData.getColumnValue('someIntField')}"/>
  • The object rowData is a Java object model wrapper, data is from the AS400. what I have been doing is creating in the wrapper class , a method like getDisplayDmrkey() and return the string value. – xpagesbeast Jan 26 '17 at 15:16
  • Maire, can you contribute to this question http://stackoverflow.com/questions/41877024/devops-with-xpages-on-premesis-or-paas-like-bluemix – xpagesbeast Jan 26 '17 at 15:37