如何使用属性文件使用struts2更改jquerytheme

问题描述 投票:1回答:1

这与我的previous question有些相关,我可以通过这种方式显示从属性文件中获取URL的图像:

<img height="40" src="<s:text name="login.logo"/>" class="pagelogo" alt="Logo" /> Login

并使用相同的方式我可以编辑某些style / CSS属性:

<h2 class="ccsBlockTitle" style="background-color: <s:text name="welcome.color" />">Welcome<h2>

我的content.properties看起来像这样:

login.logo=/oneFolderBefore/resources/media/login.png
login.title=Login
welcome.color=red
gui.theme=blitzer

Here列出了可用的主题和how to use them

但是当以这种方式调用它时:

<sj:head locale="es" jqueryui="true" jquerytheme="<s:text name="gui.theme"/>" compressed="false" defaultIndicator="ajax_loading" />

我希望上面的代码可以“减少”/“翻译”为:

<sj:head locale="es" jqueryui="true" jquerytheme="blitzer" compressed="false" defaultIndicator="ajax_loading" />

然而,我得到的是一个像这样的错误:

java.lang.RuntimeException: org.apache.jasper.JasperException: /WEB-INF/decorators/PlantillaWeb.jsp (line: [37], column: [73]) equal symbol expected
    com.opensymphony.sitemesh.webapp.decorator.BaseWebAppDecorator.render(BaseWebAppDecorator.java:39)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:84)
    org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:164)
    org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:191)
    com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:372)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:276)
    com.seguritech.botones.plugin.interceptor.ValidarSesionInterceptor.intercept(ValidarSesionInterceptor.java:51)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    org.apache.struts2.interceptor.CookieProviderInterceptor.intercept(CookieProviderInterceptor.java:75)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    org.apache.struts2.interceptor.CookieInterceptor.intercept(CookieInterceptor.java:258)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    org.apache.struts2.interceptor.CookieInterceptor.intercept(CookieInterceptor.java:258)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:76)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:229)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:253)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
    org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:575)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)

其中第37行是上面发布的,第73行是在megui.theme之间。

所以,我想改变单引号的内部双引号:

<sj:head locale="es" jqueryui="true" jquerytheme="<s:text name='gui.theme'/>" compressed="false" defaultIndicator="ajax_loading" />

但是当我检查我的HTML时,我得到了这个:

<link id="jquery_theme_link" rel="stylesheet" href="/my-project/struts/themes/<s:text name='gui.theme'/>/jquery-ui.css?s2j=3.7.1" type="text/css">

如果我像这样更改外部的:

<sj:head locale="es" jqueryui="true" jquerytheme='<s:text name="gui.theme"/>' compressed="false" defaultIndicator="ajax_loading" />

我明白了:

<link id="jquery_theme_link" rel="stylesheet" href="/my-project/struts/themes/<s:text name=" gui.theme"="">

我也尝试为jquerytheme更改${gui.theme}的值,但是我得到了与之前的问题相同的错误:

根据标记文件中的TLD或属性指令,属性值不接受任何表达式

那么,还有什么可以改变从我的jquerytheme文件中检索它的content.properties属性值呢?

在上面的情况除了第一个(使用双引号)我得到默认的base主题。

java jquery jquery-ui struts2 properties-file
1个回答
1
投票

我结束了这条线:

<sj:head locale="es" jqueryui="true" jquerytheme="base" compressed="false" defaultIndicator="ajax_loading" />

后来我在阅读这篇博客后想到了“连接”字符串:JQuery UI: Change theme dynamically using a drop-down,他们有以下代码:

<head> 
  <link id="stylesheet" rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/le-frog/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
</head>
...
<select id="themes">
  <option value="http://code.jquery.com/ui/1.10.4/themes/le-frog/jquery-ui.css">Le Frog</option>
  <option value="http://code.jquery.com/ui/1.10.4/themes/start/jquery-ui.css">Start</option>
  <option value="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">Smoothness</option>
  <option value="http://code.jquery.com/ui/1.10.4/themes/redmond/jquery-ui.css">Redmond</option>
  <option value="http://code.jquery.com/ui/1.10.4/themes/sunny/jquery-ui.css">Sunny</option>
</select>  
...

这让我想到在之前发布的那条线后面有这条线:

<link id="stylesheet" rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/le-frog/jquery-ui.css">

在我的content.properties文件中分为3部分,如下所示:

gui.current.theme=south-street

gui.theme.url.part1=//code.jquery.com/ui/1.10.4/themes/
gui.theme.url.part2=/jquery-ui.css

以上这一行划分如下:

<link id="stylesheet" rel="stylesheet" href="<s:text name="gui.theme.url.part1" /><s:text name="gui.current.theme" /><s:text name="gui.theme.url.part2" />" />

通过这些更改,我能够做我想要的,现在我的主题根据我在ThemeRoller属性中编写的任何主题(包含在gui.current.theme页面中)更改其CSS样式。

© www.soinside.com 2019 - 2024. All rights reserved.