Results 1 to 1 of 1
  1. #1
    Lars is offline Member
    Join Date
    Feb 2013
    Posts
    1
    Rep Power
    0

    Default Conversation with SFSB

    In the past I implemented conversations using Servlets and manually adding / removing e.g. a Cart/Trolley object to the HttpSession object. Now I tried to implement it using JSF, Backing Bean and a Stateful EJB which is supposed to hold the data. However, that doesn work. The SFSB is created and destroyed for each request. It gives a "JBAS014101: Failed to find SFSB instance with session ID ... in cache" and later on a NPE.

    How is that possible? The Backing Bean is conversationScoped and the SFSB dependant since otherwise the @Remove-method couldn't be called.

    How would I implement a conversation using a SFSB? I attach the project code to this post (e.g. a "mvn clean install jboss-as:deploy" will deploy it to jboss)

    Backing Bean

    Java Code:
    @Named("bookingBean")
    @ConversationScoped
    public class BookingBean implements Serializable {
    
    	private static final long serialVersionUID = 4961548908512317407L;
    	
    	@Inject Conversation conversation;
    	@Inject Trolley trolley;
    	List<TableData> tableDataList = null;
    
    	@PostConstruct
    	public void init() {
    		tableDataList = new ArrayList<TableData>();
    		tableDataList.add(new TableData("table","12345"));
    		[...]
    	}
    
    	public List<TableData> getTableData() {
    		return tableDataList;
    	}
    
    	public List<TableData> getTrolleyContent() {
    		List<TableData> retList = new ArrayList<TableData>();
    		for (Map.Entry<String, String> entry : trolley.getOrderMap().entrySet()) {
    			retList.add(new TableData(entry.getKey(), entry.getValue()));
    		}
    		return retList;
    	}
    
    	public String updateOrder(TableData tableData) {
    		if (conversation.isTransient()) {
    			conversation.begin();
    		}
    		trolley.updateTrolley(tableData);
    		return null;
    	}
    
    	public void cancel() {
    		trolley.cancelOrder();
    		if (!conversation.isTransient()) {
    			conversation.end();
    		}
    	}
    
    	public String submit() {
    		trolley.orderInfoMaterial();
    		if (!conversation.isTransient()) {
    			conversation.end();
    		}
    		return null;
    	}
    }
    Trolley
    Java Code:
    @Stateful
    @Dependent
    public class Trolley {
    
    	Map<String, String> orderMap = null;
    	
    	@PostConstruct
    	public void initMap() {
    		orderMap = new HashMap<String, String>();
    	}
    	
    	@PreDestroy
        public void cleanup(){
        	logger.info("Trolley object destroyed");
        }
    
    	public void updateTrolley(TableData tableData) {
    		orderMap.put(tableData.getName(), tableData.getNumber());
    	}
    
    	public Map<String, String> getOrderMap() {
    		return orderMap;
    	}
    
    	@Remove
    	public void orderInfoMaterial() {
    		logger.info("Submitting order");
    	}
    }
    Attached Files Attached Files
    Last edited by Lars; 02-26-2013 at 04:24 PM. Reason: A lot of blank lines have been entered by default. Edited to remove them.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •