سؤال

I am currently trying to get a basic example of struts2-jquery treeTag running.

I have placed this in the JSP :

<sj:head jqueryui="true" customBasepath="css" jquerytheme="jquery_tree_ui" debug="true" />

....

<s:url id="echo" value="http://www.google.com"/>

<sjt:tree 
    id="treeDynamicAjax" 
    jstreetheme="apple" 
    rootNode="theNodes" 
    nodeHref="%{echo}"                   
    nodeTitleProperty="title" 
    nodeIdProperty="id" 
    nodeHrefParamName="echo"

/>

The Java action does this :

private List<TreeNode> theNodes = new ArrayList<TreeNode>();
private String id = "";

public String listUsergroup() {

    TreeNode nodeA = new TreeNode();
    nodeA.setId("A" + id);
    nodeA.setTitle("Node A" + id);
    nodeA.setState(TreeNode.NODE_STATE_OPEN);

    TreeNode nodeB = new TreeNode();
    nodeB.setId("B" + id);
    nodeB.setState(TreeNode.NODE_STATE_LEAF);
    nodeB.setTitle("Node B" + id);

    TreeNode nodeC = new TreeNode();
    nodeC.setId("C" + id);
    nodeC.setState(TreeNode.NODE_STATE_LEAF);
    nodeC.setTitle("Node C" + id);

    Collection<TreeNode> children = new ArrayList<TreeNode>();
    children.add(nodeB);
    children.add(nodeC);
    nodeA.setChildren(children);
    theNodes.add(nodeA);

    return SUCCESS;
}

public List<TreeNode> getTheNodes() {
    return theNodes;
}

public void setTheNodes(List<TreeNode> theNodes) {
    this.theNodes = theNodes;
}

public String getId() {
    return id;
}
public void setId(String id) {
    this.id = id;
}   

By activating the debug option in struts, I see that theNodes has all the tree.

The problem is that I am getting a yellow-screen-FreeMarker-template error talking about ftl files like template/jquery/treenode-include.ftl or template/jquery/tree.ftl.

It's my first time with jquery-treeTag plugin and in the official documentation I don't find any suitable example (I'd rather not use JSON nor Convention plugin).

If I change rootNode="theNodes" to any other value like rootNode="XXX" I get no exception, but nothing is displayed.

I'm pretty sure that I'm using the <sjt:tree>tag incorrectly, but I can't find any useful doc for a newbie.

Thank you in advance

UPDATE 1 :

This is the FreeMarker error :

FreeMarker template error!

Expression stack.findValue(parameters.nodeTitleProperty) is undefined on line 52, column 35 in template/jquery/treenode-include.ftl. 
The problematic instruction: ---------- ==> ${stack.findValue(parameters.nodeTitleProperty)} 
[on line 52, column 33 in template/jquery/treenode-include.ftl] in include "/${parameters.templateDir}/jquery/treenode-include.ftl"
[on line 30, column 5 in template/jquery/tree.ftl] ---------- Java backtrace for programmers: 

 ---------- freemarker.core.InvalidReferenceException: Expression stack.findValue(parameters.nodeTitleProperty) is undefined on line 52, column 35 in template/jquery/treenode-include.ftl.
 at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:125)
 at freemarker.core.Expression.getStringValue(Expression.java:118)
 at freemarker.core.Expression.getStringValue(Expression.java:93)
 at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
 at freemarker.core.Environment.visit(Environment.java:221)
 at freemarker.core.MixedContent.accept(MixedContent.java:92)
 at freemarker.core.Environment.visit(Environment.java:221)
 at freemarker.core.IfBlock.accept(IfBlock.java:82)
 at freemarker.core.Environment.visit(Environment.java:221)
 at freemarker.core.IfBlock.accept(IfBlock.java:82)
 at freemarker.core.Environment.visit(Environment.java:221)
 at freemarker.core.MixedContent.accept(MixedContent.java:92)
 at freemarker.core.Environment.visit(Environment.java:221)
 at freemarker.core.Environment.include(Environment.java:1508)
 at freemarker.core.Include.accept(Include.java:169)
 at freemarker.core.Environment.visit(Environment.java:221)
 at freemarker.core.MixedContent.accept(MixedContent.java:92)
 at freemarker.core.Environment.visit(Environment.java:221)
 at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
 at freemarker.core.Environment.visit(Environment.java:221)
 at freemarker.core.MixedContent.accept(MixedContent.java:92)
 at freemarker.core.Environment.visit(Environment.java:221)
 at freemarker.core.Environment.process(Environment.java:199)
 at freemarker.template.Template.process(Template.java:259)
 at org.apache.struts2.components.template.FreemarkerTemplateEngine.renderTemplate(FreemarkerTemplateEngine.java:157)
 at org.apache.struts2.components.UIBean.mergeTemplate(UIBean.java:565)
 at org.apache.struts2.components.ClosingUIBean.start(ClosingUIBean.java:59)
 at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:53)
 at org.apache.jsp.jsp.administration.listUsergroup_jsp._jspx_meth_sjt_005ftree_005f0(listUsergroup_jsp.java:504)
 at org.apache.jsp.jsp.administration.listUsergroup_jsp._jspService(listUsergroup_jsp.java:182)
 at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
 at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
 at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
 at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
 at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
 at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
 at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:164)
 at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
 at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:374)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:278)
 at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:50)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
 at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
 at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
 at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
 at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:511)
 at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:432)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:322)
 at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
 at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
 at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
 at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:184)
 at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:155)
 at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
 at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
 at java.lang.Thread.run(Thread.java:662)  
هل كانت مفيدة؟

المحلول

First of all you need to have one root node not a list of root nodes, so change this
private List<TreeNode> theNodes = new ArrayList<TreeNode>();
to
private TreeNode theNode = new TreeNode();.

Then you can use this code in jsp

<sjt:tree 
    id="treeDynamicAjax" 
    jstreetheme="apple" 
    rootNode="theNode" 
    nodeHref="%{echo}"                   
    nodeTitleProperty="title" 
    nodeIdProperty="id" 
    nodeHrefParamName="echo"
    childCollectionProperty="children"
/>

And you do not need id property in your action.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top