[jboss-user] [JBoss Seam] - Re: Session-Variable in Conversation Context (or so...)
dschaedl
do-not-reply at jboss.com
Tue Jul 10 14:11:18 EDT 2007
It's exactly CRUD what I'd like to do.
I used Seam-gen to setup the project and to create my forms (originaly).
here us my current code (slightly simplified)
*** person.java ***
@Entity
@Name("person")
public class person implements Serializable {
private Long id;
private String name;
private String firstName;
@Id
@GeneratedValue
public Long getId() {..}
public void setId(Long id) {..}
@Length(min=3, max=120)
public String getName() {..}
public void setName(String name) {..}
public String getFirstName() {..}
public void setFirstName(String firstName) {..}
*** PersonManagerBean.java ***
@Stateful
@Scope(ScopeType.SESSION)
@Name("personManager")
public class PersonViewerBean implements PersonManager {
@Logger
private Log log;
@In(required=false)
@Out
private List personList;
@DataModel
private List personsDataModel;
@DataModelSelection
@Out(required=false)
private Person person;
@PersistenceContext(type=PersistenceContextType.EXTENDED)
private EntityManager em;
@Factory("personsDataModel")
public void findPersons() {
personsDataModel = em.createQuery("from Person r order by r.name desc").getResultList();
personList = personssDataModel;
}
@Remove @Destroy
public void destroy(){}
}
*** EditPersonBean ***
@Stateful
@Name("editperson")
public class EditpersonBean implements Editperson {
@Logger
private Log log;
@PersistenceContext(type=PersistenceContextType.EXTENDED)
private EntityManager em;
@In
FacesMessages facesMessages;
@In(required=false)
@Out
private Person person;
@In
@Out
private List personList;
@Begin
public void newPerson() {
person = new person();
}
@End
public void savePerson()
{
List existing = new ArrayList();
existing = em.createQuery("select name from Person where name=#{person.name}").getResultList();
if (existing == null || existing.size() == 0) {
em.persist(person);
personList.add(person);
}
else {
facesMessages.add("a person with this name already exists! (name=#{person.name})");
}
}
@End
public void updateperson()
{
em.persist(person);
}
@Begin
public void editperson(person r) {
this.person = em.merge(r);
}
public person getperson() { ..}
public void setperson(person person) {...}
@Remove @Destroy
public void destroy(){}
}
****** view.xhtml ******
...
<rich:panel>
<f:facet name="header">Welcome!</f:facet>
MY PERSON:
<h:outputText value="nothing to display" rendered="#{personsDataModel.rowCount==0}" />
<h:dataTable var="person" value="${personsDataModel}" rendered="#{personsDataModel.rowCount>0}">
<h:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:commandLink value="#{person.name}" action="#{personManager.select}" /> <!-- action does nothing -->
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Vorname" />
</f:facet>
<h:commandLink value="#{person.firstName}" action="#{personManager.select}" />
</h:column>
<h:column>
<s:link id="editperson" value="edit" action="#{editperson.editPerson(person)}" />
</h:column>
</h:dataTable>
<h:commandButton value="refresh" action="#{personManager.findPersons}" />
<h:commandButton value="new entry" action="#{editperson.newPerson}" />
<h3><h:outputText value="#{rower.email}" /></h3>
</rich:Panel>
...
***** edit.xhtml ****
....
<rich:panel>
<f:facet name="header">editPerson</f:facet>
<s:decorate id="firstnameDecoration" template="layout/edit.xhtml">
<ui:define name="label">Vorname</ui:define>
<h:inputText id="firstname" required="false" value="#{person.firstName}" />
</s:decorate>
<s:decorate id="nameDecoration" template="layout/edit.xhtml">
<ui:define name="label">Name</ui:define>
<h:inputText id="name" required="true" value="#{person.name}"/>
</s:decorate>
...
***************************
Logging, Comments, some other stuff was left out.
when pressing the 'new' or 'edit' Button a new conversation starts and my List (personList) is copied into the conversation-context. At the end of the conversation I'd like to copy it back to the Session.personList.
How? possible? did I missunderstand something?
thanks
Daniel
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4062623#4062623
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4062623
More information about the jboss-user
mailing list