Fórum

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

Mike Harris, modificado 12 Anos atrás.

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

Junior Member Postagens: 91 Data de Entrada: 28/03/11 Postagens Recentes
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 12 Anos atrás.

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

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
[Ljava.lang.String] means it's an array of strings, not a simple string.

Try $customField[0]
Mike Harris, modificado 12 Anos atrás.

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

Junior Member Postagens: 91 Data de Entrada: 28/03/11 Postagens Recentes
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 12 Anos atrás.

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

Junior Member Postagens: 91 Data de Entrada: 28/03/11 Postagens Recentes
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 12 Anos atrás.

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

Liferay Legend Postagens: 14919 Data de Entrada: 02/09/06 Postagens Recentes
According to this, the $customField[0] should work.
Mike Harris, modificado 12 Anos atrás.

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

Junior Member Postagens: 91 Data de Entrada: 28/03/11 Postagens Recentes
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 7 Anos atrás.

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

New Member Postagens: 5 Data de Entrada: 28/07/15 Postagens Recentes
You could also use $customField.get(0)