Best way to pass object to processor

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Best way to pass object to processor

dstarh
What is the best way to pass an object such as a Date to a processor.  I'm building a Since processor that takes a date and calculates string value based upon it.  if I do  what is the method call that i would use to be able to grab that value not as a string but as the object itself.

Right now I'm doing  but I'm thinking that the date when i call getLocalVariable("date") is really just pulling from the th:with.
Reply | Threaded
Open this post in threaded view
|

Re: Best way to pass object to processor

Zemi
Administrator
I would pass it as an attribute value
     
      < span th:myprocessor="${mydate}" >Whatever< /span >

then into the Processor code you can access that value with some code like

        String attributeValue = element.getAttributeValue(attributeName);
        Date dateObj = (Date) StandardExpressionProcessor.processExpression(arguments, attributeValue);

I do not know it this is the best way, but it is consistent with standard Thymeleaf attributes.

Reply | Threaded
Open this post in threaded view
|

Re: Best way to pass object to processor

dstarh
Thanks, I understand the thought process here now.  I was just confused because when you get the attribute you just get ${foo} as text and I was expecting it to be converted to the object at the page level rather than at the Processor level

-- 
David Herman


On Wednesday, August 15, 2012 at 3:10 PM, Zemi [via Thymeleaf - User Forum] wrote:

I would pass it as an attribute value
     
      < span th:myprocessor="${mydate}" >Whatever< /span >

then into the Processor code you can access that value with some code like

        String attributeValue = element.getAttributeValue(attributeName);
        Date dateObj = (Date) StandardExpressionProcessor.processExpression(arguments, attributeValue);

I do not know it this is the best way, but it is consistent with standard Thymeleaf attributes.




If you reply to this email, your message will be added to the discussion below:
http://forum.thymeleaf.org/Best-way-to-pass-object-to-processor-tp4024957p4024958.html
To unsubscribe from Best way to pass object to processor, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Best way to pass object to processor

danielfernandez
Administrator

Hi,

You should use the StandardExpressionProcessor in the way Zemi explains.

The reason the IProcessor interface does not offer you the already-processed object is because the interface is defined being used with any kind of dialects, even --potentially-- ones that might not admit Standard Expressions (which is what you have in ${...}).

Regards,
Daniel.