2014-10-10 49 views
1

我有一个托管的bean,它返回许多描述应用程序的不同属性。因此它可以被称为致电尝试计算Bean中调用的方法

appProps返回数据库的文件路径[sessionScope.ssApplication] .helpFilePath

appProps [sessionScope.ssApplication] .ruleFilePath

我试图找出一个通用的案例,我需要根据compositeData变量中的值调用文件路径,该变量可以采用4个不同值help/rule/app/main中的任何一个值。

我写了这SSJS和它的作品,但我想知道是否有更好的方法,使其工作:

var target:String = compositeData.DBSource; 
switch (target){ 
    case "app" : 
     return appProps[sessionScope.ssApplication].appFilePath; 
     break; 
    case "help" : 
     return appProps[sessionScope.ssApplication].helpFilePath; 
     break; 
    case "rule" : 
     return appProps[sessionScope.ssApplication].ruleFilePath; 
     break; 
    case "main" : 
     return appProps[sessionScope.ssApplication].mainFilePath; 
     break; 

} 

我无法弄清楚是否有利用计算方法的方式compositeData.DBSource +“FilePath”。当我尝试这个时,我得到一个错误,该方法不存在。使用上面的SSJS代码并不是一个真正的问题,但它似乎有点多余。

回答

2

你可以使你的管理bean中的新方法,它的目标作为参数:

public String getFilePath(String target) { 
    String returnValue = ""; 
    if (target.equalsIgnoreCase("app")) { 
     returnValue = this.appFilePath; 
    } else if (target.equalsIgnoreCase("help")) { 
     returnValue = this.helpFilePath; 
    } else if (target.equalsIgnoreCase("rule")) { 
     returnValue = this.ruleFilePath; 
    } else if (target.equalsIgnoreCase("main")) { 
     returnValue = this.mainFilePath; 
    } 

    return returnValue; 
} 

,然后在SSJS这样称呼它:

appProps[sessionScope.ssApplication].getFilePath(compositeData.DBSource); 
+0

这会工作。谢谢。 compositeData.dbSource会在EL中工作吗? – 2014-10-11 14:16:10

相关问题