From: Keats K. <ke...@xa...> - 2005-05-18 14:49:41
|
Marc Palmer wrote: >Hi guys, > >I have a WM JSP taglib working here. It works like this... in your JSP >page you do: > ><wm:template> > #foreach $reason in ["a", "very", "long", "list"] > Use webmacro! > #end ></wm:template> > > This is cool Marc. I did one of these a couple of years back, but I've lost track of my code. One thing remember that I found useful was to add an optional "id" attribute to the tag so that error messages could reference the specific tag where they occurred. (Unfortunately the WM error messages refer to locations relative to the start of the tag content, not the JSP. If you find a way around this I'd be interested in hearing about it.) I'm actually in a JSP shop now as well :-( so if we could get this into the release it might help me sneak some WM in here as well! >I also have (currently untested) support for (which Velocity JSP taglib >doesn't do): > ><wm:template template="someTemplatePath.wm"/> > >However there are issues with template resolution in webapps - I can't >create WM to use a Servlet as there may not be one that can apply to the >taglib. > > I'm not sure what your issue is here. Can you explain a bit more? >What I am now adding is a context tool to allow the WM script to access >the attributes of the JSP page in their various scopes (AKA scoped page >variables, scoped to page, session or request) > >I'm not sure about the nicest way to achieve this. I'm currently working >along the lines of: > ><wm:template> >This is from the JSP page context: $Attributes.Session.SomeSessionVar >This is from the JSP page context: $Attributes.Page.SomePageVar >This is from the JSP page context: $Attributes.Request.SomeRequestVar ></wm:template> > >This would be quite a nice way to tackle the scoping problem without >requiring method calls (one of the main benefits of WM over JSP). > > I believe I just dropped the JspContext into the WM Context, so I could access all the JSP vars as $JSP.myvar, etc. However I have been toying for a long time with adding scoped variables capabilities into WM. (We already have this with the #bean directive.) I was thinking of something similar to what you've outlined, e.g., $Ctx.Global.MyGlobalVar $Ctx.Session.MySessionVar $Ctx.Page.MyPageVar (same as $MyPageVar of course) Then to get something from the most local scope, like JSP does, you could say: $Ctx.Var.MyVar or something like that. >One thing that is annoying me is that we still can't seem to write >templates out to a Writer, only a FastWriter or OutputStream. > >In some ways this is good but in others it seems to suck. i.e. in JSP-land >the taglib has access only to a pre-constructed JspWriter to write out the >content. Currently I have to get ugly and create a ByteArrayOutputStream, >write to there, convert that to a String, then write that to the writer. >Quite nasty - although it does allow our WM evalution to be atomic - i.e. >any errors we can just dump a single error text to the JSP output. > > Can you give examples of when you need this functionality? If I understand the use-cases, maybe I can help think of solutions. >I'll keep you all posted on the progress of this. We have a bunch of >legacy JSP pages here we will probably be converting to use this taglib so >there will be plenty of lessons learned, which I will put on the Wiki >eventually. > > Looking forward to it! Keats >Cheers > > > |