You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Paul Goepfert <pa...@gmail.com> on 2005/06/14 02:54:03 UTC

Need help displaying Innformation on a template

Ok this here is my problem.  I  have a web page that I want to be able 
to display dynamic content on.  In my source program I have a Vector of 
objects that I have fields in it like first name, Last name, and 
address.  I want to be able to access these fields.  In my webpage I 
have an if statement (#if($Array))  and a #foreach statement my #foreach 
statement is
#foreach ($person in $Array) and I have calls like $person.getFirst() in 
my webpage.  I  have created a method that should fill up the variable 
Array and then merge that with velocity template.  However when I try 
and view the dynamic content All I get is  the else block in my web 
page.  If  you need more information let me know.

-Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Need help displaying Innformation on a template

Posted by Paul Goepfert <pa...@gmail.com>.
Well I think that's what it was. I didn't output the writer object. I 
was able to use System.out.println(writer.toString()); to view the html 
code.  It was printed to my debugging screen.  How would I be able to do 
the same but have it be printed to a web page?  I am still  new to web 
programming. 

-Paul

Simon Christian wrote:

>Hi Paul,
>
>One thing I thought worth checking with the code you've shown, which I'm
>guessing now has been changed to something like this:
>
>public void createContext(InfoBean [] array)
>{
>  Velocity.init();
>  Template template = null;
>  template = Velocity.getTemplate("/sortResults.vm");
>  VelocityContext context = new VelocityContext();
>  removeInsert(array);
>
>  <Map<String,String>> vecInfo = data.getInformation();
>  context.put("Array", vecInfo)
>
>  StringWriter writer = new StringWriter ();
>  template.merge(context, writer);
>}
>
>In this code, you never *do* anything with the writer after the merge
>i.e. the contents of the writer aren't returned and it's not printed
>anywhere in that method. Can you confirm that you are actually seeing
>the results of doing the template merge from this method, and not
>perhaps from some other method?
>
>- simon
>
>
>Paul Goepfert wrote:
>  
>
>>I haven't yet tried to compile with the -ea switch.  And yes I  have
>>atleast jdk 1.4.2 running.  Anyway Yesterday I decided to put my program
>>through a debugger.  I am  using the Netbeans 4.1 debugger.  I can now
>>say that I believe that the context.put("Array", vecInfo); ois noow
>>working.  However when it comes time to display the contents on my
>>webpage I still get put  into the #else box rather then the body of the
>>#if.  Can anyone tell me what I am doing wrong.  My code is in previous
>>posts.
>>
>>A few things to note in my velocity template I  have changed the method
>>calls to just variable names.  Also I  have included List <Map<String,
>>String>> vecInfo = data.getInformation(); context.put("Array", vecInfo);
>>into my create context method.
>>
>>-Paul
>>Jack Holt wrote:
>>
>>    
>>
>>>Sorry.  In order for the assert to actually do anything, you have to
>>>add the -ea switch to the java command (I'm assuming you're using at
>>>least J2SE 1.4 since you apparently didn't have a problem compiling).
>>>
>>>On 6/15/05, Paul Goepfert <pa...@gmail.com> wrote:
>>> 
>>>
>>>      
>>>
>>>>Well I just tried the code you just gave me Jack.  I don't think it
>>>>threw an exception.  However I still get the else block rather then
>>>>getting the contents of my vector.  I tried to use the other code that
>>>>was posted but I couldn't find the method getRequestScope() in the
>>>>VelocityContext class.
>>>>
>>>>-Paul
>>>>
>>>>Jack Holt wrote:
>>>>
>>>>  
>>>>
>>>>        
>>>>
>>>>>Try replacing "context.put("Array",  getInformation());" with
>>>>>
>>>>>Vector vecInfo = getInformation();
>>>>>assert vecInfo != null;
>>>>>context.put("Array", vecInfo);
>>>>>
>>>>>and let me know if the assert throws an exception.
>>>>>
>>>>>On 6/14/05, Paul Goepfert <pa...@gmail.com> wrote:
>>>>>
>>>>>
>>>>>    
>>>>>
>>>>>          
>>>>>
>>>>>>Here is my code for creating the context.   Most  of this code is
>>>>>>surrounded by try/catch blocks.  I have excluded them for space.  If
>>>>>>there is something here that is unnecessary let me  know.  I am also
>>>>>>including part of my template so you can see how I'm trying to display
>>>>>>the values.
>>>>>>
>>>>>>_________
>>>>>>Code
>>>>>>_________
>>>>>>
>>>>>>public void createContext(InfoBean [] array)
>>>>>>  {
>>>>>>      Velocity.init();
>>>>>>      Template template = null;
>>>>>>
>>>>>>      template = Velocity.getTemplate("/sortResults.vm");
>>>>>>      VelocityContext context = new VelocityContext();
>>>>>>
>>>>>>      removeInsert(array);
>>>>>>      //getInformationn returns a Vector
>>>>>>      //Each element in the Vector is of InfoBean
>>>>>>(String,String,String,String,String,String)
>>>>>>      context.put("Array",  getInformation());
>>>>>>      StringWriter writer = new StringWriter ();
>>>>>>
>>>>>>      template.merge(context, writer);
>>>>>>  }
>>>>>>
>>>>>>
>>>>>>
>>>>>>#if($Array)
>>>>>>              <table width="380" border="0" cellspacing="0"
>>>>>>cellspadding="0">
>>>>>>                  <tr>
>>>>>>                      <th width="107" scope="col">
>>>>>>                       <div align="center">$text.get("last")</div>
>>>>>>                      </th>
>>>>>>                      <th width="108" scope="col">
>>>>>>                          <div align="center">$text.get("first")</div>
>>>>>>                   </th>
>>>>>>                      <th width="165" scope="col">
>>>>>>                          <div
>>>>>>align="center">$text.get("Address")</div>
>>>>>>                      </th>
>>>>>>               </tr>
>>>>>>               #foreach($person in $Array)
>>>>>>                  <tr>
>>>>>>                      <td>$person.getLast()</td>
>>>>>>                      <td>$person.getFirst()</td>
>>>>>>                      <td>
>>>>>>                      <table width="342" border="0" cellspacing="0"
>>>>>>cellpadding="0">
>>>>>>                              <tr>
>>>>>>                               <td
>>>>>>width="386">$person.getStreet()</td>
>>>>>>                              </tr>
>>>>>>                              <tr>
>>>>>>                                  <td>$person.getCity(),
>>>>>>$person.getState() $person.getZip()</td>
>>>>>>                              </tr>
>>>>>>                          </table>
>>>>>>                      </td>
>>>>>>                  </tr>
>>>>>>              </table>
>>>>>>              <input type="submit" name="Submit" value="
>>>>>>$text.get("done") " onclick="resultsForm.action.value="done" >
>>>>>>              #end
>>>>>>              #else
>>>>>>              <p>Sorry but there is no data in the database to
>>>>>>sort.  Please
>>>>>>                 enter information in the databse </p>
>>>>>>              <input type="submit" name="Submit2" value="
>>>>>>$text.get("enter")" onclick=resultsForm.action.value="enter">
>>>>>>              #end
>>>>>>
>>>>>>-Paul
>>>>>>Jack Holt wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>      
>>>>>>
>>>>>>            
>>>>>>
>>>>>>>Could you include actual snippets of the code?  In my code that backs
>>>>>>>the Velocity templates, I'm using code like the following:
>>>>>>>
>>>>>>>// get a List of Maps. The map contains keys of "id" and "name"
>>>>>>>List<Map<String,String>> routeList = getRouteList();
>>>>>>>// the following is for Spring Web Flow but just results in the
>>>>>>>"routeList" variable ending
>>>>>>>// up in the Velocity context
>>>>>>>context.getRequestScope().setAttribute("routeList",routeList);
>>>>>>>
>>>>>>>And in the Velocity template, I'm using:
>>>>>>>
>>>>>>>#foreach($route in $routeList)
>>>>>>>$route.id
>>>>>>>$route.name
>>>>>>>#end
>>>>>>>
>>>>>>>However, I'm sure you understand that if you are getting the else
>>>>>>>block everytime, that means the $Array is either null,
>>>>>>>non-existant or
>>>>>>>false.  Are you sure that are actually placing $Array into the
>>>>>>>Velocity context?
>>>>>>>
>>>>>>>On 6/13/05, Paul Goepfert <pa...@gmail.com> wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>        
>>>>>>>
>>>>>>>              
>>>>>>>
>>>>>>>>Ok this here is my problem.  I  have a web page that I want to be
>>>>>>>>able
>>>>>>>>to display dynamic content on.  In my source program I have a
>>>>>>>>Vector of
>>>>>>>>objects that I have fields in it like first name, Last name, and
>>>>>>>>address.  I want to be able to access these fields.  In my webpage I
>>>>>>>>have an if statement (#if($Array))  and a #foreach statement my
>>>>>>>>#foreach
>>>>>>>>statement is
>>>>>>>>#foreach ($person in $Array) and I have calls like
>>>>>>>>$person.getFirst() in
>>>>>>>>my webpage.  I  have created a method that should fill up the
>>>>>>>>variable
>>>>>>>>Array and then merge that with velocity template.  However when I
>>>>>>>>try
>>>>>>>>and view the dynamic content All I get is  the else block in my web
>>>>>>>>page.  If  you need more information let me know.
>>>>>>>>
>>>>>>>>-Paul
>>>>>>>>
>>>>>>>>                
>>>>>>>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Need help displaying Innformation on a template

Posted by Simon Christian <si...@stoutstick.com>.
Hi Paul,

One thing I thought worth checking with the code you've shown, which I'm
guessing now has been changed to something like this:

public void createContext(InfoBean [] array)
{
  Velocity.init();
  Template template = null;
  template = Velocity.getTemplate("/sortResults.vm");
  VelocityContext context = new VelocityContext();
  removeInsert(array);

  <Map<String,String>> vecInfo = data.getInformation();
  context.put("Array", vecInfo)

  StringWriter writer = new StringWriter ();
  template.merge(context, writer);
}

In this code, you never *do* anything with the writer after the merge
i.e. the contents of the writer aren't returned and it's not printed
anywhere in that method. Can you confirm that you are actually seeing
the results of doing the template merge from this method, and not
perhaps from some other method?

- simon


Paul Goepfert wrote:
> I haven't yet tried to compile with the -ea switch.  And yes I  have
> atleast jdk 1.4.2 running.  Anyway Yesterday I decided to put my program
> through a debugger.  I am  using the Netbeans 4.1 debugger.  I can now
> say that I believe that the context.put("Array", vecInfo); ois noow
> working.  However when it comes time to display the contents on my
> webpage I still get put  into the #else box rather then the body of the
> #if.  Can anyone tell me what I am doing wrong.  My code is in previous
> posts.
> 
> A few things to note in my velocity template I  have changed the method
> calls to just variable names.  Also I  have included List <Map<String,
> String>> vecInfo = data.getInformation(); context.put("Array", vecInfo);
> into my create context method.
> 
> -Paul
> Jack Holt wrote:
> 
>> Sorry.  In order for the assert to actually do anything, you have to
>> add the -ea switch to the java command (I'm assuming you're using at
>> least J2SE 1.4 since you apparently didn't have a problem compiling).
>>
>> On 6/15/05, Paul Goepfert <pa...@gmail.com> wrote:
>>  
>>
>>> Well I just tried the code you just gave me Jack.  I don't think it
>>> threw an exception.  However I still get the else block rather then
>>> getting the contents of my vector.  I tried to use the other code that
>>> was posted but I couldn't find the method getRequestScope() in the
>>> VelocityContext class.
>>>
>>> -Paul
>>>
>>> Jack Holt wrote:
>>>
>>>   
>>>
>>>> Try replacing "context.put("Array",  getInformation());" with
>>>>
>>>> Vector vecInfo = getInformation();
>>>> assert vecInfo != null;
>>>> context.put("Array", vecInfo);
>>>>
>>>> and let me know if the assert throws an exception.
>>>>
>>>> On 6/14/05, Paul Goepfert <pa...@gmail.com> wrote:
>>>>
>>>>
>>>>     
>>>>
>>>>> Here is my code for creating the context.   Most  of this code is
>>>>> surrounded by try/catch blocks.  I have excluded them for space.  If
>>>>> there is something here that is unnecessary let me  know.  I am also
>>>>> including part of my template so you can see how I'm trying to display
>>>>> the values.
>>>>>
>>>>> _________
>>>>> Code
>>>>> _________
>>>>>
>>>>> public void createContext(InfoBean [] array)
>>>>>   {
>>>>>       Velocity.init();
>>>>>       Template template = null;
>>>>>
>>>>>       template = Velocity.getTemplate("/sortResults.vm");
>>>>>       VelocityContext context = new VelocityContext();
>>>>>
>>>>>       removeInsert(array);
>>>>>       //getInformationn returns a Vector
>>>>>       //Each element in the Vector is of InfoBean
>>>>> (String,String,String,String,String,String)
>>>>>       context.put("Array",  getInformation());
>>>>>       StringWriter writer = new StringWriter ();
>>>>>
>>>>>       template.merge(context, writer);
>>>>>   }
>>>>>
>>>>>
>>>>>
>>>>> #if($Array)
>>>>>               <table width="380" border="0" cellspacing="0"
>>>>> cellspadding="0">
>>>>>                   <tr>
>>>>>                       <th width="107" scope="col">
>>>>>                        <div align="center">$text.get("last")</div>
>>>>>                       </th>
>>>>>                       <th width="108" scope="col">
>>>>>                           <div align="center">$text.get("first")</div>
>>>>>                    </th>
>>>>>                       <th width="165" scope="col">
>>>>>                           <div
>>>>> align="center">$text.get("Address")</div>
>>>>>                       </th>
>>>>>                </tr>
>>>>>                #foreach($person in $Array)
>>>>>                   <tr>
>>>>>                       <td>$person.getLast()</td>
>>>>>                       <td>$person.getFirst()</td>
>>>>>                       <td>
>>>>>                       <table width="342" border="0" cellspacing="0"
>>>>> cellpadding="0">
>>>>>                               <tr>
>>>>>                                <td
>>>>> width="386">$person.getStreet()</td>
>>>>>                               </tr>
>>>>>                               <tr>
>>>>>                                   <td>$person.getCity(),
>>>>> $person.getState() $person.getZip()</td>
>>>>>                               </tr>
>>>>>                           </table>
>>>>>                       </td>
>>>>>                   </tr>
>>>>>               </table>
>>>>>               <input type="submit" name="Submit" value="
>>>>> $text.get("done") " onclick="resultsForm.action.value="done" >
>>>>>               #end
>>>>>               #else
>>>>>               <p>Sorry but there is no data in the database to
>>>>> sort.  Please
>>>>>                  enter information in the databse </p>
>>>>>               <input type="submit" name="Submit2" value="
>>>>> $text.get("enter")" onclick=resultsForm.action.value="enter">
>>>>>               #end
>>>>>
>>>>> -Paul
>>>>> Jack Holt wrote:
>>>>>
>>>>>
>>>>>
>>>>>       
>>>>>
>>>>>> Could you include actual snippets of the code?  In my code that backs
>>>>>> the Velocity templates, I'm using code like the following:
>>>>>>
>>>>>> // get a List of Maps. The map contains keys of "id" and "name"
>>>>>> List<Map<String,String>> routeList = getRouteList();
>>>>>> // the following is for Spring Web Flow but just results in the
>>>>>> "routeList" variable ending
>>>>>> // up in the Velocity context
>>>>>> context.getRequestScope().setAttribute("routeList",routeList);
>>>>>>
>>>>>> And in the Velocity template, I'm using:
>>>>>>
>>>>>> #foreach($route in $routeList)
>>>>>> $route.id
>>>>>> $route.name
>>>>>> #end
>>>>>>
>>>>>> However, I'm sure you understand that if you are getting the else
>>>>>> block everytime, that means the $Array is either null,
>>>>>> non-existant or
>>>>>> false.  Are you sure that are actually placing $Array into the
>>>>>> Velocity context?
>>>>>>
>>>>>> On 6/13/05, Paul Goepfert <pa...@gmail.com> wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>         
>>>>>>
>>>>>>> Ok this here is my problem.  I  have a web page that I want to be
>>>>>>> able
>>>>>>> to display dynamic content on.  In my source program I have a
>>>>>>> Vector of
>>>>>>> objects that I have fields in it like first name, Last name, and
>>>>>>> address.  I want to be able to access these fields.  In my webpage I
>>>>>>> have an if statement (#if($Array))  and a #foreach statement my
>>>>>>> #foreach
>>>>>>> statement is
>>>>>>> #foreach ($person in $Array) and I have calls like
>>>>>>> $person.getFirst() in
>>>>>>> my webpage.  I  have created a method that should fill up the
>>>>>>> variable
>>>>>>> Array and then merge that with velocity template.  However when I
>>>>>>> try
>>>>>>> and view the dynamic content All I get is  the else block in my web
>>>>>>> page.  If  you need more information let me know.
>>>>>>>
>>>>>>> -Paul
>>>>>>>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Need help displaying Innformation on a template

Posted by Paul Goepfert <pa...@gmail.com>.
I haven't yet tried to compile with the -ea switch.  And yes I  have 
atleast jdk 1.4.2 running.  Anyway Yesterday I decided to put my program 
through a debugger.  I am  using the Netbeans 4.1 debugger.  I can now 
say that I believe that the context.put("Array", vecInfo); ois noow 
working.  However when it comes time to display the contents on my 
webpage I still get put  into the #else box rather then the body of the 
#if.  Can anyone tell me what I am doing wrong.  My code is in previous 
posts.

A few things to note in my velocity template I  have changed the method 
calls to just variable names.  Also I  have included List <Map<String, 
String>> vecInfo = data.getInformation(); context.put("Array", vecInfo); 
into my create context method.

-Paul
Jack Holt wrote:

>Sorry.  In order for the assert to actually do anything, you have to
>add the -ea switch to the java command (I'm assuming you're using at
>least J2SE 1.4 since you apparently didn't have a problem compiling).
>
>On 6/15/05, Paul Goepfert <pa...@gmail.com> wrote:
>  
>
>>Well I just tried the code you just gave me Jack.  I don't think it
>>threw an exception.  However I still get the else block rather then
>>getting the contents of my vector.  I tried to use the other code that
>>was posted but I couldn't find the method getRequestScope() in the
>>VelocityContext class.
>>
>>-Paul
>>
>>Jack Holt wrote:
>>
>>    
>>
>>>Try replacing "context.put("Array",  getInformation());" with
>>>
>>> Vector vecInfo = getInformation();
>>> assert vecInfo != null;
>>> context.put("Array", vecInfo);
>>>
>>>and let me know if the assert throws an exception.
>>>
>>>On 6/14/05, Paul Goepfert <pa...@gmail.com> wrote:
>>>
>>>
>>>      
>>>
>>>>Here is my code for creating the context.   Most  of this code is
>>>>surrounded by try/catch blocks.  I have excluded them for space.  If
>>>>there is something here that is unnecessary let me  know.  I am also
>>>>including part of my template so you can see how I'm trying to display
>>>>the values.
>>>>
>>>>_________
>>>>Code
>>>>_________
>>>>
>>>>public void createContext(InfoBean [] array)
>>>>   {
>>>>       Velocity.init();
>>>>       Template template = null;
>>>>
>>>>       template = Velocity.getTemplate("/sortResults.vm");
>>>>       VelocityContext context = new VelocityContext();
>>>>
>>>>       removeInsert(array);
>>>>       //getInformationn returns a Vector
>>>>       //Each element in the Vector is of InfoBean (String,String,String,String,String,String)
>>>>       context.put("Array",  getInformation());
>>>>       StringWriter writer = new StringWriter ();
>>>>
>>>>       template.merge(context, writer);
>>>>   }
>>>>
>>>>
>>>>
>>>> #if($Array)
>>>>               <table width="380" border="0" cellspacing="0" cellspadding="0">
>>>>                   <tr>
>>>>                       <th width="107" scope="col">
>>>>                        <div align="center">$text.get("last")</div>
>>>>                       </th>
>>>>                       <th width="108" scope="col">
>>>>                           <div align="center">$text.get("first")</div>
>>>>                    </th>
>>>>                       <th width="165" scope="col">
>>>>                           <div align="center">$text.get("Address")</div>
>>>>                       </th>
>>>>                </tr>
>>>>                #foreach($person in $Array)
>>>>                   <tr>
>>>>                       <td>$person.getLast()</td>
>>>>                       <td>$person.getFirst()</td>
>>>>                       <td>
>>>>                       <table width="342" border="0" cellspacing="0" cellpadding="0">
>>>>                               <tr>
>>>>                                <td width="386">$person.getStreet()</td>
>>>>                               </tr>
>>>>                               <tr>
>>>>                                   <td>$person.getCity(), $person.getState() $person.getZip()</td>
>>>>                               </tr>
>>>>                           </table>
>>>>                       </td>
>>>>                   </tr>
>>>>               </table>
>>>>               <input type="submit" name="Submit" value=" $text.get("done") " onclick="resultsForm.action.value="done" >
>>>>               #end
>>>>               #else
>>>>               <p>Sorry but there is no data in the database to sort.  Please
>>>>                  enter information in the databse </p>
>>>>               <input type="submit" name="Submit2" value=" $text.get("enter")" onclick=resultsForm.action.value="enter">
>>>>               #end
>>>>
>>>>-Paul
>>>>Jack Holt wrote:
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>>>Could you include actual snippets of the code?  In my code that backs
>>>>>the Velocity templates, I'm using code like the following:
>>>>>
>>>>>// get a List of Maps. The map contains keys of "id" and "name"
>>>>>List<Map<String,String>> routeList = getRouteList();
>>>>>// the following is for Spring Web Flow but just results in the
>>>>>"routeList" variable ending
>>>>>// up in the Velocity context
>>>>>context.getRequestScope().setAttribute("routeList",routeList);
>>>>>
>>>>>And in the Velocity template, I'm using:
>>>>>
>>>>>#foreach($route in $routeList)
>>>>>$route.id
>>>>>$route.name
>>>>>#end
>>>>>
>>>>>However, I'm sure you understand that if you are getting the else
>>>>>block everytime, that means the $Array is either null, non-existant or
>>>>>false.  Are you sure that are actually placing $Array into the
>>>>>Velocity context?
>>>>>
>>>>>On 6/13/05, Paul Goepfert <pa...@gmail.com> wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>          
>>>>>
>>>>>>Ok this here is my problem.  I  have a web page that I want to be able
>>>>>>to display dynamic content on.  In my source program I have a Vector of
>>>>>>objects that I have fields in it like first name, Last name, and
>>>>>>address.  I want to be able to access these fields.  In my webpage I
>>>>>>have an if statement (#if($Array))  and a #foreach statement my #foreach
>>>>>>statement is
>>>>>>#foreach ($person in $Array) and I have calls like $person.getFirst() in
>>>>>>my webpage.  I  have created a method that should fill up the variable
>>>>>>Array and then merge that with velocity template.  However when I try
>>>>>>and view the dynamic content All I get is  the else block in my web
>>>>>>page.  If  you need more information let me know.
>>>>>>
>>>>>>-Paul
>>>>>>
>>>>>>---------------------------------------------------------------------
>>>>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>            
>>>>>>
>>>>>---------------------------------------------------------------------
>>>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>          
>>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>>
>>>
>>>
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Need help displaying Innformation on a template

Posted by Jack Holt <ja...@gmail.com>.
Sorry.  In order for the assert to actually do anything, you have to
add the -ea switch to the java command (I'm assuming you're using at
least J2SE 1.4 since you apparently didn't have a problem compiling).

On 6/15/05, Paul Goepfert <pa...@gmail.com> wrote:
> Well I just tried the code you just gave me Jack.  I don't think it
> threw an exception.  However I still get the else block rather then
> getting the contents of my vector.  I tried to use the other code that
> was posted but I couldn't find the method getRequestScope() in the
> VelocityContext class.
> 
> -Paul
> 
> Jack Holt wrote:
> 
> >Try replacing "context.put("Array",  getInformation());" with
> >
> >  Vector vecInfo = getInformation();
> >  assert vecInfo != null;
> >  context.put("Array", vecInfo);
> >
> >and let me know if the assert throws an exception.
> >
> >On 6/14/05, Paul Goepfert <pa...@gmail.com> wrote:
> >
> >
> >>Here is my code for creating the context.   Most  of this code is
> >>surrounded by try/catch blocks.  I have excluded them for space.  If
> >>there is something here that is unnecessary let me  know.  I am also
> >>including part of my template so you can see how I'm trying to display
> >>the values.
> >>
> >>_________
> >>Code
> >>_________
> >>
> >> public void createContext(InfoBean [] array)
> >>    {
> >>        Velocity.init();
> >>        Template template = null;
> >>
> >>        template = Velocity.getTemplate("/sortResults.vm");
> >>        VelocityContext context = new VelocityContext();
> >>
> >>        removeInsert(array);
> >>        //getInformationn returns a Vector
> >>        //Each element in the Vector is of InfoBean (String,String,String,String,String,String)
> >>        context.put("Array",  getInformation());
> >>        StringWriter writer = new StringWriter ();
> >>
> >>        template.merge(context, writer);
> >>    }
> >>
> >>
> >>
> >>  #if($Array)
> >>                <table width="380" border="0" cellspacing="0" cellspadding="0">
> >>                    <tr>
> >>                        <th width="107" scope="col">
> >>                         <div align="center">$text.get("last")</div>
> >>                        </th>
> >>                        <th width="108" scope="col">
> >>                            <div align="center">$text.get("first")</div>
> >>                     </th>
> >>                        <th width="165" scope="col">
> >>                            <div align="center">$text.get("Address")</div>
> >>                        </th>
> >>                 </tr>
> >>                 #foreach($person in $Array)
> >>                    <tr>
> >>                        <td>$person.getLast()</td>
> >>                        <td>$person.getFirst()</td>
> >>                        <td>
> >>                        <table width="342" border="0" cellspacing="0" cellpadding="0">
> >>                                <tr>
> >>                                 <td width="386">$person.getStreet()</td>
> >>                                </tr>
> >>                                <tr>
> >>                                    <td>$person.getCity(), $person.getState() $person.getZip()</td>
> >>                                </tr>
> >>                            </table>
> >>                        </td>
> >>                    </tr>
> >>                </table>
> >>                <input type="submit" name="Submit" value=" $text.get("done") " onclick="resultsForm.action.value="done" >
> >>                #end
> >>                #else
> >>                <p>Sorry but there is no data in the database to sort.  Please
> >>                   enter information in the databse </p>
> >>                <input type="submit" name="Submit2" value=" $text.get("enter")" onclick=resultsForm.action.value="enter">
> >>                #end
> >>
> >>-Paul
> >>Jack Holt wrote:
> >>
> >>
> >>
> >>>Could you include actual snippets of the code?  In my code that backs
> >>>the Velocity templates, I'm using code like the following:
> >>>
> >>>// get a List of Maps. The map contains keys of "id" and "name"
> >>>List<Map<String,String>> routeList = getRouteList();
> >>>// the following is for Spring Web Flow but just results in the
> >>>"routeList" variable ending
> >>>// up in the Velocity context
> >>>context.getRequestScope().setAttribute("routeList",routeList);
> >>>
> >>>And in the Velocity template, I'm using:
> >>>
> >>>#foreach($route in $routeList)
> >>> $route.id
> >>> $route.name
> >>>#end
> >>>
> >>>However, I'm sure you understand that if you are getting the else
> >>>block everytime, that means the $Array is either null, non-existant or
> >>>false.  Are you sure that are actually placing $Array into the
> >>>Velocity context?
> >>>
> >>>On 6/13/05, Paul Goepfert <pa...@gmail.com> wrote:
> >>>
> >>>
> >>>
> >>>
> >>>>Ok this here is my problem.  I  have a web page that I want to be able
> >>>>to display dynamic content on.  In my source program I have a Vector of
> >>>>objects that I have fields in it like first name, Last name, and
> >>>>address.  I want to be able to access these fields.  In my webpage I
> >>>>have an if statement (#if($Array))  and a #foreach statement my #foreach
> >>>>statement is
> >>>>#foreach ($person in $Array) and I have calls like $person.getFirst() in
> >>>>my webpage.  I  have created a method that should fill up the variable
> >>>>Array and then merge that with velocity template.  However when I try
> >>>>and view the dynamic content All I get is  the else block in my web
> >>>>page.  If  you need more information let me know.
> >>>>
> >>>>-Paul
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >>
> >>
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Need help displaying Innformation on a template

Posted by Paul Goepfert <pa...@gmail.com>.
Well I just tried the code you just gave me Jack.  I don't think it 
threw an exception.  However I still get the else block rather then 
getting the contents of my vector.  I tried to use the other code that 
was posted but I couldn't find the method getRequestScope() in the 
VelocityContext class.

-Paul

Jack Holt wrote:

>Try replacing "context.put("Array",  getInformation());" with
>
>  Vector vecInfo = getInformation();
>  assert vecInfo != null;
>  context.put("Array", vecInfo);
>
>and let me know if the assert throws an exception.
>
>On 6/14/05, Paul Goepfert <pa...@gmail.com> wrote:
>  
>
>>Here is my code for creating the context.   Most  of this code is
>>surrounded by try/catch blocks.  I have excluded them for space.  If
>>there is something here that is unnecessary let me  know.  I am also
>>including part of my template so you can see how I'm trying to display
>>the values.
>>
>>_________
>>Code
>>_________
>>
>> public void createContext(InfoBean [] array)
>>    {
>>        Velocity.init();
>>        Template template = null;
>>
>>        template = Velocity.getTemplate("/sortResults.vm");
>>        VelocityContext context = new VelocityContext();
>>
>>        removeInsert(array);
>>        //getInformationn returns a Vector
>>        //Each element in the Vector is of InfoBean (String,String,String,String,String,String)
>>        context.put("Array",  getInformation());
>>        StringWriter writer = new StringWriter ();
>>
>>        template.merge(context, writer);
>>    }
>>
>>
>>
>>  #if($Array)
>>                <table width="380" border="0" cellspacing="0" cellspadding="0">
>>                    <tr>
>>                        <th width="107" scope="col">
>>                         <div align="center">$text.get("last")</div>
>>                        </th>
>>                        <th width="108" scope="col">
>>                            <div align="center">$text.get("first")</div>
>>                     </th>
>>                        <th width="165" scope="col">
>>                            <div align="center">$text.get("Address")</div>
>>                        </th>
>>                 </tr>
>>                 #foreach($person in $Array)
>>                    <tr>
>>                        <td>$person.getLast()</td>
>>                        <td>$person.getFirst()</td>
>>                        <td>
>>                        <table width="342" border="0" cellspacing="0" cellpadding="0">
>>                                <tr>
>>                                 <td width="386">$person.getStreet()</td>
>>                                </tr>
>>                                <tr>
>>                                    <td>$person.getCity(), $person.getState() $person.getZip()</td>
>>                                </tr>
>>                            </table>
>>                        </td>
>>                    </tr>
>>                </table>
>>                <input type="submit" name="Submit" value=" $text.get("done") " onclick="resultsForm.action.value="done" >
>>                #end
>>                #else
>>                <p>Sorry but there is no data in the database to sort.  Please
>>                   enter information in the databse </p>
>>                <input type="submit" name="Submit2" value=" $text.get("enter")" onclick=resultsForm.action.value="enter">
>>                #end
>>
>>-Paul
>>Jack Holt wrote:
>>
>>    
>>
>>>Could you include actual snippets of the code?  In my code that backs
>>>the Velocity templates, I'm using code like the following:
>>>
>>>// get a List of Maps. The map contains keys of "id" and "name"
>>>List<Map<String,String>> routeList = getRouteList();
>>>// the following is for Spring Web Flow but just results in the
>>>"routeList" variable ending
>>>// up in the Velocity context
>>>context.getRequestScope().setAttribute("routeList",routeList);
>>>
>>>And in the Velocity template, I'm using:
>>>
>>>#foreach($route in $routeList)
>>> $route.id
>>> $route.name
>>>#end
>>>
>>>However, I'm sure you understand that if you are getting the else
>>>block everytime, that means the $Array is either null, non-existant or
>>>false.  Are you sure that are actually placing $Array into the
>>>Velocity context?
>>>
>>>On 6/13/05, Paul Goepfert <pa...@gmail.com> wrote:
>>>
>>>
>>>      
>>>
>>>>Ok this here is my problem.  I  have a web page that I want to be able
>>>>to display dynamic content on.  In my source program I have a Vector of
>>>>objects that I have fields in it like first name, Last name, and
>>>>address.  I want to be able to access these fields.  In my webpage I
>>>>have an if statement (#if($Array))  and a #foreach statement my #foreach
>>>>statement is
>>>>#foreach ($person in $Array) and I have calls like $person.getFirst() in
>>>>my webpage.  I  have created a method that should fill up the variable
>>>>Array and then merge that with velocity template.  However when I try
>>>>and view the dynamic content All I get is  the else block in my web
>>>>page.  If  you need more information let me know.
>>>>
>>>>-Paul
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>        
>>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>>
>>>
>>>
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Need help displaying Innformation on a template

Posted by Jack Holt <ja...@gmail.com>.
Try replacing "context.put("Array",  getInformation());" with

  Vector vecInfo = getInformation();
  assert vecInfo != null;
  context.put("Array", vecInfo);

and let me know if the assert throws an exception.

On 6/14/05, Paul Goepfert <pa...@gmail.com> wrote:
> Here is my code for creating the context.   Most  of this code is
> surrounded by try/catch blocks.  I have excluded them for space.  If
> there is something here that is unnecessary let me  know.  I am also
> including part of my template so you can see how I'm trying to display
> the values.
> 
> _________
> Code
> _________
> 
>  public void createContext(InfoBean [] array)
>     {
>         Velocity.init();
>         Template template = null;
> 
>         template = Velocity.getTemplate("/sortResults.vm");
>         VelocityContext context = new VelocityContext();
> 
>         removeInsert(array);
>         //getInformationn returns a Vector
>         //Each element in the Vector is of InfoBean (String,String,String,String,String,String)
>         context.put("Array",  getInformation());
>         StringWriter writer = new StringWriter ();
> 
>         template.merge(context, writer);
>     }
> 
> 
> 
>   #if($Array)
>                 <table width="380" border="0" cellspacing="0" cellspadding="0">
>                     <tr>
>                         <th width="107" scope="col">
>                          <div align="center">$text.get("last")</div>
>                         </th>
>                         <th width="108" scope="col">
>                             <div align="center">$text.get("first")</div>
>                      </th>
>                         <th width="165" scope="col">
>                             <div align="center">$text.get("Address")</div>
>                         </th>
>                  </tr>
>                  #foreach($person in $Array)
>                     <tr>
>                         <td>$person.getLast()</td>
>                         <td>$person.getFirst()</td>
>                         <td>
>                         <table width="342" border="0" cellspacing="0" cellpadding="0">
>                                 <tr>
>                                  <td width="386">$person.getStreet()</td>
>                                 </tr>
>                                 <tr>
>                                     <td>$person.getCity(), $person.getState() $person.getZip()</td>
>                                 </tr>
>                             </table>
>                         </td>
>                     </tr>
>                 </table>
>                 <input type="submit" name="Submit" value=" $text.get("done") " onclick="resultsForm.action.value="done" >
>                 #end
>                 #else
>                 <p>Sorry but there is no data in the database to sort.  Please
>                    enter information in the databse </p>
>                 <input type="submit" name="Submit2" value=" $text.get("enter")" onclick=resultsForm.action.value="enter">
>                 #end
> 
> -Paul
> Jack Holt wrote:
> 
> >Could you include actual snippets of the code?  In my code that backs
> >the Velocity templates, I'm using code like the following:
> >
> >// get a List of Maps. The map contains keys of "id" and "name"
> >List<Map<String,String>> routeList = getRouteList();
> >// the following is for Spring Web Flow but just results in the
> >"routeList" variable ending
> >// up in the Velocity context
> >context.getRequestScope().setAttribute("routeList",routeList);
> >
> >And in the Velocity template, I'm using:
> >
> >#foreach($route in $routeList)
> >  $route.id
> >  $route.name
> >#end
> >
> >However, I'm sure you understand that if you are getting the else
> >block everytime, that means the $Array is either null, non-existant or
> >false.  Are you sure that are actually placing $Array into the
> >Velocity context?
> >
> >On 6/13/05, Paul Goepfert <pa...@gmail.com> wrote:
> >
> >
> >>Ok this here is my problem.  I  have a web page that I want to be able
> >>to display dynamic content on.  In my source program I have a Vector of
> >>objects that I have fields in it like first name, Last name, and
> >>address.  I want to be able to access these fields.  In my webpage I
> >>have an if statement (#if($Array))  and a #foreach statement my #foreach
> >>statement is
> >>#foreach ($person in $Array) and I have calls like $person.getFirst() in
> >>my webpage.  I  have created a method that should fill up the variable
> >>Array and then merge that with velocity template.  However when I try
> >>and view the dynamic content All I get is  the else block in my web
> >>page.  If  you need more information let me know.
> >>
> >>-Paul
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >>
> >>
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> >
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Need help displaying Innformation on a template

Posted by Paul Goepfert <pa...@gmail.com>.
Here is my code for creating the context.   Most  of this code is 
surrounded by try/catch blocks.  I have excluded them for space.  If 
there is something here that is unnecessary let me  know.  I am also 
including part of my template so you can see how I'm trying to display 
the values.

_________
Code
_________

 public void createContext(InfoBean [] array)
    {
        Velocity.init();
        Template template = null;      
 
        template = Velocity.getTemplate("/sortResults.vm");            
        VelocityContext context = new VelocityContext();       

        removeInsert(array);
	//getInformationn returns a Vector
	//Each element in the Vector is of InfoBean (String,String,String,String,String,String)
        context.put("Array",  getInformation());        
        StringWriter writer = new StringWriter ();        

        template.merge(context, writer);
    }



  #if($Array)
                <table width="380" border="0" cellspacing="0" cellspadding="0">
                    <tr>
                        <th width="107" scope="col">
                         <div align="center">$text.get("last")</div>
                        </th>
                        <th width="108" scope="col">
                            <div align="center">$text.get("first")</div>
                     </th>
                        <th width="165" scope="col">
                            <div align="center">$text.get("Address")</div>
                        </th>
                 </tr>
                 #foreach($person in $Array)
                    <tr>
                        <td>$person.getLast()</td>
                        <td>$person.getFirst()</td>
                        <td>
                        <table width="342" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                 <td width="386">$person.getStreet()</td>
                                </tr>
                                <tr>
                                    <td>$person.getCity(), $person.getState() $person.getZip()</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
                <input type="submit" name="Submit" value=" $text.get("done") " onclick="resultsForm.action.value="done" >
                #end
                #else
                <p>Sorry but there is no data in the database to sort.  Please 
                   enter information in the databse </p>
                <input type="submit" name="Submit2" value=" $text.get("enter")" onclick=resultsForm.action.value="enter">
                #end

-Paul
Jack Holt wrote:

>Could you include actual snippets of the code?  In my code that backs
>the Velocity templates, I'm using code like the following:
>
>// get a List of Maps. The map contains keys of "id" and "name"
>List<Map<String,String>> routeList = getRouteList();
>// the following is for Spring Web Flow but just results in the
>"routeList" variable ending
>// up in the Velocity context
>context.getRequestScope().setAttribute("routeList",routeList);
>
>And in the Velocity template, I'm using:
>
>#foreach($route in $routeList)
>  $route.id
>  $route.name
>#end
>
>However, I'm sure you understand that if you are getting the else
>block everytime, that means the $Array is either null, non-existant or
>false.  Are you sure that are actually placing $Array into the
>Velocity context?
>
>On 6/13/05, Paul Goepfert <pa...@gmail.com> wrote:
>  
>
>>Ok this here is my problem.  I  have a web page that I want to be able
>>to display dynamic content on.  In my source program I have a Vector of
>>objects that I have fields in it like first name, Last name, and
>>address.  I want to be able to access these fields.  In my webpage I
>>have an if statement (#if($Array))  and a #foreach statement my #foreach
>>statement is
>>#foreach ($person in $Array) and I have calls like $person.getFirst() in
>>my webpage.  I  have created a method that should fill up the variable
>>Array and then merge that with velocity template.  However when I try
>>and view the dynamic content All I get is  the else block in my web
>>page.  If  you need more information let me know.
>>
>>-Paul
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: Need help displaying Innformation on a template

Posted by Jack Holt <ja...@gmail.com>.
Could you include actual snippets of the code?  In my code that backs
the Velocity templates, I'm using code like the following:

// get a List of Maps. The map contains keys of "id" and "name"
List<Map<String,String>> routeList = getRouteList();
// the following is for Spring Web Flow but just results in the
"routeList" variable ending
// up in the Velocity context
context.getRequestScope().setAttribute("routeList",routeList);

And in the Velocity template, I'm using:

#foreach($route in $routeList)
  $route.id
  $route.name
#end

However, I'm sure you understand that if you are getting the else
block everytime, that means the $Array is either null, non-existant or
false.  Are you sure that are actually placing $Array into the
Velocity context?

On 6/13/05, Paul Goepfert <pa...@gmail.com> wrote:
> Ok this here is my problem.  I  have a web page that I want to be able
> to display dynamic content on.  In my source program I have a Vector of
> objects that I have fields in it like first name, Last name, and
> address.  I want to be able to access these fields.  In my webpage I
> have an if statement (#if($Array))  and a #foreach statement my #foreach
> statement is
> #foreach ($person in $Array) and I have calls like $person.getFirst() in
> my webpage.  I  have created a method that should fill up the variable
> Array and then merge that with velocity template.  However when I try
> and view the dynamic content All I get is  the else block in my web
> page.  If  you need more information let me know.
> 
> -Paul
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org