【问题标题】:How to change jquerytheme with struts2 using a properties file如何使用属性文件使用 struts2 更改 jquerytheme
【发布时间】:2017-12-18 17:54:04
【问题描述】:

这与我的previous question 有点相关,在该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 或属性指令,属性值不接受任何表达式

那么,从我的content.properties 文件中检索jquerytheme 属性值的另一种方法是什么?

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

【问题讨论】:

  • Struts 标签语法不允许您使用 EL 表达式。
  • @RomanC 是的,这也是我在上一个问题中发现的......这就是我在尝试使用s:text name 时首先没有考虑的原因,但是当我做不到时,我决定尝试使用 EL 表达式来试试运气。但是,我已经搜索了所有我能想到的方法,但找不到类似的东西。你知道有什么方法可以做我想做的吗?任何解决方法都可能,任何事情都可能有所帮助
  • 您可以通过多种方式加载属性,然后将其应用于操作。

标签: java jquery jquery-ui struts2 properties-file


【解决方案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" />" />

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

【讨论】:

    猜你喜欢
    • 2010-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-22
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多