xpagesbeast
xpagesbeast

Reputation: 816

How to convert int to string in Expression Language?

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?

Upvotes: 1

Views: 5187

Answers (2)

Gary Forbis
Gary Forbis

Reputation: 888

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.)

Upvotes: 4

Maire Kehoe - IBM
Maire Kehoe - IBM

Reputation: 491

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')}"/>

Upvotes: 2

Related Questions