[xwiki-users] data model and velocity
I have a data model that follow this page structure: Detectors -> Detector1 -> Detector1History1 -> Detector1History2 -> Detector2 (Implemented with my DetectorClass and DetectorHistoryClass) The Detectors is like a dashboard for Detectors and their history. It's mostly working. My issue is that my Velocity code on that top dashboard page is looking pretty ugly. It has nested loops and I don't know how to do any encapsulation. If I could do things like detector1.getNewestHistory() that would be very helpful. But my Detector Object Class is limited to what I can define in XWiki. To my knowledge, XWiki's "user defined" classes aren't able to encapsulate code. Am I wrong? It seems like defining my Velocity macros would help, but my understanding is a macro can't return anything, just evaluates to output. If I'm wrong-headed, please correct me. Thanks, Scott
If you only need string return values there is a workaround described here: http://old.nabble.com/macro-question-td23105606.html Better than nothing I guess. Cheers, Olaf
________________________________ Von: Scott Serr <[email protected]> An: [email protected] Gesendet: 15:51 Mittwoch, 28.September 2011 Betreff: [xwiki-users] data model and velocity
I have a data model that follow this page structure:
Detectors -> Detector1 -> Detector1History1 -> Detector1History2 -> Detector2
(Implemented with my DetectorClass and DetectorHistoryClass)
The Detectors is like a dashboard for Detectors and their history. It's mostly working. My issue is that my Velocity code on that top dashboard page is looking pretty ugly. It has nested loops and I don't know how to do any encapsulation. If I could do things like detector1.getNewestHistory() that would be very helpful. But my Detector Object Class is limited to what I can define in XWiki. To my knowledge, XWiki's "user defined" classes aren't able to encapsulate code. Am I wrong?
It seems like defining my Velocity macros would help, but my understanding is a macro can't return anything, just evaluates to output.
If I'm wrong-headed, please correct me.
Thanks, Scott _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
On 09/28/2011 09:51 AM, Scott Serr wrote:
I have a data model that follow this page structure:
Detectors -> Detector1 -> Detector1History1 -> Detector1History2 -> Detector2
(Implemented with my DetectorClass and DetectorHistoryClass)
The Detectors is like a dashboard for Detectors and their history. It's mostly working. My issue is that my Velocity code on that top dashboard page is looking pretty ugly. It has nested loops and I don't know how to do any encapsulation. If I could do things like detector1.getNewestHistory() that would be very helpful. But my Detector Object Class is limited to what I can define in XWiki. To my knowledge, XWiki's "user defined" classes aren't able to encapsulate code. Am I wrong?
It seems like defining my Velocity macros would help, but my understanding is a macro can't return anything, just evaluates to output.
If I'm wrong-headed, please correct me.
From Velocity code only, you can't get very far towards clean domain-specific code. You should consider writing some Java code that wraps the XWiki plain data model into more useful rich objects. The way I see it, you should have Detector and DetectorHistory java classes that contain a com.xpn.xwiki.BaseObject object inside them to which they forwards data requests, plus new methods that bridge them together. Then, a ScriptService class that offers access to these objects from Velocity, which you would access with $services.detector in Velocity. -- Sergiu Dumitriu http://purl.org/net/sergiu/
participants (3)
-
O Voss -
Scott Serr -
Sergiu Dumitriu