我已经使用Eclipse/Ant一段时间了,并决定看看Netbeans/Maven的JSF开发.一路上,我想我会尝试使用比我安装的更新的Mojarra版本glassfish/modules.我似乎无法让它工作,因为我是Maven和Netbeans的新手,我不确定它是否适用于那些或其他东西.
我做了一个非常简单的应用程序,它使用支持bean从索引页面打印出Mojarra版本:
Info.java:
@Named
@RequestScoped
public class Info
{
public String getVersion()
{
return FacesContext.class.getPackage().getImplementationVersion();
}
}
Run Code Online (Sandbox Code Playgroud)
index.xhtml:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:body>
<h:outputText value="The Mojarra version is #{info.version}" />
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我看到的页面内容
Mojarra版本是2.2.5
正如我所料(我把2.2.5的罐子放glassfish/modules回去了一段时间).然后,我在Mojarra网站上添加了对Mojarra 2.2.7的依赖:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.x</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
用"x"代替"7".生成的POM文件看起来像这样(大部分是来自Netbeans的样板文件):
POM.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>mavenproject1</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId> …Run Code Online (Sandbox Code Playgroud) 我正在尝试将同一个实体持久化到MySQL和Postgres数据库(这主要是为了识别任何不一致,并找出执行双写的任何问题的细节 - 我在这里遇到过).我发现的文章都描述了依赖于其他框架的解决方案.我正在尝试使用Glassfish 4.0开箱即用,JPA 2.1以及EclipseLink 2.5作为JPA提供程序来解决这个问题.我正在使用Eclipse,并意识到IDE不支持在persistence.xml文件中配置多个持久性单元,所以我正在为此直接编写XML.
我期待在代码中执行类似的操作(使用相同的方法):
@PersistenceContext(name = "MyAppMySQLPU")
EntityManager emMySQL;
@PersistenceContext(name = "MyAppPostgresPU")
EntityManager emPostgres;
//...etc...
MyThing thing = new MyThing();
//...etc...
emMySQL.persist(thing);
emPostgres.persist(thing);
Run Code Online (Sandbox Code Playgroud)
并使用persistence.xml包含以下内容的文件:
<persistence-unit name="MyAppPostgresPU">
<jta-data-source>jdbc/PostgresPool_test</jta-data-source>
<class>model.MyThing</class>
</persistence-unit>
<persistence-unit name="MyAppMySQLPU">
<jta-data-source>jdbc/MySQLPool_test</jta-data-source>
<class>model.MyThing</class>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我收到以下错误:
SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
SEVERE: Exception while preparing the app
SEVERE: Exception while preparing the app : Could not resolve a persistence unit corresponding to the persistence-context-ref-name [MyAppPostgresPU] in the scope of the module called [MyApp]. …Run Code Online (Sandbox Code Playgroud) 有没有办法使用JSF EL(Java EE 7)列出所有请求的标题名称和2列表中的相应值,而不引入支持bean?我可以这样做,如果我创建一个bean并从EL访问它,所以我确实有一个方法到最后 - 但我想弄清楚的是,它是否可以完全用"开箱即用"完成EL."这是不可能的"将是一个很好的答案 - 我还在学习.
我想是这样的:
<table>
<ui:repeat value="#{request.getHeaderNames()}" var="hdr">
<tr>
<td>#{hdr}</td>
<td>#{headerValues[hdr]}</td>
</tr>
</ui:repeat>
</table>
Run Code Online (Sandbox Code Playgroud)
但这给出了一个1行的表,如下所示:
org.apache.catalina.util.Enumerator@2dbf763b [Ljava.lang.String;@74eb32f3
Run Code Online (Sandbox Code Playgroud)
我怀疑因为request.getHeaderNames()给一个普查员而不是某种ui:repeat想要的列表,这种方法根本不起作用,我需要做一些根本不同的事情.