我有一个JSF验证器,我正在构建其中包含我希望从ResourceBundle加载的属性.但是,我不太确定如何使用它,因为它没有正确加载.关于如何使这项工作的任何想法?
我尝试使用a @PostContruct来做,但我在Eclipse中遇到以下错误:
访问限制:由于对所需库/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Classes/classes.jar的限制,无法访问PostConstruct类型
所以,我不太清楚最好的方法是什么.我正在谈论的一个样本如下......
验证者......
@FacesValidator("usernameValidator")
public class UserNameValidator implements Validator {
@ManagedProperty(value="#{props_userNamePattern}")
private String userNamePattern;
@ManagedProperty(value="#{props_minUserNameLength}")
private int minUserNameLength;
@ManagedProperty(value="#{props_maxUserNameLength}")
private int maxUserNameLength;
public void validate(FacesContext context, UIComponent component, Object
value) throws ValidatorException {
//My validations here...
}
//Setters for the class properties
}
Run Code Online (Sandbox Code Playgroud)
faces-config.xml中
<resource-bundle>
<base-name>settings</base-name>
</resource-bundle>
Run Code Online (Sandbox Code Playgroud)
settings.properties
props_userNamePattern = /^[a-z0-9_-]+$/
props_minUserNameLength = 3
props_maxUserNameLength = 30
Run Code Online (Sandbox Code Playgroud) 我决定使用ResourceBundles为我的php应用程序提供翻译.虽然ResourceBundle(http://www.php.net/manual/en/class.resourcebundle.php)功能很新,但我更喜欢它在gettext上的工作方式.
我的问题是有没有好的ResourceBundle编辑器?特别是我正在寻找一个将扫描我的所有源文件并生成需要翻译和/或更新的消息ID列表.
以前,我使用POEdit为gettext生成翻译文件.它能够扫描我的源文件以获取_()等函数,并向我提供要翻译的消息ID列表.
我已经尝试安装一个eclipse插件(http://sourceforge.net/projects/eclipse-rbe/),虽然它有一个很好的GUI,但它不会扫描我的源文件来生成要翻译的消息ID列表.
任何人都可以推荐任何资源包编辑器吗?
我是 Spring 的新手,正在尝试使用它的 ReloadableResourceBundleMessageSource 类。
我正在尝试使用它,以便我们不再需要重新启动我们的 Web 应用程序来更改/更新属性文件。
我有一个 Web 应用程序(主要使用 JSF)和一个单独的 tar 组件,其中包含我的所有属性文件。
属性tar的结构如下:
- CompanyOneMessages.properties
- CompanyOneMessages_fr_FR.properties
- CompanyTwoMessages.properties
- CompanyTwoMessages_fr_FR.properties
- CompanyThreeMessages.properties
- CompanyThreeMessages_fr_FR.properties
- ...
Run Code Online (Sandbox Code Playgroud)
此 tar 被解压缩并部署到服务器上的某个位置,该位置指定为位于 websphere 配置中的类路径上。
我将以下内容添加到我的 applicationContext-config.xml 中:
<!-- Enable reloading of resource bundles without requiring web-app restart -->
<bean id="messages"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basenames">
<list>
<value>classpath:com/resource/dynamic/CompanyOneMessages</value>
<value>classpath:com/resource/dynamic/CompanyTwoMessages</value>
<value>classpath:com/resource/dynamic/CompanyThreeMessages</value>
</list>
</property>
<property name="cacheSeconds" value="1" />
</bean>
<!-- Declare location of bean to handle messages and define property reference
we will use to …Run Code Online (Sandbox Code Playgroud) 这是使用Guice在Tomcat上运行的webapp.根据文档,我们应该能够调用ResourceBundle.clearCache();清除ResourceBundle缓存,并且可能从bundle属性文件中获取最新信息.
我们还尝试了以下方法:
Class klass = ResourceBundle.getBundle("my.bundle").getClass().getSuperclass();
Field field = klass.getDeclaredField("cacheList");
field.setAccessible(true);
ConcurrentHashMap cache = (ConcurrentHashMap) field.get(null);
cache.clear(); // If i debug here I can see the cache is now empty!
Run Code Online (Sandbox Code Playgroud)
和
ResourceBundle.clearCache(this.class.getClassLoader());
Run Code Online (Sandbox Code Playgroud)
我期待的行为是:
所以问题是,ResourceBundle.clearCache()实际上是如何工作的?还有一些我们需要清除的通用文件缓存吗?
我在NetBeans中有一个java项目,我使用Mercurial进行版本控制.我希望在约框中看到我的项目版本号,我希望根据Mercurial版本号更新它.有什么想法怎么做?:)
我写了一个新的应用程序,它将使用现有的主题,设计师将对其进行更改。
因此,我决定将主题保留在Theme文件夹(带有子目录-js,css,img)中,而不是将脚本放入“脚本”中以及“内容”中的其他所有内容(Css,图像)中
所以我尝试更改捆绑的脚本以指向主题/ js中的脚本,而不是脚本
我将其更改为
bundles.Add(
new ScriptBundle("~/Scripts/vendor")
.Include("~/Theme/js/jquery-{version}.js")
.Include("~/Theme/js/knockout-{version}.debug.js")
.Include("~/Theme/js/sammy-{version}.js")
.Include("~/Theme/js/toastr.js")
.Include("~/Theme/js/Q.js")
.Include("~/Theme/js/breeze.debug.js")
.Include("~/Theme/js/bootstrap.js")
.Include("~/Theme/js/moment.js")
);
Run Code Online (Sandbox Code Playgroud)
我不明白的是线
new ScriptBundle("~/Scripts/vendor")
Run Code Online (Sandbox Code Playgroud)
如果我将其保留为上述内容(即使没有Scripts / vendor文件夹,代码也可以正常工作,但是如果我将其更改为
new ScriptBundle("~/Theme/js/vendor")
Run Code Online (Sandbox Code Playgroud)
我在萤火虫中收到网络错误:
"NetworkError: 404 Not Found - http://localhost:51154/scripts/vendor"
Run Code Online (Sandbox Code Playgroud)
其余脚本未加载。
那条线是做什么的?
谢谢
我有一个 Web 服务实现,它验证请求并在响应中写入错误消息。响应的格式不符合要求。
错误消息模板位于资源包属性文件中。
...
key=Plant name {0} Plant Id {1}.
...
Run Code Online (Sandbox Code Playgroud)
这是我在验证后收到的错误消息。
Plant name PLANT1 Plant Id 9,905,005.
Run Code Online (Sandbox Code Playgroud)
但所需的输出没有数字变量的逗号。
Plant name WPLANT Plant Id 9905005.
Run Code Online (Sandbox Code Playgroud)
这是我的代码。
...
key=Plant name {0} Plant Id {1}.
...
Run Code Online (Sandbox Code Playgroud)
我使用以下键和变量调用此方法。
Plant name PLANT1 Plant Id 9,905,005.
Run Code Online (Sandbox Code Playgroud)
如何更改此代码以获得所需的输出?我更喜欢不包含 %s, %d 的方法,因为这样我就失去了更改属性文件中错误消息中变量顺序的能力。
我正在使用名为jnca的库来捕获从路由器发送的netflow udp数据包.
当它被导入到IntellijIDea中的新项目时,它可以工作.

在maven项目中使用它时,它不起作用并给出此异常.

例外:
java.util.MissingResourceException: Can't find bundle for base name org.wso2.event.adaptor.udp.jnca.etc.NetFlow, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1499)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1322)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:795)
at org.wso2.event.adaptor.udp.jnca.cai.utils.Resources.<init>(Resources.java:24)
at org.wso2.event.adaptor.udp.jnca.cai.flow.collector.Collector.<clinit>(Collector.java:51)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at org.wso2.event.adaptor.udp.jnca.cai.flow.collector.Run.<clinit>(Run.java:14)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)
NetFlow.properties: Can't find bundle for base name org.wso2.event.adaptor.udp.jnca.etc.NetFlow, locale en_US
Run Code Online (Sandbox Code Playgroud)
没有包命名问题.
问题在于此代码段
try {
resources = ResourceBundle.getBundle("org.wso2.event.adaptor.udp.jnca.etc." + myName, Locale
.getDefault());
} catch (MissingResourceException exc) {
exc.printStackTrace();
error(SuperString.exceptionMsg(exc.toString()));
}
Run Code Online (Sandbox Code Playgroud)
myName = Netflow
我已经尝试更改资源的路径,但它不起作用.并尝试将该netflow.properties文件包含在maven项目的资源文件夹中,它也无法正常工作
如何解决这个问题
谢谢
在我的应用程序中,我有一个键(字符串)列表,用户可以在其中选择其中一个.在用户界面中,将根据当前区域设置输出密钥:
<h:selectOneMenu value="#{bean.selectedKey}">
<f:selectItems value="#{bean.allKeys}" var="_key" itemLabel="#{msgs[_key]}" />
</h:selectOneMenu>
Run Code Online (Sandbox Code Playgroud)
我的设置使用配置的标准资源包,faces-config.xml如BalusC 在本回答中所述.msgs在上面的示例中是资源包变量的名称.
我现在selectOneMenu想要的是,要按字母顺序排序的项目.当然,顺序取决于使用的区域设置.问题是,我不能/不会在backing-bean中进行排序,因为我不知道JSF页面将如何输出密钥.
这个问题对我来说似乎很通用,所以我想知道解决这类问题的最佳做法是什么.
(当然问题不仅适用于selectOneMenu.任何将在用户界面中输出的列表/集合都会遇到同样的问题.)
目前,我正在使用 Jester 编写一个 Web 应用程序,并希望通过捆绑所有静态资源(CSS、HTML、JS)来促进部署。
在 Nim 中执行此操作的最佳方法是什么?
resourcebundle ×10
java ×4
jsf ×2
asp.net-mvc ×1
file ×1
guice ×1
jsf-2 ×1
localization ×1
maven ×1
mercurial ×1
netbeans ×1
nim-lang ×1
php ×1
sorting ×1
spring-mvc ×1
tomcat ×1
versioning ×1