【发布时间】:2014-03-18 15:38:22
【问题描述】:
我对 Vaadin 框架很陌生,我正在尝试制作一个国际化的应用程序。我正在使用 NetBeans,我已按照以下步骤操作:
- 使用单个 UI 类创建一个新的 Vaadin 项目 文本字段。
- 我进入了工具 -> 国际化 -> 国际化向导,并按照这些步骤将 UI 类国际化。
很简单。但是当我运行应用程序时,我得到了这个异常:
javax.servlet.ServletException: com.vaadin.server.ServiceException: java.util.MissingResourceException: Can't find bundle for base name com/mycompany/i18ntest/Bundle, locale es_AR
com.vaadin.server.VaadinServlet.service(VaadinServlet.java:240)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
异常提示 Bundle.properties 文件无法找到,但它与 UI 类存在于同一个包中:
MyVaadinUI.java
package com.mycompany.i18ntest;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.FormLayout;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import java.util.ResourceBundle;
@Theme("mytheme")
@SuppressWarnings("serial")
public class MyVaadinUI extends UI {
private final ResourceBundle bundle = ResourceBundle.getBundle("com/mycompany/i18ntest/Bundle");
@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = MyVaadinUI.class
, widgetset = "com.mycompany.i18ntest.AppWidgetSet")
public static class Servlet extends VaadinServlet {
}
@Override
protected void init(VaadinRequest request) {
TextField textField = new TextField(bundle.getString("MyVaadinUI.textField.caption"));
textField.setRequired(true);
textField.setRequiredError(bundle.getString("MyVaadinUI.textField.requiredError"));
final FormLayout layout = new FormLayout(textField);
layout.setMargin(true);
setContent(layout);
}
}
Bundle.properties
MyVaadinUI.textField.caption = User
MyVaadinUI.textField.requiredError = Please input your user name here
另外,我尝试将 .properties 文件重命名为 Bundle_es_AR.properties,因为我的浏览器的默认语言是西班牙语(es)阿根廷(AR),但没有运气,仍然出现异常。
【问题讨论】:
-
Bundle.properties 是否也包含在 WAR 文件中?
-
不,不是!而且我不知道如何使 WAR 文件包含它。我正在检查所有项目属性选项,但我没有找到如何在项目部署中包含此文件。 @AndréSchild
标签: java maven netbeans vaadin vaadin7