[jboss-user] [JBoss Seam] - Re: problem with conversations
Kruno
do-not-reply at jboss.com
Thu Jul 5 10:13:03 EDT 2007
I was a bit lost in your example:
here is on of mine :
pages.xml:
|
| <page view-id="/page.jsp" >
| <begin-conversation join="true"/>
| </page>
|
RegisterAction
| package orka.test;
|
| import javax.ejb.Remove;
| import javax.ejb.Stateful;
| import javax.persistence.EntityManager;
| import javax.persistence.PersistenceContext;
|
| import org.jboss.seam.ScopeType;
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Scope;
|
| @Stateful
| @Scope(ScopeType.CONVERSATION)
| @Name("register")
| public class RegisterAction implements Register {
|
| @PersistenceContext
| private EntityManager em;
|
| @In
| User user;
|
|
| public String reg(){
| System.err.println(user.getName());
| // check for errors
| // then persist
| //em.persist(user);
|
| return "ok";
|
| }
| @Remove @Destroy
| public void destroy(){
|
| }
|
| }
|
user class I belive that this is much better way if you divide data form actions
| package orka.test;
|
| import org.jboss.seam.ScopeType;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Scope;
|
| // make him an entity so you can persist him
| @Name("user")
| @Scope(ScopeType.CONVERSATION)
| public class User {
|
| private String name;
|
| public String getName() {
| return name;
| }
|
| public void setName(String name) {
| this.name = name;
| }
|
|
|
|
| }
|
and jsp page
|
| <%@ page contentType="text/html; charset=UTF-8" %>
| <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
| <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
| <%@ taglib uri="http://jboss.com/products/seam/taglib" prefix="s"%>
|
|
| <f:view>
| <h:form id="forma">
|
| <h:inputText value="#{user.name}"></h:inputText>
|
| <h:commandButton action="#{register.reg}" value="register" />
|
|
|
| </h:form>
| </f:view>
|
every time you come to page it will be a new conversation because user entity is conversation scope and it is empty, but when you submit it is not new conversation. I think that is what you want
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4060837#4060837
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4060837
More information about the jboss-user
mailing list