NutzCN Logo
问答 自定义viewMarker遇到Eval FAIL
发布于 2034天前 作者 任杰 1375 次浏览 复制 上一个帖子 下一个帖子
标签:

自定义viewMarker如下:

@Override
	public View make(Ioc ioc, String type, String value) {
		
		log.info("type:" + type);
		log.info("value:" + value);
		if(type.equals(ADMIN_JSON)) {
			if (StringUtils.isEmpty(value)) {
	                return new AdminView(JsonFormat.nice()).setJsonp(true);
            }else {
            	// 除高级的json format定义之外,也支持简单的缩写
                if (value.charAt(0) == '{'){
                	log.info("=======================");
                    return new AdminView(Json.fromJson(JsonFormat.class, value)).setJsonp(true);
                }else if ("nice".equals(value))
                    return new AdminView(JsonFormat.nice()).setJsonp(true);
                else if ("forlook".equals(value))
                    return new AdminView(JsonFormat.forLook()).setJsonp(true);
                else if ("full".equals(value))
                    return new AdminView(JsonFormat.full()).setJsonp(true);
                else if ("compact".equals(value))
                    return new AdminView(JsonFormat.compact()).setJsonp(true);
                else if ("tidy".equals(value))
                    return new AdminView(JsonFormat.tidy()).setJsonp(true);
                else
                    throw new IllegalArgumentException("unkown json view format : " + value);
            }
		}
		return null;
	}

Module入口如下:

@At("/screen-agent")
@Ok("adminJson:{dateFormat:'yyyyMMdd'}")

就是使用自己的jsonview,继承了utf8jsonView,想使用原本的format

12 回复

@Views写了没

MainModule

@SetupBy(value = MainModule.class)
@IocBy(type = ComboIocProvider.class, args = { "*js", "ioc.js", "*anno", "com.tohours.superplanner", "*tx", "*quartz" })
@Views(value = {SpViewMaker.class, DefaultViewMaker.class})
@ChainBy(args = { "chain.js" })

debug一下 if(type.equals(ADMIN_JSON)) { 这一行

错误日志:

[superplanner][INFO ]2019-05-28 14:11:58,897 (com.tohours.superplanner.view.SpViewMaker:24) type:adminjson
 [superplanner][INFO ]2019-05-28 14:11:58,897 (com.tohours.superplanner.view.SpViewMaker:25) value:{dateFormat:'yyyyMMdd'}
 [superplanner][DEBUG]2019-05-28 14:11:58,898 (org.nutz.mvc.impl.NutActionChainMaker:51) Eval FAIL!! : public org.nutz.lang.util.NutMap com.tohours.superplanner.module.AdminModule.screenAgent(java.lang.String,java.lang.Integer,java.lang.Integer)
 java.lang.RuntimeException: Can not eval adminJson:{dateFormat:'yyyyMMdd'}("adminJson:{dateFormat:'yyyyMMdd'}") View for public org.nutz.lang.util.NutMap com.tohours.superplanner.module.AdminModule.screenAgent(java.lang.String,java.lang.Integer,java.lang.Integer)
	at org.nutz.lang.Lang.makeThrow(Lang.java:139)
	at org.nutz.mvc.view.ViewZone.makeView(ViewZone.java:90)
	at org.nutz.mvc.impl.processor.ViewProcessor.evalView(ViewProcessor.java:89)
	at org.nutz.mvc.impl.processor.ViewProcessor.init(ViewProcessor.java:31)
	at org.nutz.mvc.impl.NutActionChainMaker.eval(NutActionChainMaker.java:38)
	at org.nutz.mvc.impl.UrlMappingImpl.add(UrlMappingImpl.java:54)
	at org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:205)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:108)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:91)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:69)
	at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:137)
	at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:856)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349)
	at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1404)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1366)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)
	at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
	at org.eclipse.jetty.server.Server.start(Server.java:411)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
	at org.eclipse.jetty.server.Server.doStart(Server.java:378)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at net.sourceforge.eclipsejetty.starter.jetty9.Jetty9Adapter.start(Jetty9Adapter.java:68)
	at net.sourceforge.eclipsejetty.starter.common.AbstractJettyLauncherMain.launch(AbstractJettyLauncherMain.java:84)
	at net.sourceforge.eclipsejetty.starter.jetty9.Jetty9LauncherMain.main(Jetty9LauncherMain.java:42)
[superplanner][ERROR]2019-05-28 14:11:58,902 (org.nutz.mvc.impl.NutLoading:125) Error happend during start serivce!
 java.lang.RuntimeException: Can not eval adminJson:{dateFormat:'yyyyMMdd'}("adminJson:{dateFormat:'yyyyMMdd'}") View for public org.nutz.lang.util.NutMap com.tohours.superplanner.module.AdminModule.screenAgent(java.lang.String,java.lang.Integer,java.lang.Integer)
	at org.nutz.lang.Lang.makeThrow(Lang.java:139)
	at org.nutz.mvc.view.ViewZone.makeView(ViewZone.java:90)
	at org.nutz.mvc.impl.processor.ViewProcessor.evalView(ViewProcessor.java:89)
	at org.nutz.mvc.impl.processor.ViewProcessor.init(ViewProcessor.java:31)
	at org.nutz.mvc.impl.NutActionChainMaker.eval(NutActionChainMaker.java:38)
	at org.nutz.mvc.impl.UrlMappingImpl.add(UrlMappingImpl.java:54)
	at org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:205)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:108)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:91)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:69)
	at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:137)
	at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:856)
	at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:349)
	at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1404)
	at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1366)
	at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)
	at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)
	at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:520)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)
	at org.eclipse.jetty.server.Server.start(Server.java:411)
	at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)
	at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
	at org.eclipse.jetty.server.Server.doStart(Server.java:378)
	at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
	at net.sourceforge.eclipsejetty.starter.jetty9.Jetty9Adapter.start(Jetty9Adapter.java:68)
	at net.sourceforge.eclipsejetty.starter.common.AbstractJettyLauncherMain.launch(AbstractJettyLauncherMain.java:84)
	at net.sourceforge.eclipsejetty.starter.jetty9.Jetty9LauncherMain.main(Jetty9LauncherMain.java:42)
[superplanner][ERROR]2019-05-28 14:11:58,903 (org.nutz.mvc.impl.NutLoading:127) try to depose ioc

看上去只是type.equals没对上

总的viewmarker:

package com.tohours.superplanner.view;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.nutz.ioc.Ioc;
import org.nutz.json.Json;
import org.nutz.json.JsonFormat;
import org.nutz.mvc.View;
import org.nutz.mvc.ViewMaker;

public class SpViewMaker implements ViewMaker{

	private static final Logger log = Logger.getLogger(SpViewMaker.class);
	
	private final String ADMIN_JSON = "adminJson";
	
	public SpViewMaker() {
		super();
	}
	
	@Override
	public View make(Ioc ioc, String type, String value) {
		
		log.info("type:" + type);
		log.info("value:" + value);
		if(type.equals(ADMIN_JSON)) {
			if (StringUtils.isEmpty(value)) {
	                return new AdminView(JsonFormat.nice()).setJsonp(true);
            }else {
            	// 除高级的json format定义之外,也支持简单的缩写
                if (value.charAt(0) == '{'){
                	log.info("=======================");
                    return new AdminView(Json.fromJson(JsonFormat.class, value)).setJsonp(true);
                }else if ("nice".equals(value))
                    return new AdminView(JsonFormat.nice()).setJsonp(true);
                else if ("forlook".equals(value))
                    return new AdminView(JsonFormat.forLook()).setJsonp(true);
                else if ("full".equals(value))
                    return new AdminView(JsonFormat.full()).setJsonp(true);
                else if ("compact".equals(value))
                    return new AdminView(JsonFormat.compact()).setJsonp(true);
                else if ("tidy".equals(value))
                    return new AdminView(JsonFormat.tidy()).setJsonp(true);
                else
                    throw new IllegalArgumentException("unkown json view format : " + value);
            }
		}
		return null;
	}
	

}

"adminJson" -- "adminjson"

大小写对不上

不对哈,我Module里面用的是

@Ok("adminJson:{dateFormat:'yyyyMMdd'}")

为什么在启动的时候成了adminjson

是不是框架装成了小写的,我需要做一下转换是吧

翻了翻代码,ViewZone里面把type转小写了

添加回复
请先登陆
回到顶部