You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by michael shek sia lim <mi...@eigentechnology.com> on 2002/12/12 07:16:08 UTC

Math Evaluation

Hi...

When I use Velocity to read something from a Database, how do I convert it
into Numerics so that I can do mathematic manupilation?  Apparantly it is
interpreted as "text" by default.

thanks
michael




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


Re: Math Evaluation

Posted by michael shek sia lim <mi...@eigentechnology.com>.
Problems solved. There is no need for any casting, I was reading from a
NumberKey field ... sorry folks.

michael


> I am sorry if my previous question was not appropriate. Could anyone
> tell me where I can find information about this operation then?
>
> thanks
> michael
>
>
>
>
>
>> Hi...
>>
>> When I use Velocity to read something from a Database, how do I
>> convert it into Numerics so that I can do mathematic manupilation?
>> Apparantly it is interpreted as "text" by default.
>>
>> thanks
>> michael
>>
>>
>>
>>
>> --
>> 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>




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


RE: Math Evaluation

Posted by James Cooper <ja...@maxware.nl>.
I'm not entirely sure what you're aiming for Michael. Do you want to do
basic arithmetic functionality within the template itself or the action or
screen class behind.

Are asking how to do object conversion?



-----Original Message-----
From: michael shek sia lim [mailto:michael@eigentechnology.com]
Sent: 12 December 2002 12:14
To: turbine-user@jakarta.apache.org
Subject: Re: Math Evaluation


I am sorry if my previous question was not appropriate. Could anyone tell
me where I can find information about this operation then?

thanks
michael





> Hi...
>
> When I use Velocity to read something from a Database, how do I convert
> it into Numerics so that I can do mathematic manupilation?  Apparantly
> it is interpreted as "text" by default.
>
> thanks
> michael
>
>
>
>
> --
> 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>



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


Regexp in Turbine + A Java Question + ...

Posted by Eigen Technology Pty Ltd <mi...@eigentechnology.com>.
Peter,

Yes, it worked. But I still have two problems with this approach:

1. I have to create 1 List and 1 Vector for my logic to work. List for the
iterator and Vector for Return value. I tried to return List, Velocity
does not like it. This could be a potential problem when my database grows
big.


2. Once I have matched and selected the objects from the Iterator, I need
to add them to a Vector to return for Velocity to display. What format
should I use, I read BaseContactPeer.java, it has a rather compilcated way
to build its Vector which I do not completely understand.

thanks.
michael





> Michael,
>
> I'm not sure I understand you.
>
> Torque returns a List of data objects. If your table is Registry as in
> my example, if you look in your WEB-INF/src/java/.../om directory you
> will find a Registry.java file which extends BaseRegistry.java file, a
> RegistryPeer file which extends BaseRegistryPeer file.
>
> The select will return a List of Registry objects. If you look at the
> BaseRegistry.java file you will see that Torque has created accessor
> methods for each of the columns in the table for you. (Look at all the
> public methods in these files as they can save you lots of work.)
>
> if you do something like this :-
>
> List objs = RegistryPeer.doSelect(c);
> Iterator itr = objs.iterator();
> while ( itr.hasNext())
> 	{
> 		Registry reg = (Registry) itr.next();
> 		String title = reg.getTitle();
> 		long id = reg.getRegistryid();
> 	}
>
> where Registry is the name of my table which has a column title which is
> a VARCHAR or other type which is convertible to a String and a column
> registryid which is a BIGINT which returns a long.
>
> Is this what you are getting at.
>
> Look at the source code for the newapp example. This shows usage.
>
> Peter
>
>
> On Fri, 2002-12-27 at 22:18, Eigen Technology Pty Ltd wrote:
>> Peter,
>>
>> Yes, I can get a list of objects from the Pulled data. The question is
>> how do I further extract data from the extracted objects? Because the
>> data I want is within these objects.
>>
>> thanks
>> michael
>>
>>
>>
>> > Michael,
>> >
>> > Do your filtering in your pull tool method. You can return a list of
>> objects or a single object. Try to make sure any exception is caught
>> as velocity is not good at handling exceptions.
>> >
>> > Peter
>> >
>> >
>> > On Fri, 2002-12-27 at 12:19, Eigen Technology Pty Ltd wrote:
>> >> Peter,
>> >>
>> >> I have solved the first problem now. It was caused by the wrong
>> placement of the .class file. I corrected the input in
>> TR.properties and it was rectified.
>> >>
>> >> Now I am facing another problem. The data extracted from the DB is
>> a Vector (or List) of Objects. How do I further extract data out
>> from this Object to do data filtering?
>> >>
>> >> cheers
>> >> michael
>> >>
>> >>
>> >>
>> >>
>> >> > Michael,
>> >> >
>> >> > Look in the velocity log for your webapp.
>> >> >
>> >> > It should log if method calls are null. Is your utils object
>> being
>> >> found?
>> >> >
>> >> > Peter
>> >> >
>> >> > On Thu, 2002-12-26 at 22:55, Eigen Technology Pty Ltd wrote:
>> >> >> Peter, I need to bother you a bit more on this topic.
>> >> >>
>> >> >> Assuming the method I deployed is working, if I want to modify
>> the
>> >> data in the java program before I present them in the .vm file, how
>> is that to be done?
>> >> >>
>> >> >> best wishes
>> >> >> michael
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >>
>> >> >> > Michael,
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> > On Wed, 2002-12-25 at 23:10, Eigen Technology Pty Ltd wrote:
>> >> >> >> Peter,
>> >> >> >>
>> >> >> >> I guess my question should be "how could I manipulate List
>> >> object
>> >> >> in a .vm file? " to be more specific.
>> >> >> >>
>> >> >> > #foreach ($doc in $documents)
>> >> >> >
>> >> >> > $doc.Title
>> >> >> > ...
>> >> >> >
>> >> >> > #end
>> >> >> >
>> >> >> >> cheers
>> >> >> >> michael
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> > Michael,
>> >> >> >> >
>> >> >> >> > A pull tool is very easy. implement init as below and
>> refresh,
>> >> >> which
>> >> >> >> can be empty. Then write whatever methods you need. All
>> methods
>> >> >> will be available in your context.
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > An example
>> >> >> >> >
>> >> >> >> > public class UtilsTool implements ApplicationTool
>> >> >> >> > {
>> >> >> >> >
>> >> >> >> >     /**
>> >> >> >> >      * Initialize the UtilsTool object.
>> >> >> >> >      *
>> >> >> >> >      * @param data This is null, RunData or User depending
>> >> upon *
>> >> >> >> specified tool scope.
>> >> >> >> >      */
>> >> >> >> >     public void init(Object data)
>> >> >> >> >     {
>> >> >> >> >
>> >> >> >> >         if (data == null)
>> >> >> >> >         {
>> >> >> >> >             Log.debug("UtilsTool scope is global");
>> >> >> >> >         }
>> >> >> >> >         else if (data instanceof RunData)
>> >> >> >> >         {
>> >> >> >> >             Log.debug("UtilsTool scope is request");
>> >> >> >> > 	            }
>> >> >> >> >         else if (data instanceof User)
>> >> >> >> >         {
>> >> >> >> >             Log.debug("UtilsTool scope is session");
>> >> >> >> >         }
>> >> >> >> >
>> >> >> >> >     }
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >     public void refresh()
>> >> >> >> >     {
>> >> >> >> > 	// this does not need to do anything
>> >> >> >> >         Log.debug("Refreshing UtilsTool");
>> >> >> >> >
>> >> >> >> >     }
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > 	/** gets a list of all docs in the Registry table in my db
>> >> >> >> > 	 */
>> >> >> >> > 	public List getDocuments()
>> >> >> >> > 	{
>> >> >> >> > 		List docs = null;
>> >> >> >> > 		try
>> >> >> >> > 			{
>> >> >> >> > 				Criteria c = new Criteria();
>> >> >> >> > 				docs = RegistryPeer.doSelect(c);
>> >> >> >> > 			}
>> >> >> >> > 		catch ( TorqueException e)
>> >> >> >> > 			{
>> >> >> >> > 				Log.info("system",
>> >> >> >> > 					 "UtilsTool-getDocuments:" +
>> >> >> >> > 					 "Exception caught", e );
>> >> >> >> > 				return null;
>> >> >> >> > 			}
>> >> >> >> >
>> >> >> >> > 		return docs;
>> >> >> >> > 	}
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > Once written add the following to your Turbine.properties
>> file
>> >> >> under
>> >> >> >> the pull tools section
>> >> >> >> >
>> >> >> >> > 	tool.request.utils=com.ittdirect.tolreg.tools.UtilsTool
>> >> >> >> >
>> >> >> >> > this is tool.
>> >> >> >> > followed by scope ( normally 'request' )
>> >> >> >> > followed by a name for the tool ( in this case 'utils' )
>> >> followed by =
>> >> >> >> > followed by the fully qualified class name ( in this case
>> >> com.mycompany.tools.UtilsTool )
>> >> >> >> >
>> >> >> >> > If your tool is called 'utils' as in this example and the
>> >> class
>> >> >> name
>> >> >> >> is as given above look in turbine.log after you restart
>> turbine.
>> >> >> You should see an entry stating that UtilsTool will be added to
>> the
>> >> context as 'utils'.
>> >> >> >> >
>> >> >> >> > When this is done the tool will be added to the context of
>> >> every
>> >> >> >> request and all of your .vm templates can refer to the
>> methods
>> >> of
>> >> >> the tool class like this :
>> >> >> >> >
>> >> >> >> >  #set ( $documents = $utils.getDocuments()) which sets
>> >> $documents
>> >> >> to
>> >> >> >> a
>> >> >> >> > list of document records as returned by the method.
>> >> >> >> >
>> >> >> >> > It is that easy.
>> >> >> >> >
>> >> >> >> > One caution. It is so easy to just add another method to a
>> >> tool.
>> >> >> If
>> >> >> >> you keep on doing this you end up with tool classes thousands
>> of
>> >> >> lines long and can never find what you want when looking through
>> >> it. Write more tools!
>> >> >> >> >
>> >> >> >> > Hope this helps.
>> >> >> >> >
>> >> >> >> > Regards,
>> >> >> >> >
>> >> >> >> > Peter
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > On Fri, 2002-12-13 at 06:06, michael shek sia lim wrote:
>> >> >> >> >> Peter,
>> >> >> >> >>
>> >> >> >> >> I have read the introduction bit on the pull tool doc. It
>> >> >> appears
>> >> >> >> to be rather abstract. Where could I find some examples for
>> this
>> >> >> pull tool ?
>> >> >> >> >>
>> >> >> >> >> thanks
>> >> >> >> >> michael
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >> > Michael,
>> >> >> >> >> >
>> >> >> >> >> > I'm not sure what you are trying to achieve. However, if
>> >> you
>> >> >> are
>> >> >> >> >> pulling values from a database and then carrying out maths
>> >> >> operations on the data, Velocity, as a templating engine, would
>> not
>> >> >> >> seem to be the appropriate place to do this. I suggest you
>> use a
>> >> >> pull tool to extract the data from the database and to oparate
>> on
>> >> it and place the results in the context for Velocity to render.
>> Look at the pull tool documentation on the turbine web site. If you
>> have not used pull tools before you will find that they are very
>> easy to write, deploy and use.
>> >> >> >> >> >
>> >> >> >> >> > On the other hand I may have totally misunderstood what
>> you
>> >> >> are
>> >> >> >> >> trying to achieve...
>> >> >> >> >> >
>> >> >> >> >> > I hope this helps.
>> >> >> >> >> >
>> >> >> >> >> > Peter
>> >> >> >> >> >
>> >> >> >> >> > On Thu, 2002-12-12 at 11:13, michael shek sia lim wrote:
>> >> >> >> >> >> I am sorry if my previous question was not appropriate.
>> >> Could
>> >> >> >> >> anyone tell me where I can find information about this
>> >> operation
>> >> >> >> then?
>> >> >> >> >> >>
>> >> >> >> >> >> thanks
>> >> >> >> >> >> michael
>> >> >> >> >> >>
>> >> >> >> >> >>
>> >> >> >> >> >>
>> >> >> >> >> >>
>> >> >> >> >> >>
>> >> >> >> >> >> > Hi...
>> >> >> >> >> >> >
>> >> >> >> >> >> > When I use Velocity to read something from a
>> Database,
>> >> how
>> >> >> do
>> >> >> >> I
>> >> >> >> >> >> convert it into Numerics so that I can do mathematic
>> >> >> >> manupilation?
>> >> >> >> >> Apparantly it is interpreted as "text" by default.
>> >> >> >> >> >> >
>> >> >> >> >> >> > thanks
>> >> >> >> >> >> > michael
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> >
>> >> >> >> >> >> > --
>> >> >> >> >> >> > 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>
>> >> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >>
>> >> >>
>> >>
>> >>
>>
>>




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


Re: Math Evaluation

Posted by michael shek sia lim <mi...@eigentechnology.com>.
I am sorry if my previous question was not appropriate. Could anyone tell
me where I can find information about this operation then?

thanks
michael





> Hi...
>
> When I use Velocity to read something from a Database, how do I convert
> it into Numerics so that I can do mathematic manupilation?  Apparantly
> it is interpreted as "text" by default.
>
> thanks
> michael
>
>
>
>
> --
> 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>