我已经开始学习JSF,但遗憾的是,大多数教程只提供登录或注册部分.
你能指点我一些更深入的例子吗?我感兴趣的一件事是一个展示产品清单的页面.我在页面回家,我按下页面产品,以便我可以看到添加的最新产品.每次访问该页面时,都会根据数据库中的最新条目创建产品列表.我怎么处理这个?
解决此问题的一种方法是创建一个会话范围的托管bean,在其中我将通过其他托管bean更新不同的实体.我在一些教程中发现了这种方法,但它看起来很困难而且很笨拙.
哪个是解决这类问题的最佳方法?在两页主从细节用户界面中,会话范围的正确用法是什么?
我正在开发一个使用Struts 1.3的小项目,我遇到了以下问题.
在一些业务逻辑发生之后,Action我想将控件转发给映射到的另一个Action struts-config.xml.
通常这是我解决这个问题的方式:
struts-config.xml中
<action path="/boardCreate" type="com.example.BoardCreateAction" name="BoardCreateForm" input="/board.jsp">
<forward name="success" path="/board.do" redirect="true" />
</action>
Run Code Online (Sandbox Code Playgroud)
Java动作类
return mapping.findForward("success");
Run Code Online (Sandbox Code Playgroud)
这将重定向到board.do也映射到那里的动作.
我的问题是我想将控件重定向到:
<forward name="success" path="/board.do?id=1" redirect="true" />
Run Code Online (Sandbox Code Playgroud)
注意id = 1参数.除了重建我自己的行动之外,这是否还有其他任何方式?我找不到任何辩论此事的文件.谢谢!
实体:
@Entity
@Table(name="user_account")
public class UserAccount implements Serializable{
private static final long serialVersionUID = -2606506548742732094L;
@Id
@GeneratedValue(strategy=GenerationType.TABLE)
private Integer id;
Run Code Online (Sandbox Code Playgroud)
persistence.xml中
<persistence-unit name="Maze" transaction-type="RESOURCE_LOCAL">
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/mazedb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
</properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
错误
WARNING: #{accountController.performLogin}: java.lang.IllegalArgumentException: No [EntityType] was found for the key class [com.maze.model.UserAccount] in the Metamodel - please verify that the [Entity] class was referenced in persistence.xml using a specific <class>com.maze.model.UserAccount</class> property or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element.
javax.faces.FacesException: #{accountController.performLogin}: java.lang.IllegalArgumentException: …Run Code Online (Sandbox Code Playgroud) 将JPA与EclipseLink实现一起使用.
码:
try{
if(!em.getTransaction().isActive())
em.getTransaction().begin();
System.out.println(2);
em.persist(currentUser);
System.out.println(3);
if (em.getTransaction().isActive()){
System.out.println("IS ACTIVE");
} else {
System.out.println("NO ACTIVE");
}
em.getTransaction().commit();
System.out.println(4);
} catch (Exception e){
completed = false;
em.getTransaction().rollback();
System.out.println("ERROR: " + e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
错误:
INFO: persistOne - Enter
INFO: 2
INFO: 3
INFO: IS ACTIVE
INFO: [EL Warning]: 2012-01-06 14:45:59.221--UnitOfWork(12492659)--java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: com.maze.model.UserDetail@d52ea.
WARNING: #{accountController.performRegister}: java.lang.IllegalStateException:
Exception Description: No transaction is currently active
javax.faces.FacesException: #{accountController.performRegister}: java.lang.IllegalStateException: …Run Code Online (Sandbox Code Playgroud) 数据库:
user_account
id(pk)
email
password
...
user_detail
id(pk fk)
name_first
name_last
...
Run Code Online (Sandbox Code Playgroud)
实体
@Entity
@Table(name="user_account")
@SecondaryTable(name="user_detail", pkJoinColumns=@PrimaryKeyJoinColumn())
public class UserAccount implements Serializable{
private static final long serialVersionUID = -2606506548742732094L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
private String email;
private String password;
private String tab;
private String shortcut;
private String setting;
private Integer role;
@Column(table="user_detail", name="name_first")
private String nameFirst;
@Column(table="user_detail", name="name_last")
private String nameLast;
@Column(table="user_detail")
private String occupation;
@Column(table="user_detail")
@Temporal(TemporalType.DATE)
private Date birth;
....
}
Run Code Online (Sandbox Code Playgroud)
行动
try{
EntityTransaction transaction = em.getTransaction();
transaction.begin(); …Run Code Online (Sandbox Code Playgroud) resp.sendRedirect("/myurl");
req.getSession().setAttribute("foo", "bar");
Run Code Online (Sandbox Code Playgroud)
在这种情况下,重定向后是否可以访问foo属性?一般来说,servlet在重定向之前完全执行,或者在重定向行之后停止执行?
谢谢
我正在尝试实现一个用户名列表,可以通过单击UP或DOWN链接重新排列.
<ul>
<ui:repeat var="user" value="#{cc.attrs.value}">
<li>
#{user.name}
<h:link outcome = "user" value = "left" onclick="#{accountController.moveDown}">
<f:param name="id" value = "${user.id}" />
</h:link>
</li>
</ui:repeat>
</ul>
Run Code Online (Sandbox Code Playgroud)
这里的问题是我似乎没有正确使用onclick属性.这样做的正确方法是什么?
编辑:根据您的建议,我将所有链接放在一个表单中:
<h:form>
<ui:repeat value="#{cc.attrs.value}" var = "user">
<div class = "user">
<h:commandLink id = "Link1" value = "Up" binding = "#{accountController.ommandLink}" action = "#{accountController.moveUserUp}">
<f:attribute name = "userId" value = "#{user.id}" />
</h:commandLink>
<h:commandLink id = "Link2" value = "Down" binding = "#{accountController.commandLink}" action = "#{accountController.moveUserDown}">
<f:attribute name = …Run Code Online (Sandbox Code Playgroud) 我有这个简单的代码:
DateTime date = new DateTime(dateValue);
DateTime currentDate = new DateTime(System.currentTimeMillis());
System.out.println("date: " + date.toString());
System.out.println("currentDate: " + currentDate.toString());
Period period = new Period(currentDate, date);
System.out.println("PERIOD MINUTES: " + period.getMinutes());
System.out.println("PERIOD DAYS: " + period.getDays());
Duration duration = new Duration(currentDate, date);
System.out.println("DURATION MINUTES: " + duration.getStandardMinutes());
System.out.println("DURATION DAYS: " + duration.getStandardDays());
Run Code Online (Sandbox Code Playgroud)
我想简单地找出两个随机日期之间的天数和分钟数.
这是这段代码的输出:
date: 2012-02-09T00:00:00.000+02:00
currentDate: 2012-02-09T18:15:40.739+02:00
PERIOD MINUTES: -15
PERIOD DAYS: 0
DURATION MINUTES: -1095
DURATION DAYS: 0
Run Code Online (Sandbox Code Playgroud)
我猜我做错了什么,我只是看不出来.
我想使用Eclipse IDE在Windows 7上使用C测试openMP.我无法找到设置openMP的任何特定步骤.你能帮助我吗?
我正在尝试[br]用<br />Java String 替换它.
someText.replaceAll("\\[br\\]","<br />");
Run Code Online (Sandbox Code Playgroud)
这根本不起作用.我尝试删除反斜杠,但我得到了相同的结果.
我正在使用JSF2和Glassfish 3.0.
我有一个非常简单的应用程序,我正在尝试设置一些默认错误页面404和500错误.
这是WEB.XML部分:
<error-page>
<exception-type>404</exception-type>
<location>/error.xhtml</location>
</error-page>
<error-page>
<exception-type>500</exception-type>
<location>/error.xhtml</location>
</error-page>
Run Code Online (Sandbox Code Playgroud)
即使error.xhtml存在,在浏览器中我仍然得到标准HTTP Status 404 -警告.