Re: TemplateModelException when unwrapping SimpleMethodModel
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Seems BeansWrapper produces a few disfunct TemplateSequenceModels... like CollectionModel-s whose get(index) method fails (had to work it around in 2.3.17). I don't know why SimpleMethodModel implements TemplateSequenceModel at all. As its size() method isn't working it violates the interface, and its get(index) method just returns a List that only contains the index, which sounds strange. Anyway, I suppose SimpleMethodModel should implement AdapterTemplateModel, and return getMember() for getAdaptedObject. That would, coincidently, solve the issue with DeepUnwrap. Attila, what do you think, can I go ahead and do that in 2.3? Is this the right thing to do? -- Best regards, Daniel Dekany Thursday, August 4, 2011, 12:06:51 AM, Rebecca Younes wrote: > Now I see that as long as I'm working within the > freemarker.ext.beans package, I can call > SimpleMethodModel.getMember() to get its member method. This may be > the only option, given the issues with the unwrap method. > > From: Rebecca Younes <[email protected]> > Date: Wed, 3 Aug 2011 17:22:01 -0400 > To: "[email protected]" > <[email protected]> > Subject: Re: TemplateModelException when unwrapping SimpleMethodModel > > OK, I see that SimpleMethodModel.size() throws an exception, which > seems to me an indication that SimpleMethodModel shouldn't implement > TemplateSequenceModel in the first place. However, given that it > does, what can I do to get the underlying method? > > Thanks. > > From: Rebecca Younes <[email protected]> > Date: Wed, 3 Aug 2011 17:10:30 -0400 > To: "[email protected]" > <[email protected]> > Subject: TemplateModelException when unwrapping SimpleMethodModel > > Hello, > > I'm getting a TemplateModelException when I try to do > DeepUnwrap.permissiveUnwrap() or DeepUnwrap.unwrap() on a > SimpleMethodModel. The error is generated in the following code > block, with the message "?size is unsupported for: > freemarker.ext.beans.SimpleMethodModel". However, size() is defined > for this class. What is going wrong, and is there a workaround so > that I can get at the wrapped method? > > if(model instanceof TemplateSequenceModel) { > TemplateSequenceModel seq = (TemplateSequenceModel)model; > ArrayList list = new ArrayList(seq.size()); > for(int i = 0; i < seq.size(); ++i) { > list.add(unwrap(seq.get(i), nullModel, permissive)); > } > return list; > } > > Thank you. > > Rebecca Younes ------------------------------------------------------------------------------ BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA The must-attend event for mobile developers. Connect with experts. Get tools for creating Super Apps. See the latest technologies. Sessions, hands-on labs, demos & much more. Register early & save! http://p.sf.net/sfu/rim-blackberry-1