You can't directly reference instance fields in Velocity:  see the user's guide 
"References" section.  Here's the relevant part.

"Note: References to instance variables in a template are not resolved. Only 
references to the attribute equivalents of JavaBean getter/setter methods are resolved 
(i.e. $foo.Name does resolve to the class Foo's getName() instance method, but not to 
a public Name instance variable of Foo)."

Add a method "getFName()" and reference it like "$fkb.FName".  That should work.

>>> [EMAIL PROTECTED] 03/08/04 12:13AM >>>
Hi, I am just wondering how to access the instance field of my class in
velocity template. Here is the description of the problem:
 
I have a user defined class as follows:
 
package org.apache.jetspeed.modules.actions.portlets;
import java.util.*;
public class Feedback
  {
    public String fname;
    public String fcomment;
    public String fbug;
    public Feedback(String fn, String fc, String fb)
    {
      this.fname = fn;
      this.fcomment = fc;
      this.fbug = fb;
    }
}
 
I add this class to a list vector which I put into the context
eventually. All goes fine unitl this.
 
But, when I use following velocity template, I don't see my values. I
found that $fbk has this:
[EMAIL PROTECTED]
 
<table>
  <tr>
    <td>
      <table border="true" cellspacing="1" cellpadding="3">
        <tr>
          #foreach ($fhdr in ["Name","Comment","Bug"])
          #headerCell ($fhdr)
          #end
        </tr>
 
        #foreach ($fbk in $feedbacks)
        <tr>
          <td>$fbk.fname</td>
          <td>$fbk.fcomment</td>
          <td>$fbk.fbug</td>  
        </tr>
        #end
      </table>
    </td>
  </tr>
</table>

I am sure, I am missing something very basic and key concept here. Any
help will be very useful.
 
_________________________
Manish Kumar
Project Manager
Infosys Technologies Ltd.
Tel: (408) 853-2346
Bldg - J, San Jose.
_________________________
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to