freemarker variable resolution in milestone 1

I've been playing around with one of the features that we've most wanted in IDEA - freemarker support. The syntax highlighting seems to be working well so far from what I can tell, however I'm really having issues with trying to get IDEA to recognize and autocomplete variables.

A bit of background on our application. The view layer is struts2 and freemarker based glued together via spring 2.5. We have a custom class which extends struts2's FreemarkerManager where we inject a variety of objects into freemarker's context.

One of the things that struts2 injects into the freemarker context is a bunch of models for things like url, text, etc all under the 's' prefix if you will. Here's a couple of example usages

When I attempt to tell IDEA how to resolve 's' it requires a class name ... whereas in this case the likeliest way to resolve it is via a .tld file. The best I could come up with is [#-- @ftlvariable name="s" type="org.apache.struts2.views.freemarker.tags.StrutsModels" --] However that doesn't really seem to do the trick as IDEA now knows about the tag names but nothing about their attributes. Also, for references like this: The 'view' variable is really a reference to CommunityAction.getView() and 'statics' is literally just a special map injected into the freemarker context. Is there way to have IDEA figure out the 'action' resolution from the struts configuration files? The linkage is already there: ... /template/global/community-all.ftl]]>
...

Though of course I also can't figure out how to tell IDEA that /template/ resolves to xyz directory so until I can do that ...


Any help is appreciated.

4 comments
Comment actions Permalink

<@s.text name="community.show_all.link"/> <@s.url value='/'/>


You can write <#assign s = JspTagLibs['tld url']>. Now you can do this
only in the source file, but we'll add external implicit assignments
support in the nearest future.

<#if view ==
statics['com.jivesoftware.community.action.CommunityAction'].VIEW_DISCUSSIONS>


Static members access will be available in the next EAP. The declaration
will look like [#-- @ftlvariable
name="statics['com.jivesoftware.community.action.CommunityAction']"
type="com.jivesoftware.community.action.CommunityAction.static" --]

The 'view' variable is really a reference to
CommunityAction.getView() and 'statics' is literally just a special
map injected into the freemarker context. Is there way to have
IDAfigure out the 'action' resolution from the struts configuration
files? The linkage is already there:


<action name="community"
> .. <result
name="success-all">/template/global/community-all.ftl</result> ..

Sorry, I don't understand you herre. What exactly do you want IDEA to
figure out from this linkage?

Though of course I also can't figure out how to tell IDEA that
/template/ resolves to xyz directory so until I can do that ...


There is an open issue on this problem:
http://www.jetbrains.net/jira/browse/IDEADEV-29347. You can watch it to
get notified about changes. Also any suggestions on how to to this would
be very welcome.

Thank you for feedback!

0
Comment actions Permalink

The 'view' variable is really a reference to
CommunityAction.getView() and 'statics' is literally just a special
map injected into the freemarker context. Is there way to have
IDAfigure out the 'action' resolution from the struts configuration
files? The linkage is already there:


<action name="community"
> .. <result
name="success-all">/template/global/community-all.ftl</result> ..

Sorry, I don't understand you herre. What exactly do you want IDEA to
figure out from this linkage?


Well, because of the struts2 mapping that already exists (in the struts-xyz.xml file) that has this file as a result for the CommunityAction. I was hoping that IDEA would be able to figure out that

1. community-all.ftl file is only used by this one action because of the struts2 mapping
2. unresolved ftl variables in the community-all.ftl file should first be resolved against the CommunityAction (or it's parents) to see if there is a corresponding method such that the ftl variable 'view' is mapped by IDEA to CommunityAction.getView() if a method by that name exists.

The reason for this is that in a lot of cases mapping every single variable in the ftl file to it's corresponding method/class/whatever is going to be excruciatingly painful - made even more painful by the fact that many/most if not all of the variables are really just getters on the parent struts2 action.

If IDEA can figure it out for itself via the struts2 config files, awesome. If not, having the ability to define an 'implicit' scope per ftl file that is used to test unresolved ftl variables against would be a welcome second option.

Bruce

0
Comment actions Permalink

Bruce Ritchie wrote:
>>> The 'view' variable is really a reference to
>>> CommunityAction.getView() and 'statics' is literally just a special
>>> map injected into the freemarker context. Is there way to have
>>> IDAfigure out the 'action' resolution from the struts configuration
>>> files? The linkage is already there:
>>> >> > .. >> name="success-all">/template/global/community-all.ftl .. >> Sorry, I don't understand you herre. What exactly do you want IDEA to >>]]> figure out from this linkage?


Well, because of the struts2 mapping that already exists (in the struts-xyz.xml file) that has this file as a result for the CommunityAction. I was hoping that IDEA would be able to figure out that

1. community-all.ftl file is only used by this one action because of the struts2 mapping
2. unresolved ftl variables in the community-all.ftl file should first be resolved against the CommunityAction (or it's parents) to see if there is a corresponding method such that the ftl variable 'view' is mapped by IDEA to CommunityAction.getView() if a method by that name exists.

The reason for this is that in a lot of cases mapping every single variable in the ftl file to it's corresponding method/class/whatever is going to be excruciatingly painful - made even more painful by the fact that many/most if not all of the variables are really just getters on the parent struts2 action.

If IDEA can figure it out for itself via the struts2 config files, awesome. If not, having the ability to define an 'implicit' scope per ftl file that is used to test unresolved ftl variables against would be a welcome second option.

Bruce


Ok, got it. JIRA issues created:
http://www.jetbrains.net/jira/browse/IDEADEV-29449 and
http://www.jetbrains.net/jira/browse/IDEADEV-29450

0
Comment actions Permalink

Hi Peter,

Do you know how should look like comment to suppres worning for unresolved method?
I have example method defined in class com.konri.SomeClass.SomeMethod and it extends TemplateMethodModelEx.

I tried different variations of ftlvariable and few other @xxx but can not find any docs about this.

Best regards
Konrad

0

Please sign in to leave a comment.