[jboss-user] [JBoss Seam] - Re: Challenge: Simple Example Adding Records With Lookup Dro
johnurban
do-not-reply at jboss.com
Wed Nov 1 12:15:40 EST 2006
I was able to get the example working after closely following your example Mr. Muir. Thank you.
In your example you have Client and ClientType POJO's. My next hurdle is getting the Client object to persist from a JSF. Is there an example already out there showing how to persist an object that has a dropdown/lookup, reference as an @ManyToOne?
My JSF seems to pass validation, however I keep getting
"unable to access entity manager"
as a return message in my JSF. No exceptions come up the stack trace and the action event never gets called. So, some magic is happening between jsf submit and RoomServiceBean.
JSF
| <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
| <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
|
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
| <f:view>
| <f:loadBundle basename="messages" var="msg"/>
| <head>
| <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
| <title>
| <h:outputText value="#{msg.Create} #{msg.Person}" rendered="#{roomService.new}"/>
| </title>
| <style type="text/css" media="all">
| @import "style/default/screen.css";
| </style>
| </head>
| <body>
|
| <%@ include file="header.htm" %>
|
| <h:form>
|
| <div class="rvgFind">
| <fieldset class="rvgFieldSet">
| <legend><h:outputText value="#{msg.Person} #{msg.Attributes}"/></legend>
|
| <span class="rvgInputs">
| <span class="rvgMeassage"><h:messages globalOnly="false"/></span>
|
| <h:selectOneMenu value="#{person.room}" converter="org.jboss.seam.EntityConverter">
| <f:selectItems value="#{rooms}" />
| </h:selectOneMenu>
| <h:selectOneMenu value="#{person.organization}" converter="org.jboss.seam.EntityConverter">
| <f:selectItems value="#{organizations}" />
| </h:selectOneMenu>
|
| <h:outputLabel value="#{msg.Person_firstName}">
| <h:inputText value="#{person.firstName}" id="firstName"/>
| <span class="rvgMessage"><h:message for="firstName"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_middleName}">
| <h:inputText value="#{person.middleName}" id="middleName"/>
| <span class="rvgMessage"><h:message for="middleName"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_lastName}">
| <h:inputText value="#{person.lastName}" id="lastName"/>
| <span class="rvgMessage"><h:message for="lastName"/></span>
| </h:outputLabel>
|
| <h:outputLabel value="#{msg.Person_birthday}" for="birthday">
| <h:inputText value="#{person.birthday}" id="birthday">
| <f:convertDateTime type="date" dateStyle="short"/>
| </h:inputText>
| <span class="rvgMessage"><h:message for="birthday"/></span>
| </h:outputLabel>
|
| <h:outputLabel value="#{msg.Person_address1}" for="address1">
| <h:inputText value="#{person.address1}" id="address1"/>
| <span class="rvgMessage"><h:message for="address1"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_city}" for="city">
| <h:inputText value="#{person.city}" id="city"/>
| <span class="rvgMessage"><h:message for="city"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_state}" for="state">
| <h:inputText value="#{person.state}" id="state"/>
| <span class="rvgMessage"><h:message for="state"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_zip}" for="zip">
| <h:inputText value="#{person.zip}" id="zip"/>
| <span class="rvgMessage"><h:message for="zip"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_email}" for="email">
| <h:inputText value="#{person.email}" id="email"/>
| <span class="rvgMessage"><h:message for="email"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_sex}" for="sex">
| <h:inputText value="#{person.sex}" id="sex"/>
| <span class="rvgMessage"><h:message for="sex"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_homePhone}" for="homePhone">
| <h:inputText value="#{person.homePhone}" id="homePhone"/>
| <span class="rvgMessage"><h:message for="homePhone"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_workPhone}" for="workPhone">
| <h:inputText value="#{person.workPhone}" id="workPhone"/>
| <span class="rvgMessage"><h:message for="workPhone"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_beeperPhone}" for="beeperPhone">
| <h:inputText value="#{person.beeperPhone}" id="beeperPhone"/>
| <span class="rvgMessage"><h:message for="beeperPhone"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_cellPhone}" for="cellPhone">
| <h:inputText value="#{person.cellPhone}" id="cellPhone"/>
| <span class="rvgMessage"><h:message for="cellPhone"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_extraPhone}" for="extraPhone">
| <h:inputText value="#{person.extraPhone}" id="extraPhone"/>
| <span class="rvgMessage"><h:message for="extraPhone"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_extraPhoneMemo}" for="extraPhoneMemo">
| <h:inputText value="#{person.extraPhoneMemo}" id="extraPhoneMemo"/>
| <span class="rvgMessage"><h:message for="extraPhoneMemo"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_school}" for="school">
| <h:inputText value="#{person.school}" id="school"/>
| <span class="rvgMessage"><h:message for="school"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_schoolGrade}" for="schoolGrade">
| <h:inputText value="#{person.schoolGrade}" id="schoolGrade"/>
| <span class="rvgMessage"><h:message for="schoolGrade"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_contact}" for="contact">
| <h:inputText value="#{person.contact}" id="contact"/>
| <span class="rvgMessage"><h:message for="contact"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_parentName}" for="parentName">
| <h:inputText value="#{person.parentName}" id="parentName"/>
| <span class="rvgMessage"><h:message for="parentName"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_comments}" for="comments">
| <h:inputText value="#{person.comments}" id="comments"/>
| <span class="rvgMessage"><h:message for="comments"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_minsitry}" for="minsitry">
| <h:inputText value="#{person.minsitry}" id="minsitry"/>
| <span class="rvgMessage"><h:message for="minsitry"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_drama}" for="drama">
| <h:inputText value="#{person.drama}" id="drama"/>
| <span class="rvgMessage"><h:message for="drama"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_music}" for="music">
| <h:inputText value="#{person.music}" id="music"/>
| <span class="rvgMessage"><h:message for="music"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_status}" for="status">
| <h:inputText value="#{person.status}" id="status"/>
| <span class="rvgMessage"><h:message for="status"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_visitor}" for="visitor">
| <h:inputText value="#{person.visitor}" id="visitor"/>
| <span class="rvgMessage"><h:message for="visitor"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_mailList}" for="mailList">
| <h:inputText value="#{person.mailList}" id="mailList"/>
| <span class="rvgMessage"><h:message for="mailList"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_leader}" for="leader">
| <h:inputText value="#{person.leader}" id="leader"/>
| <span class="rvgMessage"><h:message for="leader"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_lastAttended}" for="lastAttended">
| <h:inputText value="#{person.lastAttended}" id="lastAttended">
| <f:convertDateTime type="date" dateStyle="short"/>
| </h:inputText>
| <span class="rvgMessage"><h:message for="lastAttended"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_created}" for="created">
| <h:inputText value="#{person.created}" id="created">
| <f:convertDateTime type="date" dateStyle="short"/>
| </h:inputText>
| <span class="rvgMessage"><h:message for="created"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_updated}" for="updated">
| <h:inputText value="#{person.updated}" id="updated">
| <f:convertDateTime type="date" dateStyle="short"/>
| </h:inputText>
| <span class="rvgMessage"><h:message for="updated"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_vcall}" for="vcall">
| <h:inputText value="#{person.vcall}" id="vcall"/>
| <span class="rvgMessage"><h:message for="vcall"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_vhouseCall}" for="vhouseCall">
| <h:inputText value="#{person.vhouseCall}" id="vhouseCall"/>
| <span class="rvgMessage"><h:message for="vhouseCall"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_team}" for="team">
| <h:inputText value="#{person.team}" id="team"/>
| <span class="rvgMessage"><h:message for="team"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_photoFile}" for="photoFile">
| <h:inputText value="#{person.photoFile}" id="photoFile"/>
| <span class="rvgMessage"><h:message for="photoFile"/></span>
| </h:outputLabel>
| <h:outputLabel value="#{msg.Person_uniqueId}" for="uniqueId">
| <h:inputText value="#{person.uniqueId}" id="uniqueId"/>
| <span class="rvgMessage"><h:message for="uniqueId"/></span>
| </h:outputLabel>
| </span>
|
|
|
| <span class="rvgActions">
| <h:commandButton type="submit" value="#{msg.Create}" action="#{roomService.addNewPerson}"/>
| </span>
|
| </fieldset>
| </div>
|
| </h:form>
|
| </body>
| </f:view>
| </html>
|
|
Person.java
| package testSeam;
|
| // Generated Sep 23, 2006 1:30:00 PM by Hibernate Tools 3.2.0.beta7
|
| import java.util.Date;
| import javax.persistence.Column;
| import javax.persistence.Entity;
| import javax.persistence.Id;
| import javax.persistence.Table;
| import javax.persistence.OneToOne;
| import javax.persistence.ManyToOne;
| import javax.persistence.JoinColumn;
| import javax.persistence.GeneratedValue;
|
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.annotations.Name;
| import static org.jboss.seam.ScopeType.SESSION;
|
| /**
| * Person generated by hbm2java
| */
| @Entity
| @Name("person")
| @Scope(SESSION)
| @Table(name = "person", catalog = "checkin", uniqueConstraints = {})
| public class Person implements java.io.Serializable {
|
| // Fields
|
| private int id;
|
| private Room room;
|
| private Organization organization;
|
| private String firstName;
|
| private String middleName;
|
| private String lastName;
|
| private String address1;
|
| private String city;
|
| private String state;
|
| private String zip;
|
| private String email;
|
| private Date birthday;
|
| private Long sex;
|
| private String homePhone;
|
| private String workPhone;
|
| private String beeperPhone;
|
| private String cellPhone;
|
| private String extraPhone;
|
| private String extraPhoneMemo;
|
| private String school;
|
| private String schoolGrade;
|
| private String contact;
|
| private String parentName;
|
| private String comments;
|
| private String minsitry;
|
| private Character drama;
|
| private Character music;
|
| private Long status;
|
| private Character visitor;
|
| private Character mailList;
|
| private Character leader;
|
| private Date lastAttended;
|
| private Date created;
|
| private Date updated;
|
| private Character vcall;
|
| private Character vhouseCall;
|
| private String team;
|
| private String photoFile;
|
| private String uniqueId;
|
| // Constructors
|
| /** default constructor */
| public Person() {
| System.out.println("Person Constructor called");
| }
|
| /** minimal constructor */
| /*
| public Person(int id, int roomId, int organizationId, String firstName) {
| System.out.println("Person Constructor called with 3 parms");
| this.id = id;
| this.roomId = roomId;
| this.organizationId = organizationId;
| this.firstName = firstName;
| }
| */
|
| /** full constructor */
| /*
| public Person(int id, int roomId, int organizationId, String firstName,
| String middleName, String lastName, String address1, String city,
| String state, String zip, String email, Date birthday, Long sex,
| String homePhone, String workPhone, String beeperPhone,
| String cellPhone, String extraPhone, String extraPhoneMemo,
| String school, String schoolGrade, String contact,
| String parentName, String comments, String minsitry,
| Character drama, Character music, Long status, Character visitor,
| Character mailList, Character leader, Date lastAttended,
| Date created, Date updated, Character vcall, Character vhouseCall,
| String team, String photoFile, String uniqueId) {
| System.out.println("Person Constructor called with ALL parms");
| this.id = id;
| this.roomId = roomId;
| this.organizationId = organizationId;
| this.firstName = firstName;
| this.middleName = middleName;
| this.lastName = lastName;
| this.address1 = address1;
| this.city = city;
| this.state = state;
| this.zip = zip;
| this.email = email;
| this.birthday = birthday;
| this.sex = sex;
| this.homePhone = homePhone;
| this.workPhone = workPhone;
| this.beeperPhone = beeperPhone;
| this.cellPhone = cellPhone;
| this.extraPhone = extraPhone;
| this.extraPhoneMemo = extraPhoneMemo;
| this.school = school;
| this.schoolGrade = schoolGrade;
| this.contact = contact;
| this.parentName = parentName;
| this.comments = comments;
| this.minsitry = minsitry;
| this.drama = drama;
| this.music = music;
| this.status = status;
| this.visitor = visitor;
| this.mailList = mailList;
| this.leader = leader;
| this.lastAttended = lastAttended;
| this.created = created;
| this.updated = updated;
| this.vcall = vcall;
| this.vhouseCall = vhouseCall;
| this.team = team;
| this.photoFile = photoFile;
| this.uniqueId = uniqueId;
| }
| */
|
| // Property accessors
| @Id
| @GeneratedValue
| public int getId() {
| System.out.println("Person.getId:"+id);
| return this.id;
| }
|
| public void setId(int id) {
| System.out.println("Person.setId:"+id);
| this.id = id;
| }
|
| @ManyToOne(optional=false)
| @JoinColumn(name="roomId")
| public Room getRoom() {
| System.out.println("Person.getRoom:"+room);
| return this.room;
| }
|
| public void setRoom(Room room) {
| System.out.println("Person.setRoom:"+room.getId());
| this.room = room;
| }
|
| @ManyToOne(optional=true)
| @JoinColumn(name="organizationId")
| public Organization getOrganization() {
| System.out.println("Person.getOrganization:"+organization);
| return organization;
| }
|
| public void setOrganization(Organization organization) {
| System.out.println("Person.setRoom:"+organization.getId());
| this.organization = organization;
| }
|
| @Column(name = "firstName", unique = false, nullable = false, insertable = true, updatable = true, length = 20)
| public String getFirstName() {
| System.out.println("Person.getFirstName:"+firstName);
| return this.firstName;
| }
|
| public void setFirstName(String firstName) {
| System.out.println("Person.setFirstName:"+firstName);
| this.firstName = firstName;
| }
|
| @Column(name = "middleName", unique = false, nullable = true, insertable = true, updatable = true, length = 20)
| public String getMiddleName() {
| System.out.println("Person.getMiddleName:"+middleName);
| return this.middleName;
| }
|
| public void setMiddleName(String middleName) {
| System.out.println("Person.setMiddleName:"+middleName);
| this.middleName = middleName;
| }
|
| @Column(name = "lastName", unique = false, nullable = true, insertable = true, updatable = true, length = 25)
| public String getLastName() {
| System.out.println("Person.getLastName:"+lastName);
| return this.lastName;
| }
|
| public void setLastName(String lastName) {
| System.out.println("Person.setLastName:"+lastName);
| this.lastName = lastName;
| }
|
| @Column(name = "Address1", unique = false, nullable = true, insertable = true, updatable = true, length = 90)
| public String getAddress1() {
| return this.address1;
| }
|
| public void setAddress1(String address1) {
| this.address1 = address1;
| }
|
| @Column(name = "City", unique = false, nullable = true, insertable = true, updatable = true, length = 15)
| public String getCity() {
| return this.city;
| }
|
| public void setCity(String city) {
| this.city = city;
| }
|
| @Column(name = "State", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
| public String getState() {
| return this.state;
| }
|
| public void setState(String state) {
| this.state = state;
| }
|
| @Column(name = "Zip", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
| public String getZip() {
| return this.zip;
| }
|
| public void setZip(String zip) {
| this.zip = zip;
| }
|
| @Column(name = "EMail", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
| public String getEmail() {
| return this.email;
| }
|
| public void setEmail(String email) {
| this.email = email;
| }
|
| @Column(name = "birthday", unique = false, nullable = true, insertable = true, updatable = true, length = 19)
| public Date getBirthday() {
| return this.birthday;
| }
|
| public void setBirthday(Date birthday) {
| this.birthday = birthday;
| }
|
| @Column(name = "Sex", unique = false, nullable = true, insertable = true, updatable = true, precision = 10, scale = 0)
| public Long getSex() {
| return this.sex;
| }
|
| public void setSex(Long sex) {
| this.sex = sex;
| }
|
| @Column(name = "HomePhone", unique = false, nullable = true, insertable = true, updatable = true, length = 15)
| public String getHomePhone() {
| return this.homePhone;
| }
|
| public void setHomePhone(String homePhone) {
| this.homePhone = homePhone;
| }
|
| @Column(name = "WorkPhone", unique = false, nullable = true, insertable = true, updatable = true, length = 15)
| public String getWorkPhone() {
| return this.workPhone;
| }
|
| public void setWorkPhone(String workPhone) {
| this.workPhone = workPhone;
| }
|
| @Column(name = "BeeperPhone", unique = false, nullable = true, insertable = true, updatable = true, length = 15)
| public String getBeeperPhone() {
| return this.beeperPhone;
| }
|
| public void setBeeperPhone(String beeperPhone) {
| this.beeperPhone = beeperPhone;
| }
|
| @Column(name = "CellPhone", unique = false, nullable = true, insertable = true, updatable = true, length = 15)
| public String getCellPhone() {
| return this.cellPhone;
| }
|
| public void setCellPhone(String cellPhone) {
| this.cellPhone = cellPhone;
| }
|
| @Column(name = "ExtraPhone", unique = false, nullable = true, insertable = true, updatable = true, length = 15)
| public String getExtraPhone() {
| return this.extraPhone;
| }
|
| public void setExtraPhone(String extraPhone) {
| this.extraPhone = extraPhone;
| }
|
| @Column(name = "ExtraPhoneMemo", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
| public String getExtraPhoneMemo() {
| return this.extraPhoneMemo;
| }
|
| public void setExtraPhoneMemo(String extraPhoneMemo) {
| this.extraPhoneMemo = extraPhoneMemo;
| }
|
| @Column(name = "School", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
| public String getSchool() {
| return this.school;
| }
|
| public void setSchool(String school) {
| this.school = school;
| }
|
| @Column(name = "SchoolGrade", unique = false, nullable = true, insertable = true, updatable = true, length = 2)
| public String getSchoolGrade() {
| return this.schoolGrade;
| }
|
| public void setSchoolGrade(String schoolGrade) {
| this.schoolGrade = schoolGrade;
| }
|
| @Column(name = "Contact", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
| public String getContact() {
| return this.contact;
| }
|
| public void setContact(String contact) {
| this.contact = contact;
| }
|
| @Column(name = "ParentName", unique = false, nullable = true, insertable = true, updatable = true, length = 75)
| public String getParentName() {
| return this.parentName;
| }
|
| public void setParentName(String parentName) {
| this.parentName = parentName;
| }
|
| @Column(name = "Comments", unique = false, nullable = true, insertable = true, updatable = true, length = 100)
| public String getComments() {
| return this.comments;
| }
|
| public void setComments(String comments) {
| this.comments = comments;
| }
|
| @Column(name = "Minsitry", unique = false, nullable = true, insertable = true, updatable = true, length = 60)
| public String getMinsitry() {
| return this.minsitry;
| }
|
| public void setMinsitry(String minsitry) {
| this.minsitry = minsitry;
| }
|
| @Column(name = "Drama", unique = false, nullable = true, insertable = true, updatable = true, length = 1)
| public Character getDrama() {
| return this.drama;
| }
|
| public void setDrama(Character drama) {
| this.drama = drama;
| }
|
| @Column(name = "Music", unique = false, nullable = true, insertable = true, updatable = true, length = 1)
| public Character getMusic() {
| return this.music;
| }
|
| public void setMusic(Character music) {
| this.music = music;
| }
|
| @Column(name = "Status", unique = false, nullable = true, insertable = true, updatable = true, precision = 10, scale = 0)
| public Long getStatus() {
| return this.status;
| }
|
| public void setStatus(Long status) {
| this.status = status;
| }
|
| @Column(name = "Visitor", unique = false, nullable = true, insertable = true, updatable = true, length = 1)
| public Character getVisitor() {
| return this.visitor;
| }
|
| public void setVisitor(Character visitor) {
| this.visitor = visitor;
| }
|
| @Column(name = "Mail_List", unique = false, nullable = true, insertable = true, updatable = true, length = 1)
| public Character getMailList() {
| return this.mailList;
| }
|
| public void setMailList(Character mailList) {
| this.mailList = mailList;
| }
|
| @Column(name = "Leader", unique = false, nullable = true, insertable = true, updatable = true, length = 1)
| public Character getLeader() {
| return this.leader;
| }
|
| public void setLeader(Character leader) {
| this.leader = leader;
| }
|
| @Column(name = "Last_Attended", unique = false, nullable = true, insertable = true, updatable = true, length = 19)
| public Date getLastAttended() {
| return this.lastAttended;
| }
|
| public void setLastAttended(Date lastAttended) {
| this.lastAttended = lastAttended;
| }
|
| @Column(name = "Created", unique = false, nullable = true, insertable = true, updatable = true, length = 19)
| public Date getCreated() {
| return this.created;
| }
|
| public void setCreated(Date created) {
| this.created = created;
| }
|
| @Column(name = "Updated", unique = false, nullable = true, insertable = true, updatable = true, length = 19)
| public Date getUpdated() {
| return this.updated;
| }
|
| public void setUpdated(Date updated) {
| this.updated = updated;
| }
|
| @Column(name = "VCall", unique = false, nullable = true, insertable = true, updatable = true, length = 1)
| public Character getVcall() {
| return this.vcall;
| }
|
| public void setVcall(Character vcall) {
| this.vcall = vcall;
| }
|
| @Column(name = "VHouseCall", unique = false, nullable = true, insertable = true, updatable = true, length = 1)
| public Character getVhouseCall() {
| return this.vhouseCall;
| }
|
| public void setVhouseCall(Character vhouseCall) {
| this.vhouseCall = vhouseCall;
| }
|
| @Column(name = "Team", unique = false, nullable = true, insertable = true, updatable = true, length = 17)
| public String getTeam() {
| return this.team;
| }
|
| public void setTeam(String team) {
| this.team = team;
| }
|
| @Column(name = "PhotoFile", unique = false, nullable = true, insertable = true, updatable = true, length = 75)
| public String getPhotoFile() {
| return this.photoFile;
| }
|
| public void setPhotoFile(String photoFile) {
| this.photoFile = photoFile;
| }
|
| @Column(name = "UniqueID", unique = false, nullable = true, insertable = true, updatable = true, length = 45)
| public String getUniqueId() {
| return this.uniqueId;
| }
|
| public void setUniqueId(String uniqueId) {
| this.uniqueId = uniqueId;
| }
|
| }
|
|
Room.java
| package testSeam;
|
| // Generated Oct 6, 2006 12:55:26 AM by Hibernate Tools 3.2.0.beta7
|
| import javax.persistence.Column;
| import javax.persistence.Entity;
| import javax.persistence.Id;
| import javax.persistence.Table;
|
| /**
| * Room generated by hbm2java
| */
| @Entity
| @Table(name = "room", catalog = "checkin", uniqueConstraints = {})
| public class Room implements java.io.Serializable {
|
| // Fields
|
| private int id;
|
| private String name;
|
| private int organizationId;
|
| private int capacity;
|
| // Constructors
|
| /** default constructor */
| public Room() {
| }
|
| /** full constructor */
| public Room(int id, String name, int organizationId, int capacity) {
| this.id = id;
| this.name = name;
| this.organizationId = organizationId;
| this.capacity = capacity;
| }
|
| // Property accessors
| @Id
| @Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true)
| public int getId() {
| return this.id;
| }
|
| public void setId(int id) {
| this.id = id;
| }
|
| @Column(name = "Name", unique = false, nullable = false, insertable = true, updatable = true, length = 50)
| public String getName() {
| return this.name;
| }
|
| public void setName(String name) {
| this.name = name;
| }
|
| @Column(name = "OrganizationID", unique = false, nullable = false, insertable = true, updatable = true)
| public int getOrganizationId() {
| return this.organizationId;
| }
|
| public void setOrganizationId(int organizationId) {
| this.organizationId = organizationId;
| }
|
| @Column(name = "Capacity", unique = false, nullable = false, insertable = true, updatable = true)
| public int getCapacity() {
| return this.capacity;
| }
|
| public void setCapacity(int capacity) {
| this.capacity = capacity;
| }
|
| }
|
|
Organization.java
| package testSeam;
|
| // Generated Sep 23, 2006 1:30:00 PM by Hibernate Tools 3.2.0.beta7
|
| import javax.persistence.Column;
| import javax.persistence.Entity;
| import javax.persistence.Id;
| import javax.persistence.Table;
|
| /**
| * Organization generated by hbm2java
| */
| @Entity
| @Table(name = "organization", catalog = "checkin", uniqueConstraints = {})
| public class Organization implements java.io.Serializable {
|
| // Fields
|
| private int id;
|
| private String name;
|
| private String address1;
|
| private String address2;
|
| private String city;
|
| private String state;
|
| private String zip;
|
| private String country;
|
| private String phone1;
|
| private String phone2;
|
| private String homepage;
|
| // Constructors
|
| /** default constructor */
| public Organization() {
| }
|
| /** full constructor */
| public Organization(int id, String name, String address1, String address2,
| String city, String state, String zip, String country,
| String phone1, String phone2, String homepage) {
| this.id = id;
| this.name = name;
| this.address1 = address1;
| this.address2 = address2;
| this.city = city;
| this.state = state;
| this.zip = zip;
| this.country = country;
| this.phone1 = phone1;
| this.phone2 = phone2;
| this.homepage = homepage;
| }
|
| // Property accessors
| @Id
| @Column(name = "id", unique = true, nullable = false, insertable = true, updatable = true)
| public int getId() {
| return this.id;
| }
|
| public void setId(int id) {
| this.id = id;
| }
|
| @Column(name = "name", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
| public String getName() {
| return this.name;
| }
|
| public void setName(String name) {
| this.name = name;
| }
|
| @Column(name = "address1", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
| public String getAddress1() {
| return this.address1;
| }
|
| public void setAddress1(String address1) {
| this.address1 = address1;
| }
|
| @Column(name = "address2", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
| public String getAddress2() {
| return this.address2;
| }
|
| public void setAddress2(String address2) {
| this.address2 = address2;
| }
|
| @Column(name = "city", unique = false, nullable = false, insertable = true, updatable = true, length = 45)
| public String getCity() {
| return this.city;
| }
|
| public void setCity(String city) {
| this.city = city;
| }
|
| @Column(name = "state", unique = false, nullable = false, insertable = true, updatable = true, length = 45)
| public String getState() {
| return this.state;
| }
|
| public void setState(String state) {
| this.state = state;
| }
|
| @Column(name = "zip", unique = false, nullable = false, insertable = true, updatable = true, length = 45)
| public String getZip() {
| return this.zip;
| }
|
| public void setZip(String zip) {
| this.zip = zip;
| }
|
| @Column(name = "country", unique = false, nullable = false, insertable = true, updatable = true, length = 45)
| public String getCountry() {
| return this.country;
| }
|
| public void setCountry(String country) {
| this.country = country;
| }
|
| @Column(name = "phone1", unique = false, nullable = false, insertable = true, updatable = true, length = 40)
| public String getPhone1() {
| return this.phone1;
| }
|
| public void setPhone1(String phone1) {
| this.phone1 = phone1;
| }
|
| @Column(name = "phone2", unique = false, nullable = false, insertable = true, updatable = true, length = 40)
| public String getPhone2() {
| return this.phone2;
| }
|
| public void setPhone2(String phone2) {
| this.phone2 = phone2;
| }
|
| @Column(name = "homepage", unique = false, nullable = false, insertable = true, updatable = true, length = 100)
| public String getHomepage() {
| return this.homepage;
| }
|
| public void setHomepage(String homepage) {
| this.homepage = homepage;
| }
| }
|
|
RoomServiceBean.java
| package testSeam;
|
| // Generated Oct 6, 2006 12:55:26 AM by Hibernate Tools 3.2.0.beta7
|
| import java.util.ArrayList;
| import java.util.Iterator;
| import java.util.Map;
| import java.util.List;
| import javax.ejb.Remove;
| import javax.ejb.Stateless;
| import javax.ejb.Stateful;
| import javax.ejb.TransactionAttribute;
| import static javax.ejb.TransactionAttributeType.NOT_SUPPORTED;
| import javax.faces.application.FacesMessage;
| import javax.faces.context.FacesContext;
| import javax.faces.model.SelectItem;
| import javax.interceptor.Interceptors;
| import javax.persistence.EntityManager;
|
| import org.jboss.seam.annotations.Begin;
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.End;
| import org.jboss.seam.annotations.IfInvalid;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Out;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.Outcome;
| import org.jboss.seam.annotations.Logger;
| import org.jboss.seam.annotations.Factory;
|
| import org.jboss.seam.ejb.SeamInterceptor;
| import org.jboss.seam.log.Log;
| import org.jboss.seam.selectitems.annotations.SelectItems;
|
| import org.hibernate.validator.Valid;
|
| @Name("roomService")
| @Stateless
| @Interceptors(SeamInterceptor.class)
| public class RoomServiceBean implements RoomService {
| @Logger
| private Log log;
|
| @In(create = true)
| private EntityManager entityManager;
|
| private Room room = new Room();
|
| @Valid
| private Person person;
|
| private String doneOutcome = "find";
|
| @In(required = false)
| private transient RoomFinder roomFinder;
|
| @In(create = true)
| private transient Map messages;
|
| private boolean isNew = true;
|
| @SelectItems(label="name", addNoSelectionLabel="Please select a room")
| private List<Room> rooms;
|
| @SelectItems(label="name", addNoSelectionLabel="Please select an organization")
| private List<Organization> organizations;
|
| @TransactionAttribute(NOT_SUPPORTED)
| public Person getPerson() {
| System.out.println("PersonEditorBean.getPerson|"+person);
| return person;
| }
|
| public void setPerson(Person person) {
| System.out.println("PersonEditorBean.setPerson|"+person);
| this.person = person;
| }
|
| @TransactionAttribute(NOT_SUPPORTED)
| public Room getRoom() {
| return room;
| }
|
| public void setRoom(Room room) {
| this.room = room;
| }
|
| @TransactionAttribute(NOT_SUPPORTED)
| public boolean isNew() {
| return isNew;
| }
|
| public void setNew(boolean isNew) {
| this.isNew = isNew;
| }
|
| public void setDoneOutcome(String outcome) {
| doneOutcome = outcome;
| }
|
| @SuppressWarnings("unchecked")
| @Factory("rooms")
| public void buildRooms() {
| log.info("top of buildRooms()");
| rooms = entityManager.createQuery("select rm from Room rm").getResultList();
| log.info("Room list has " + rooms.size() + " entries");
| }
|
| @SuppressWarnings("unchecked")
| @Factory("organizations")
| public void buildOrganizations() {
| log.info("top of buildOrganizations()");
| organizations = entityManager.createQuery("select org from Organization org").getResultList();
| log.info("Organization list has " + organizations.size() + " entries");
| }
|
| @Begin(join = true)
| @IfInvalid(outcome = Outcome.REDISPLAY)
| public String addNewPerson() {
| log.info("top of RoomServieBean.create()");
| log.info("person.firstName: "+person.getFirstName());
|
| if (entityManager.find(Person.class, person.getId()) != null) {
| FacesContext.getCurrentInstance().addMessage( null, new FacesMessage(messages.get("Person_id") + " " + messages.get("AlreadyExists")));
| return null;
| }
|
| entityManager.persist(person);
| isNew = false;
| refreshFinder();
| return "uQuickPersonAdd";
| }
|
| @IfInvalid(outcome = Outcome.REDISPLAY)
| public String update() {
| refreshFinder();
| return null;
| }
|
| @End(ifOutcome = "find")
| public String delete() {
| entityManager.remove(room);
| refreshFinder();
| return doneOutcome;
| }
|
| @End(ifOutcome = "find")
| public String done() {
| if (!isNew)
| entityManager.refresh(room);
| return doneOutcome;
| }
|
| private void refreshFinder() {
| if (roomFinder != null)
| roomFinder.refresh();
| }
| }
|
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3982416#3982416
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3982416
More information about the jboss-user
mailing list