Forums de discussion
[RESOLVED] How to display the value of a String in Velocity Template
Mike Harris, modifié il y a 11 années.
[RESOLVED] How to display the value of a String in Velocity Template
Junior Member Publications: 91 Date d'inscription: 28/03/11 Publications récentes
I'm using this to display a custom field of a page in a velocity template :
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
#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
David H Nebinger, modifié il y a 11 années.
RE: How to display the value of a String in Velocity Template
Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
[Ljava.lang.String] means it's an array of strings, not a simple string.
Try $customField[0]
Try $customField[0]
Mike Harris, modifié il y a 11 années.
RE: How to display the value of a String in Velocity Template
Junior Member Publications: 91 Date d'inscription: 28/03/11 Publications récentes
This doesn't work for me.
It shows the same thing with the index after like :
[Ljava.lang.String;@5d8280c7[0]
It shows the same thing with the index after like :
[Ljava.lang.String;@5d8280c7[0]
Mike Harris, modifié il y a 11 années.
RE: How to display the value of a String in Velocity Template
Junior Member Publications: 91 Date d'inscription: 28/03/11 Publications récentes
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)
#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)
David H Nebinger, modifié il y a 11 années.
RE: How to display the value of a String in Velocity Template
Liferay Legend Publications: 14914 Date d'inscription: 02/09/06 Publications récentes
Mike Harris, modifié il y a 11 années.
RE: How to display the value of a String in Velocity Template
Junior Member Publications: 91 Date d'inscription: 28/03/11 Publications récentes
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
#set ($testItems = $page.getExpandoBridge().getAttribute("Custom Field Name"))
#set ($myVar = 'Default value')
#foreach( $testItem in $testItems)
#set ($myVar = $testItem )
#end
$myVar
Daniel Carrillo Broeder, modifié il y a 7 années.
RE: [RESOLVED] How to display the value of a String in Velocity Template
New Member Publications: 5 Date d'inscription: 28/07/15 Publications récentes
You could also use $customField.get(0)