我想将我的jsf web项目的默认位置设置为英语,所以我做了以下内容:
faces-config.xml中
<application>
<locale-config>
<default-locale>en_EN</default-locale>
<supported-locale>de_DE</supported-locale>
</locale-config>
<resource-bundle>
<base-name>de.hof.tschuwwa.resources.messages</base-name>
<var>msg</var>
</resource-bundle>
</application>
Run Code Online (Sandbox Code Playgroud)
我在我的src文件夹中有一个包,在de.hof.tschuwwa.resources该包内有两个属性文件:
messages_de_DE.properties
messages_en_EN.properties
Run Code Online (Sandbox Code Playgroud)
我在一个小的xhtml文件中测试它:
<h:body>
<ui:composition template="/templates/master.xhtml">
<ui:define name="header">
<h:form>
<h:commandButton action="#{navigationService.toLogin}" value="#{msg['login']}" />
<h:commandButton action="#{navigationService.toRegister}" value="#{msg['register']}" />
</h:form>
</ui:define>
</ui:composition>
</h:body>
Run Code Online (Sandbox Code Playgroud)
当我开始我的应用程序时,它显示德国值而不是英语值.我希望默认语言是英语.
如何设置我的默认语言?faces-config.xml默认语言环境似乎不起作用.
此外,我需要知道如何改变我的本地化.我写了这个小服务:
@Named
@SessionScoped
public class LanguageService implements Serializable {
private static final long serialVersionUID = 1L;
public void changeLanguage(String language) {
FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale(language));
}
}
Run Code Online (Sandbox Code Playgroud)
并尝试使用表单中的以下按钮:
<p:commandButton id="english" value="English" action="#{languageService.changeLanguage('en')}" immediate="true" />
<p:commandButton id="german" value="Deutsch" action="#{languageService.changeLanguage('de')}" immediate="true" />
Run Code Online (Sandbox Code Playgroud)
但是当我使用它们时没有任何反应.
使用JPA我有一个与CascadeTypes有关的问题.
例如:
@ManyToMany(fetch=FetchType.LAZY, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
Run Code Online (Sandbox Code Playgroud)
与此不同:
@ManyToMany(fetch=FetchType.LAZY, cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
Run Code Online (Sandbox Code Playgroud)
为什么?我需要cascadetype persist来自动在我的实体类中插入引用的对象.我需要合并,因为我不希望在我的表中有双重条目.但是当我首先定义持久化时,合并不起作用,当我首先定义合并时,持久化不起作用.
为什么?
我的jsf表格有一个小问题.我做了一个带有提交按钮和重置按钮的示例注册表单:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Register</title>
</h:head>
<h:body>
<ui:composition template="/templates/master.xhtml" >
<ui:define name="content">
<center>
<h:outputText value="New User Registration" />
</center>
<h:form>
<h:panelGrid columns="3">
<h:outputText value="Username:" />
<h:inputText id="username" value="#{registerService.userName}" required="true" requiredMessage="Please Enter Username!" />
<h:message for="username" style="color:red" />
<h:outputText value="Password:" />
<h:inputSecret id="password" value="#{registerService.password}" required="true" requiredMessage="Please Enter Password!" />
<h:message for="password" style="color:red" />
<h:outputText value="Confirm Password:" />
<h:inputSecret id="confirmPassword" value="#{registerService.confirmPassword}" required="true" requiredMessage="Please Confirm Password!" />
<h:message …Run Code Online (Sandbox Code Playgroud) 我有一个250 GB的大.txt文件,我的硬盘上只剩下50 GB的空间.此.txt文件中的每一行都有一个长前缀,我想删除此前缀以使该文件更小.
首先,我想逐行阅读,更改它并将其写入另一个文件.
// read line out of first file
line = line.replace(prefix, "");
// write line into second file
Run Code Online (Sandbox Code Playgroud)
问题是我没有足够的空间.
那么如何从我的文件中删除所有前缀呢?
当我尝试在我的gwt-maven Projekt上进行maven-install时,我得到此错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project MyProject: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] C:\Development\java jre7\..\lib\tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, …Run Code Online (Sandbox Code Playgroud) 我正在寻找管理我的maven项目版本的可能性.
我的maven项目中有一些maven模块,其中一些模块依赖于其他模块.
我想定义要为每个模块或依赖项全局使用的版本.
这有点可能吗?
就像是
globalVersion=2.0
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>${globalVersion}</version>
Run Code Online (Sandbox Code Playgroud)
但正如我所说,不是在每一个pom.我的意思是我的maven模块中的所有poms全局.
我目前面临的问题如下:
Exception in thread "main" javax.persistence.EntityExistsException: a different object with the same identifier value was already associated with the session: [de.entities.Genre#28]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1359)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1316)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:881)
at de.model.DatabaseBuilder.importData(DatabaseBuilder.java:87)
at de.main.Main.main(Main.java:55)
Run Code Online (Sandbox Code Playgroud)
所以异常告诉我我想插入两个具有相同主键 id 的不同对象。
我想要使用 JPA 插入数据库的所有数据都来自 XML 文件。我用 SAXParser 解析这个文件。当然,id 为 28 的流派条目有很多,因为许多电影都有相同的流派。
如果我使用自动生成的 id,数据将不再正确,因为所有 id 均由 XML 文件正确给出。
我怎么解决这个问题?为什么 JPA 不只是忽略这个对象已经存在于数据库中的事实,而只是将电影的 ID 和流派插入到我的 m:n 表中?
我的GWT Projekt中有一个CellTable,每行都有一个CheckBox.不知何故,我需要迭代cellTable中的所有行,并需要检查是否选中了每行的CheckBox.
我不知道该怎么做,我无法找到任何显示如何.
private Column<Article, Boolean> showPinColumn = new Column<Article, Boolean>(new CheckboxCell()) {
public Boolean getValue(Article object) {
return false;
}
};
Run Code Online (Sandbox Code Playgroud) 我想使用select来验证我的用户名.如果用户名已存在于数据库中,则验证失败.
我找到了像这样的primefaces的一些注释,例如:
@Size(min=2,max=5)
private String name;
Run Code Online (Sandbox Code Playgroud)
我没有找到这样的注释解决方案:
try {
dao.findUserByUserName(userName);
message = new FacesMessage ("Invalid username!", "Username Validation Error");
message.setDetail("Username already exists!");
message.setSeverity(FacesMessage.SEVERITY_ERROR);
throw new ValidatorException(message);
} catch (NoSuchUserException e) {}
Run Code Online (Sandbox Code Playgroud)
我是否必须使用自定义验证器或是否有注释?
我有一个这样的SQL语句:
INSERT INTO TABLE_3(TABLE_1ID, TABLE_2ID)
SELECT ID FROM TABLE_1 WHERE NAME = '..',
SELECT ID FROM TABLE_2 WHERE NAME = '..';
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我刚收到一个错误
声明...靠近"SELECT":语法错误.
那么如何正确地做到这一点?没有示例如何使用来自两个不同表的两个选项来处理此问题.
这可行:
INSERT INTO TABLE_1(NAME, AGE)
SELECT NAME, AGE FROM TABLE_2 WHERE ID = '..';
Run Code Online (Sandbox Code Playgroud)