[Mav-user] a new view
I recently had reason to develop a new view type for Maverick, and wonder if there might be any interest in it. If so, perhaps I can contribute it back to the project. The problem: I needed a very simple X?HTML template system. It had to be something that, however, complicated under the hood, could be used by junior developers and design people. I also wanted the source pages to be valid XML, so that I could use the various XML tools to edit/process/test the pages. I wanted to avoid JSP's scriptlet syntax. JSTL might work, but I wanted the source pages to be valid XML, so I wanted to avoid stuff like a href=c:out value='...'/ ... /a Basically, I wanted XML source files, with the ability to dynamically evaluate expressions and a some minimal amount of flow control. Looping, for sure. Conditionals, probably. Something to match the minimalist spirit of Maverick itself. Something that might look like this (with some of the namespace stuff cleared away): html body h2Welcome ${user.fullName}/h2 Your order contains the following items: table ctl:for-each items='${order.items}' name='item' trtd${item.productId}/tdtd${item.description}/td/tr /ctl:for-each /table the current time is ${util.dateTime} /body /html looks a bit like JSTL, but is required to be valid XML, unlike JSP+JSTL. I used OGNL for the expression language. The processing model goes like this: the page description (e.g. the above sample) is loaded once at app startup and parsed as a stream of SAX events. The events are recorded, and we do a certain amount of pre-processing, e.g. joining and compiling text nodes. Then, at request time we replay the event stream using a request specific evaluation context that contains things like the current request, the authenticated user, and some utilities. Maverick makes this pretty simple, because we can grab the next transform step in the view handler, and send the replayed SAX events on down the line. This means that any XSTL we might want to perform can be specified in Maverick's config, and will be handled completely by Maverick. Another nice thing about this is that unlike using JSP+XSLT, where the output of the JSP has to be re-parsed on every request, in my system the source is parsed exactly once. The strange thing about all this is that I wasn't able to find anything that quite suited my purpose. So I guess that's one purpose of this message: to see what I may have missed in the sea of Java webapp frameworks. The other purpose is to see if there's any interest in this. If not, then I must have missed something, because I've been quite pleased with the results. If so, then I can see about getting it cleaned up and put out somewhere for the Maverick community to have a look at. -- joe --- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=5047alloc_id=10808op=click [INVALID FOOTER]
Re: [Mav-user] a new view
Doug Kirk [EMAIL PROTECTED] writes: Hmmm...I don't want to rain on any parades, but I'm just wondering why you didn't want to use Velocity, as it accomplishes the same thing and it's already written and well-supported? I do use Velocity, and am happy with it in the contexts in which I use it. However, it didn't seem to quite fit here. I wanted the source pages to be plain old HTML, to the greatest extent possible. So consider something like a role-sensitive navigation bar. rather than #if ($user.inRole('admin')) a href=''AdminFunctions/a #end #if ($user.inRole('manager')) a href=''ManagerFunction/a #end ... I wanted a href='' ctl:if='${user.inRole(admin)}'Admin Functions/a ... Also, I wanted to be able to leverage XML tools (XSLT) in interesting ways. If the control elements are expressed in XML, then I could (for example) pass a template containing a looping construct through an appropriate stylesheet (I'm referring here to an offline process) and get a reasonable looking mockup. Another thing: I figured I'd be using XSLT at runtime. Both JSP and vanilla Velocity are what you might call text oriented. Meaning that the results of a template evaluation or JSP page evaluation would have to be reparsed as XML on every request. I wanted to avoid that overhead. Certainly I could have used Velocity. I'm not terribly proud of having increased the number of Java web technologies, and I always figured I could resist the urge when it came upon me. But it turned out I was wrong. -- joe --- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=5047alloc_id=10808op=click [INVALID FOOTER]
[Mav-user] a new view
I recently had reason to develop a new view type for Maverick, and wonder if there might be any interest in it. If so, perhaps I can contribute it back to the project. The problem: I needed a very simple X?HTML template system. It had to be something that, however, complicated under the hood, could be used by junior developers and design people. I also wanted the source pages to be valid XML, so that I could use the various XML tools to edit/process/test the pages. I wanted to avoid JSP's scriptlet syntax. JSTL might work, but I wanted the source pages to be valid XML, so I wanted to avoid stuff like a href=c:out value='...'/ ... /a Basically, I wanted XML source files, with the ability to dynamically evaluate expressions and a some minimal amount of flow control. Looping, for sure. Conditionals, probably. Something to match the minimalist spirit of Maverick itself. Something that might look like this (with some of the namespace stuff cleared away): html body h2Welcome ${user.fullName}/h2 Your order contains the following items: table ctl:for-each items='${order.items}' name='item' trtd${item.productId}/tdtd${item.description}/td/tr /ctl:for-each /table the current time is ${util.dateTime} /body /html looks a bit like JSTL, but is required to be valid XML, unlike JSP+JSTL. I used OGNL for the expression language. The processing model goes like this: the page description (e.g. the above sample) is loaded once at app startup and parsed as a stream of SAX events. The events are recorded, and we do a certain amount of pre-processing, e.g. joining and compiling text nodes. Then, at request time we replay the event stream using a request specific evaluation context that contains things like the current request, the authenticated user, and some utilities. Maverick makes this pretty simple, because we can grab the next transform step in the view handler, and send the replayed SAX events on down the line. This means that any XSTL we might want to perform can be specified in Maverick's config, and will be handled completely by Maverick. Another nice thing about this is that unlike using JSP+XSLT, where the output of the JSP has to be re-parsed on every request, in my system the source is parsed exactly once. The strange thing about all this is that I wasn't able to find anything that quite suited my purpose. So I guess that's one purpose of this message: to see what I may have missed in the sea of Java webapp frameworks. The other purpose is to see if there's any interest in this. If not, then I must have missed something, because I've been quite pleased with the results. If so, then I can see about getting it cleaned up and put out somewhere for the Maverick community to have a look at. -- joe --- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php [INVALID FOOTER]
Re: [Mav-user] a new view
Schnitzer, Jeff [EMAIL PROTECTED] writes: Velocity produces text that must be parsed to perform XSLT transforms. This new approach starts immediately with SAX events. Unlike a hypothetical saxify, it doesn't require fully navigating the source object graph. Cool. yes, I think so too. in fact, I'd say that this might be the biggest win to this approach. The downside is that it introduces yet another templating language syntax. What about borrowing the syntax of XSLT? Presumably your web developers are already using XSLT to handle the outgoing sax events, it would be nice if they could leverage their existing knowledge. I agree, and have given quite a bit of thought to exactly this solution. but I don't think it'd work, at least not in a way that would meet my initial requirements. first, XSLT is needlessly verbose. I don't want to have to say xsl:value-of select='...'/ every time I want to refer to a value. second, and more importantly, it doesn't really solve the problem. the key piece is something to allow you to refer to objects/properties/methods from within the template. that is, you want to be able to easily cross the boundary between the template language and the host language. I could think of only two ways of doing this in XSLT 1) write an XSLT extention function, to be used as in xsl:template match='' ... a xsl:attribute name='href' xsl:value-of select='ext:expr(model.price)'/ /xsl:attribute ... /a /xsl:template but that's way too verbose, and doesn't really solve anything anyhow, because you've still got a mini-expression language (e.g. model.price). 2) domify the graph of potentially reachable objects, and use the document() function plus a suitable URL resolver to find access the objects from the stylesheet. that also seemed too awkward. the bottom line is that the expression language used in XSLT is XPath, which is an incredibly powerful and useful language, if you happen to be applying it to something that fits with the XPath data model. this didn't seem to be the case to me at the time, although XPath 2.0 looks like it might come closer. I wanted something that would be both fast (execution-wise) and relatively easy to explain to programmers/designers of moderate experience level. I've been pretty happy with it so far on both counts. the app in question exhibits snappy performance (although I have done no testing to validate this) and people have picked up on the ideas pretty easily. on a somewhat off-topic note, I'll say that when I first considered doing this my instinctive reaction was: Please! Not another Java web framework!. But on further consideration, I don't think this critisicm was really valid. Really, it's just a recycling/repackging of various systems already available (Maverick, OGNL, SAX). More importantly, it used to be, back before I became someone who designs applications exclusively for the web (sigh), that I wasn't afraid of designing application-specific little languages. This approach was considered a powerful tool for solving problems in a general way. anyhow, maybe the best thing would be for me to clean things up, put the code+examples someplace public, and let people take a look. I'll do this and let the list know when it's available. -- joe --- This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170 Project Admins to receive an Apple iPod Mini FREE for your judgement on who ports your project to Linux PPC the best. Sponsored by IBM. Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php [INVALID FOOTER]