[jboss-user] [JBoss Seam] - Re: Adding/Persisting A Record Problem...
johnurban
do-not-reply at jboss.com
Sun Oct 22 11:07:01 EDT 2006
Getting closer. I removed the room dropdown lookup logic from the jsp and it complianed about calling personEdtor.poo. I changed it back to personEditor.create and it added the record. So it appears there is something that occurs when the dropdown room lookup logic is inserted in the jsf:
JSF:
| <h:selectOneMenu value="#{roomFinder.example}" converter="org.jboss.seam.EntityConverter">
| <f:selectItems value="#{roomListByOrganization}" />
| </h:selectOneMenu>
|
|
RoomFinderBean
| package testSeam;
|
| // Generated Oct 6, 2006 12:55:26 AM by Hibernate Tools 3.2.0.beta7
|
| import java.util.HashMap;
| import java.util.List;
| import java.util.ArrayList;
| import java.util.Iterator;
| import java.util.Map;
| import java.util.Map.Entry;
| import java.util.TreeMap;
| import javax.ejb.Remove;
| import javax.ejb.Stateful;
| import javax.interceptor.Interceptors;
| import javax.persistence.EntityManager;
| import javax.persistence.Query;
| import javax.faces.component.UISelectItems;
| import javax.faces.model.SelectItem;
| import org.jboss.seam.ScopeType;
| import org.jboss.seam.annotations.Destroy;
| import org.jboss.seam.annotations.In;
| import org.jboss.seam.annotations.Out;
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.RequestParameter;
| import org.jboss.seam.annotations.Scope;
| import org.jboss.seam.annotations.Factory;
|
| import org.jboss.seam.selectitems.annotations.*;
|
| import org.jboss.seam.annotations.datamodel.DataModel;
| import org.jboss.seam.annotations.datamodel.DataModelSelection;
| import org.jboss.seam.ejb.SeamInterceptor;
|
| @Name("roomFinder")
| @Stateful
| @Scope(ScopeType.SESSION)
| @Interceptors(SeamInterceptor.class)
| public class RoomFinderBean implements RoomFinder {
|
| @Out
| private Room example = new Room();
|
| public Room getExample() {
| return example;
| }
|
| @In(required=false)
| private Login login;
|
| private int pageNumber = 0;
| private int pageSize = 25;
|
| public void setPageSize(int size) {
| pageSize = size;
| }
|
| public int getPageSize() {
| return pageSize;
| }
|
| public boolean isPreviousPage() {
| return roomList != null && pageNumber > 0;
| }
|
| public boolean isNextPage() {
| return roomList != null && roomList.size() == pageSize;
| }
|
| @DataModel
| private List<Room> roomList;
|
| // @Out
| // @SelectItems(valueStrategy=SelectItems.Strategy.OBJECT, labelMethod="getname")
| // private List<Room> roomListByOrganization;
| @Out
| @SelectItems(label="name")
| private List<Room> roomListByOrganization;
|
| @DataModelSelection
| private Room selectedRoom;
|
| @In(create = true)
| private EntityManager entityManager;
|
| private void executeQuery() {
| Map<String, Object> parameters = new HashMap<String, Object>();
| StringBuffer queryString = new StringBuffer();
| if (example.getId() != 0) {
| queryString.append(" and room.id = :id");
| parameters.put("id", example.getId());
| }
| if (example.getName() != null && example.getName().length() > 0) {
| queryString.append(" and room.name like :name");
| parameters.put("name", '%' + example.getName() + '%');
| }
| if (example.getOrganizationId() != 0) {
| queryString.append(" and room.organizationId = :organizationId");
| parameters.put("organizationId", example.getOrganizationId());
| }
| if (example.getCapacity() != 0) {
| queryString.append(" and room.capacity = :capacity");
| parameters.put("capacity", example.getCapacity());
| }
| if (queryString.length() == 0) {
| queryString.append("select room from Room room");
| } else {
| queryString.delete(0, 4).insert(0,
| "select room from Room room where");
| }
|
| if (order != null) {
| queryString.append(" order by room.").append(order);
| if (descending)
| queryString.append(" desc");
| }
|
| Query query = entityManager.createQuery(queryString.toString());
| for (Entry<String, Object> param : parameters.entrySet()) {
| query.setParameter(param.getKey(), param.getValue());
| }
|
| roomList = (List<Room>) query.setMaxResults(pageSize).setFirstResult(
| pageSize * pageNumber).getResultList();
| }
|
| @SuppressWarnings("unchecked")
| @Factory("roomListByOrganization")
| public void getRoomListByOrganization() { // f:selectItems value
| Map<String, Object> parameters = new HashMap<String, Object>();
| StringBuffer queryString = new StringBuffer();
| Users loggedInUser = login.getInstance();
|
| queryString.append(" and room.organizationId = :organizationId");
| parameters.put("organizationId", loggedInUser.getOrganizationId());
|
| if (queryString.length() == 0) {
| queryString.append("select room from Room room");
| } else {
| queryString.delete(0, 4).insert(0,
| "select room from Room room where");
| }
|
| if (order != null) {
| queryString.append(" order by room.").append(order);
| if (descending)
| queryString.append(" desc");
| }
|
| Query query = entityManager.createQuery(queryString.toString());
| for (Entry<String, Object> param : parameters.entrySet()) {
| query.setParameter(param.getKey(), param.getValue());
| }
| roomListByOrganization = query.getResultList();
|
| List selectItems=new ArrayList();
| for (Iterator iterator = roomListByOrganization.iterator(); iterator.hasNext();)
| {
| Room value = (Room)iterator.next();
| SelectItem item = new SelectItem(value, value.getName());
| selectItems.add(item);
| }
|
| roomListByOrganization = selectItems;
|
| // return roomListByOrganization;
| }
|
| public String findFirstPage() {
| pageNumber = 0;
| executeQuery();
| return null;
| }
|
| public String findNextPage() {
| pageNumber++;
| executeQuery();
| return null;
| }
|
| public String findPreviousPage() {
| pageNumber--;
| executeQuery();
| return null;
| }
|
| public void refresh() {
| if (roomList != null)
| executeQuery();
| }
|
| public String clear() {
| roomList = null;
| example = new Room();
| return null;
| }
|
| public Room getSelection() {
| return entityManager.merge(selectedRoom);
| }
|
| @Destroy
| @Remove
| public void destroy() {
| }
|
| private String order;
|
| private boolean descending = false;
|
| @RequestParameter
| private String orderBy;
|
| public String reorder() {
| if (orderBy.equals(order)) {
| descending = !descending;
| } else {
| descending = false;
| }
| order = orderBy;
| executeQuery();
| return null;
| }
|
| }
|
What am I missing here?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3979898#3979898
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3979898
More information about the jboss-user
mailing list