[freemarker]使用freemarker生成父子关系树抛异常

需要生成一个菜单树,使用了freemarker,由于采用了tiles2,在和freemarker整合的时候出现了问题,所以直接使用freemarker 2.3.15将模板通过template.process方法产生html code显示到前端,主要代码如下:
[code="java"]
//产生freemarker config
package project.util.freemarker;

import freemarker.cache.ClassTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.DefaultObjectWrapper;
import freemarker.template.TemplateExceptionHandler;

public class FreeMarkerService {
private static Configuration cfg = new Configuration();

static {
    //设置模版加载的路径,相对于FreemarkerService类路径下的templates路径
    cfg.setTemplateLoader(new ClassTemplateLoader(FreeMarkerService.class,
            "ftl"));
    //设置对象包装器
    cfg.setObjectWrapper(new DefaultObjectWrapper());
    //设置默认编码
    cfg.setDefaultEncoding("UTF-8");
    //设置异常处理器
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
}

public static Configuration getConfiguration() {
    return cfg;
}

}
[/code]

[code="java"]
//freemarker工具类,将数据和模板合成html
package project.util.freemarker

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Map;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

public class FreeMarkerUtil {
@SuppressWarnings("rawtypes")
public static String dataToString(Map data,String templatePath) throws IOException,TemplateException{
if(data == null){
return null;
}

    Writer out = null;

    Configuration cfg = FreeMarkerService.getConfiguration();
    Template template = cfg.getTemplate(templatePath);
    out = new StringWriter();
    template.process(data,out);
    return out.toString();
}

}
[/code]

freemarker 模板
[code="html"]
<#-- 定义宏buildNode -->
<#macro buildNode child parent>




style="text-decoration:line-through"
</#if>
>
${parent.menuName}


<#if child?? && child?size gt 0>

    <#list child as t>
    <#-- 递归调用宏buildNode -->
    <@buildNode child=t.children parent=t/>
    </#list>

</#if>

</#macro>
    <ul>
        <@buildNode child=rootMenu.children parent=rootMenu/>
    </ul>

[/code]

[code="java"]
//实体类
package project.bean;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

@Entity
@Table(name="RBAC_MENUS")
public class Menu {
private int menuId;
private String menuName;
private String description;
private Menu parent;
private List

children;
private List functions;
private String isDel;
public Menu(){}

@Id
@GeneratedValue(generator = "paymentableGenerator")     
@GenericGenerator(name = "paymentableGenerator", strategy = "sequence", parameters= {@Parameter(name="sequence",value="RBAC_MENU_SEQ")})
@Column(name="MENU_ID")
public int getMenuId() {
    return menuId;
}

public void setMenuId(int menuId) {
    this.menuId = menuId;
}

@Column(name="MENU_NAME")
public String getMenuName() {
    return menuName;
}

public void setMenuName(String menuName) {
    this.menuName = menuName;
}

@ManyToOne(cascade = {CascadeType.MERGE,CascadeType.REFRESH }, optional = true)  
@JoinColumn(name="PARENT_MENU_ID")
public Menu getParent() {
    return parent;
}

public void setParent(Menu parent) {
    this.parent = parent;
}

@OneToMany(cascade = { CascadeType.REFRESH, CascadeType.PERSIST,
        CascadeType.MERGE, CascadeType.REMOVE },mappedBy ="parent")
public List<Menu> getChildren() {
    return children;
}

public void setChildren(List<Menu> children) {
    this.children = children;
}

public void addChildren(Menu menu){
    if(this.children == null){
        this.children = new ArrayList<Menu>();
    }
    this.children.add(menu);
}

@OneToMany(cascade = { CascadeType.REFRESH, CascadeType.PERSIST,CascadeType.MERGE, CascadeType.REMOVE },mappedBy ="menu")
public List<Function> getFunctions() {
    return functions;
}

public void setFunctions(List<Function> functions) {
    this.functions = functions;
}

@Column(name="IS_DEL")
public String getIsDel() {
    return isDel;
}

public void setIsDel(String isDel) {
    this.isDel = isDel;
}

@Column(name="description")
public String getDescription() {
    return description;
}

public void setDescription(String description) {
    this.description = description;
}

}
[/code]

[code="java"]
//Struts action
package project.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import project.bean.Menu;
import project.service.MenuService;
import project.util.freemarker.FreeMarkerUtil;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

public class MenuAction extends ActionSupport {
...
@Resource private MenuService menuService;

    private String menuTree;

    public String getMenuTree(){
    return menuTree;
}
   ...
@SuppressWarnings({ "rawtypes", "unchecked" })
public String initMenu(){

    Menu rootMenu = menuService.getRootMenu();

    try{
        Map freemarkerData = new HashMap();
        freemarkerData.put("rootMenu", rootMenu);
        freemarkerData.put("webRoot", ServletActionContext.getServletContext().getContextPath());
        menuTree = FreeMarkerUtil.dataToString(freemarkerData, "menumgmt.ftl");
    }
    catch(Exception e){
        e.printStackTrace();
    }

    return ActionSupport.SUCCESS;
}
    ...

[/code]

[code="java"]
//Menu Service实现类
public class MenuServiceImpl implements MenuService {
@Resource private SessionFactory sessionFactory;
...

//得到根菜单
@SuppressWarnings("unchecked")
@Override
public Menu getRootMenu() {
    List<Menu> menus = sessionFactory.getCurrentSession().createQuery("from Menu m where m.parent is null").list();

    if(menus != null && menus.size()>0)
        return menus.get(0);

    return null;
}

//插入菜单
@Override
public void insertMenu(Menu menu) {
    sessionFactory.getCurrentSession().persist(menu);
}
    ...

}
[/code]

jsp代码
[code="html"]
...


<!--添加层开始-->

菜单列表


${menuTree}



...
<br> $(document).ready(function(){<br> $(&quot;#treeContainer ul&quot;).Treeview();<br> $(&quot;#treeContainer&quot;).show(500);<br> });<br>
[/code]

异常信息
...
Hibernate:
select
menu0_.MENU_ID as MENU1_2_,
menu0_.description as descript2_2_,
menu0_.IS_DEL as IS3_2_,
menu0_.MENU_NAME as MENU4_2_,
menu0_.PARENT_MENU_ID as PARENT5_2_
from
RBAC_MENUS menu0_
where
menu0_.PARENT_MENU_ID is null
Hibernate:
select
children0_.PARENT_MENU_ID as PARENT5_1_,
children0_.MENU_ID as MENU1_1_,
children0_.MENU_ID as MENU1_2_0_,
children0_.description as descript2_2_0_,
children0_.IS_DEL as IS3_2_0_,
children0_.MENU_NAME as MENU4_2_0_,
children0_.PARENT_MENU_ID as PARENT5_2_0_
from
RBAC_MENUS children0_
where
children0_.PARENT_MENU_ID=?
[ERROR] [freemarker.log.Log4JLoggerFactory$Log4JLogger.error(Log4JLoggerFactory.java:96)] er.runtime -

Expression parent.parent is undefined on line 3, column 43 in menumgmt.ftl.

The problematic instruction:

==> ${parent.parent.menuId} [on line 3, column 41 in menumgmt.ftl]

in user-directive buildNode [on line 27, column 21 in menumgmt.ftl]

Java backtrace for programmers:

freemarker.core.InvalidReferenceException: Expression parent.parent is undefined on line 3, column 43 in menumgmt.ftl.
at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java:124)
at freemarker.core.TemplateObject.invalidTypeException(TemplateObject.java:134)
at freemarker.core.Dot._getAsTemplateModel(Dot.java:78)
at freemarker.core.Expression.getAsTemplateModel(Expression.java:89)
at freemarker.core.Expression.getStringValue(Expression.java:93)
at freemarker.core.DollarVariable.accept(DollarVariable.java:76)
at freemarker.core.Environment.visit(Environment.java:209)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:209)
at freemarker.core.Macro$Context.runMacro(Macro.java:168)
at freemarker.core.Environment.visit(Environment.java:602)
at freemarker.core.UnifiedCall.accept(UnifiedCall.java:106)
at freemarker.core.Environment.visit(Environment.java:209)
at freemarker.core.MixedContent.accept(MixedContent.java:92)
at freemarker.core.Environment.visit(Environment.java:209)
at freemarker.core.Environment.process(Environment.java:189)
at freemarker.template.Template.process(Template.java:237)
at project.rbac.util.freemarker.FreeMarkerUtil.dataToString(FreeMarkerUtil.java:24)
at project.rbac.web.MenuAction.initMenu(MenuAction.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:184)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:422)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
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:857)
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)
Hibernate:
select
children0_.PARENT_MENU_ID as PARENT5_1_,
children0_.MENU_ID as MENU1_1_,
children0_.MENU_ID as MENU1_2_0_,
children0_.description as descript2_2_0_,
children0_.IS_DEL as IS3_2_0_,
children0_.MENU_NAME as MENU4_2_0_,
children0_.PARENT_MENU_ID as PARENT5_2_0_
from
RBAC_MENUS children0_
where
children0_.PARENT_MENU_ID=?
Hibernate:
select
children0_.PARENT_MENU_ID as PARENT5_1_,
children0_.MENU_ID as MENU1_1_,
children0_.MENU_ID as MENU1_2_0_,
children0_.description as descript2_2_0_,
children0_.IS_DEL as IS3_2_0_,
children0_.MENU_NAME as MENU4_2_0_,
children0_.PARENT_MENU_ID as PARENT5_2_0_
from
RBAC_MENUS children0_
where
children0_.PARENT_MENU_ID=?
...

菜单能够正常展现,但是这个异常为什么发生呢,我还碰到一个问题就是当我选择一个菜单项,并且插入一个子菜单的时候,发生一个异常,并且页面也无法展现最新插入的那个菜单,需要刷新一下才能看到新插入的菜单

程序界面如下:

[img]http://hiphotos.baidu.com/lucky_sonic/pic/item/c81382cf5b0ce869f9dc612a.jpg[/img]

2个回答

[quote]当我客户端插入一个新的菜单的时候,由Action返回,菜单树上面新的菜单没有被加载,html代码中也看不到,我在Action中调试,发现查询出来的数据是对的,包含了新插入的菜单,我就怀疑是否是freemarker的问题,不知是否能够给出解答. [/quote]
因为我没有你的开发环境,也不知道你菜单生成的机制,也不知道调用结构。但你可以通过debug看看数据在哪里出错:
1.action
2.freemarker渲染数据
3.界面某些js出错
可以用一些js调试技巧发现问题,很多问题会是界面的问题,比如一些空格、标点、参数不对、id重复等都有可能照成界面出不来。

freemarker里面层级对象引用xx.xx.xx,每一级都需要判断是否为空,否则抛异常。
[code="java"]Expression parent.parent is undefined on line 3, column 43 in menumgmt.ftl. [/code]
看到没有,说parent.parent未定义。结贴吧。哈哈。

给出我以前的代码,以供参考:
[code="java"]<#--
Description:栏目模板(图片Tab方式,上面横向展示商品,有图片,一行五列;下面只展示商品内容,无图片)
Author: Peter Wei
Date: 2010-1-26
-->

<#--
参数配置,如果ctx,images有值传进来,则用传进来的值;没有,则赋值.
-->
<#if !(ctx?exists && ctx?has_content)>
<#assign ctx = "/web" />
</#if>
<#if !(images?exists && images?has_content)>
<#assign images = "/web/images" />
</#if>

  • ${subList.title?if_exists}
  • #list> #if>
<div class="tab_content">
<#if  root.subList?exists>
    <#list root.subList as subList>
        <div class="tab_item">
            <ul> <#if  subList.productList?exists>
                <#list subList.productList as product>
                    <li>
                        <div class="sku-img"><a href="${ctx}/product/${product.sid}.html"><img
                                src="${images}/${product.proPicture?if_exists.proPictDir?if_exists}/${product.proPicture?if_exists.proPictName?if_exists}"
                                alt="${product.proSku?if_exists}"/>

                            <div class="zhekou">
                            ${product.proPrice?if_exists.offValue?default("0")}折
                            </div>
                        </a>
                        </div>
                        <div><a href="${ctx}/product/${product.sid}.html">

                            <p>${product.productName?if_exists}</p>
                        </a>

                            <h3>
                                <em>${product.proPrice?if_exists.originalPrice?if_exists}</em>¥${product.proPrice?if_exists.promotionPrice?if_exists}
                            </h3>
                            <span class="color666666">
                                <#if (product.productCates?exists)&&(product.productCates?size>=1)>
                                    <a href="${ctx}/list--${product.productCates[0].sid}.html">更多同类商品>></a>
                                    <#else>
                                        <a href="${ctx}/list-${product.brandSid}.html">更多同类商品>></a>
                                </#if>
                            </span>
                        </div>
                    </li>
                    <#if (product_index>=4)> <#break> </#if>
                </#list>
            </#if>
            </ul>

        <ul class="tab-list">
            <#assign i=0 />
            <#if  subList.productList?exists>
                <#list subList.productList as product>
                    <#if (product_index>4)>
                        <#if (i%3==0)&&(i>2)>
                        </ul>
                        <ul class="tab-list">
                        </#if>
                        <li><a href="${ctx}/product/${product.sid}.html"><span
                                class="ff6600">[立省${product.proPrice?if_exists.saveMoney?if_exists}
                            元]</span>${product.productName?if_exists}
                        </a>
                        </li>
                        <#if (product_index>=10)> <#break> </#if>
                        <#assign i=i+1 />
                    </#if>
                </#list>
            </#if>
        </ul>
        </div>
    </#list>
</#if>
</div>

[/code]
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!