Foros de discusión

[RESOLVED] How to display the value of a String in Velocity Template

Mike Harris, modificado hace 12 años.

[RESOLVED] How to display the value of a String in Velocity Template

Junior Member Mensajes: 91 Fecha de incorporación: 28/03/11 Mensajes recientes
I'm using this to display a custom field of a page in a velocity template :

  #set ($customField= $layout.getExpandoBridge().getAttribute("CustomFieldKey"))
  CustomFieldKey= $customField


This works but it's displaying the object's memory address like [Ljava.lang.String;@6842333]
How can I display it's value?

I tried $customField.toString() (same thing)
or
#set ($customField= (String)$layout.getExpandoBridge().getAttribute("CustomFieldKey"))
doesn't work either
thumbnail
David H Nebinger, modificado hace 12 años.

RE: How to display the value of a String in Velocity Template

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
[Ljava.lang.String] means it's an array of strings, not a simple string.

Try $customField[0]
Mike Harris, modificado hace 12 años.

RE: How to display the value of a String in Velocity Template

Junior Member Mensajes: 91 Fecha de incorporación: 28/03/11 Mensajes recientes
This doesn't work for me.
It shows the same thing with the index after like :
[Ljava.lang.String;@5d8280c7[0]

emoticon
Mike Harris, modificado hace 12 años.

RE: How to display the value of a String in Velocity Template

Junior Member Mensajes: 91 Fecha de incorporación: 28/03/11 Mensajes recientes
Here's what I tried... Nothing of these works:

#set ($customField = $layout.getExpandoBridge().getAttribute("CustomField"))

<br>Test 1 : $customField.get(0)

#set($customField2 = $customField .get(0))
<br>Test 2 : $customField2

<br>Test 3 : $customField [0]

#set($customField4 = $customField[0])
<br>Test 4 : $customField4

(test 4 gives me a stack trace)
thumbnail
David H Nebinger, modificado hace 12 años.

RE: How to display the value of a String in Velocity Template

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
According to this, the $customField[0] should work.
Mike Harris, modificado hace 12 años.

RE: How to display the value of a String in Velocity Template

Junior Member Mensajes: 91 Fecha de incorporación: 28/03/11 Mensajes recientes
Well, it never worked... I used a foreach instead like this :

#set ($testItems = $page.getExpandoBridge().getAttribute("Custom Field Name"))

#set ($myVar = 'Default value')

#foreach( $testItem in $testItems)
#set ($myVar = $testItem )
#end

$myVar
thumbnail
Daniel Carrillo Broeder, modificado hace 7 años.

RE: [RESOLVED] How to display the value of a String in Velocity Template

New Member Mensajes: 5 Fecha de incorporación: 28/07/15 Mensajes recientes
You could also use $customField.get(0)