You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by James You <jy...@hywy.com> on 2001/12/18 21:56:14 UTC

Need help -- How to do the class casting in velocity template?

Hi, all:
I have a question about the class object casting in velocity template.

For example: 
(1) In Java code  I create a Hashtable object called
employeeProjectListTable and 
	put it into the velocity context.
	employeeProjectListTable's key/value pair are:
	--- key is the employee's last name such as "Smith"
	--- value is the ArrayList object (projectList  ) in which contains all
of the project name
        	for which that employee is responsible. such as 
	        Smith has two projects on hand called "VTL" and "TOMCAT"

		
	velocityContext.put("employee", "Smith");
	velocityContext.put("employeeProjectListTable",
employeeProjectListTable);

(2) In VTL template file:
	(0): #set($employeeName = $employee)

        (i): Can I create a new variable called "empProjTable" ?	
	      #set($empProjTable = $employeeProjectListTable  )

        (ii): How can I get the projectList for "Smith" from the
"$employeeProjectListTable" ?
 	       #set($projList =
${employeeProjectListTable.get($employeeName)}  )	  

	
	(iii) Do I need to do the class casting ?
 	       #set($projList =
(ArrayList)${employeeProjectListTable.get($employeeName)}  )	  
	      If so, how I can do it.
	      If not, how I can get the project List (ArrayList) for some known
people, such as "Smith"
	
	(iV) The purpose of doing this is to list out the name of project which
the particular employee is responsible for.
		
		#foreach($projectName in $projList)
			Project Name --> $projectName
		#end		

        Can anyone give me a hint or explanation or examples of how to
doing this ASAP.


Thanks in advance...........


James

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Need help -- How to do the class casting in velocity template?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 12/18/01 5:38 PM, "James You" <jy...@hywy.com> wrote:

> Geir:
> Thanks for your fastest reply my questions. All of your answers are
> helphul.
> 
> Merry Christmas!
> 
> 

I'm hoping for not only helpful and fast but correct.  I'll assumed things
worked :)

Happy Holidays

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Need help -- How to do the class casting in velocity template?

Posted by James You <jy...@hywy.com>.
Geir:
Thanks for your fastest reply my questions. All of your answers are
helphul.

Merry Christmas!


James



"Geir Magnusson Jr." wrote:
> 
> On 12/18/01 3:56 PM, "James You" <jy...@hywy.com> wrote:
> 
> > Hi, all:
> > I have a question about the class object casting in velocity template.
> 
> There is no such thing, formally.
> 
> >
> > For example:
> > (1) In Java code  I create a Hashtable object called
> > employeeProjectListTable and
> > put it into the velocity context.
> > employeeProjectListTable's key/value pair are:
> > --- key is the employee's last name such as "Smith"
> > --- value is the ArrayList object (projectList  ) in which contains all
> > of the project name
> > for which that employee is responsible. such as
> >        Smith has two projects on hand called "VTL" and "TOMCAT"
> >
> >
> > velocityContext.put("employee", "Smith");
> > velocityContext.put("employeeProjectListTable",
> > employeeProjectListTable);
> 
> > (2) In VTL template file:
> > (0): #set($employeeName = $employee)
> >
> >       (i): Can I create a new variable called "empProjTable" ?
> >      #set($empProjTable = $employeeProjectListTable  )
> 
> Yes, but you could just use $employeeProjectListTable (just like you could
> use $employee)
> 
> In each case, they are both references to the same object
> 
> >
> >       (ii): How can I get the projectList for "Smith" from the
> > "$employeeProjectListTable" ?
> >       #set($projList =
> > ${employeeProjectListTable.get($employeeName)}  )
> 
> #set( $list = $employeeProjectListTable.get( $employeeName ) )
> 
> Should do it
> 
> >
> >
> > (iii) Do I need to do the class casting ?
> >       #set($projList =
> > (ArrayList)${employeeProjectListTable.get($employeeName)}  )
> 
> Good heavens no!
> 
> >      If so, how I can do it.
> >      If not, how I can get the project List (ArrayList) for some known
> > people, such as "Smith"
> 
> #set($list = $employeeProjectListTable.get("Smith") )
> 
> > (iV) The purpose of doing this is to list out the name of project which
> > the particular employee is responsible for.
> >
> > #foreach($projectName in $projList)
> > Project Name --> $projectName
> > #end
> >
> >       Can anyone give me a hint or explanation or examples of how to
> > doing this ASAP.
> >
> 
> Is this fast enough?
> 
> --
> Geir Magnusson Jr.                                     geirm@optonline.net
> System and Software Consulting
> "He who throws mud only loses ground." - Fat Albert
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Need help -- How to do the class casting in velocity template?

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 12/18/01 3:56 PM, "James You" <jy...@hywy.com> wrote:

> Hi, all:
> I have a question about the class object casting in velocity template.

There is no such thing, formally.

> 
> For example: 
> (1) In Java code  I create a Hashtable object called
> employeeProjectListTable and
> put it into the velocity context.
> employeeProjectListTable's key/value pair are:
> --- key is the employee's last name such as "Smith"
> --- value is the ArrayList object (projectList  ) in which contains all
> of the project name
> for which that employee is responsible. such as
>        Smith has two projects on hand called "VTL" and "TOMCAT"
> 
> 
> velocityContext.put("employee", "Smith");
> velocityContext.put("employeeProjectListTable",
> employeeProjectListTable);

> (2) In VTL template file:
> (0): #set($employeeName = $employee)
> 
>       (i): Can I create a new variable called "empProjTable" ?
>      #set($empProjTable = $employeeProjectListTable  )

Yes, but you could just use $employeeProjectListTable (just like you could
use $employee)

In each case, they are both references to the same object

> 
>       (ii): How can I get the projectList for "Smith" from the
> "$employeeProjectListTable" ?
>       #set($projList =
> ${employeeProjectListTable.get($employeeName)}  )

#set( $list = $employeeProjectListTable.get( $employeeName ) )

Should do it
      
> 
> 
> (iii) Do I need to do the class casting ?
>       #set($projList =
> (ArrayList)${employeeProjectListTable.get($employeeName)}  )

Good heavens no!
     
>      If so, how I can do it.
>      If not, how I can get the project List (ArrayList) for some known
> people, such as "Smith"


#set($list = $employeeProjectListTable.get("Smith") )
 
> (iV) The purpose of doing this is to list out the name of project which
> the particular employee is responsible for.
> 
> #foreach($projectName in $projList)
> Project Name --> $projectName
> #end        
> 
>       Can anyone give me a hint or explanation or examples of how to
> doing this ASAP.
> 

Is this fast enough?

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>