[jboss-user] [JBoss Seam] - Re: Stale Session Objects ? DataModelSelection Problems

kryptontri do-not-reply at jboss.com
Tue Jul 25 11:30:23 EDT 2006


Sorry about the bad formatting and being lazy. I am tying to provide
add/remove functionality through a page, where by there is a 1 to
many relationship. 

If I now take the messages example and modify it
to add messages (remove already exists) I cannot get this to work
properly, can anyone point me in the right direction or to an example
that does this ie managed relationships for objects?

In the view - messages.jsp I added (I tried make it format nice, but for some mysterious
reason it does not want to, i have previoued this severla times :-( )
anonymous wrote : 
  |  <!-- Added New Messages -->
  |  <h:form> 
  |      
  |        
  |           
  |              <h:outputLabel for="title">Title:</h:outputLabel>
  |           
  |           
  |               <h:inputText id="title" value="#{message.title}"/>
  |           
  |            
  |               <h:outputLabel for="text">Text:</h:outputLabel>
  |            
  |             
  |                <h:inputText id="text" value="#{message.text}"/>
  |             
  |         
  |             
  |                 
  |                     <h:commandButton value="Add Message" action="#{messageManager.addMessage}"/>
  |                 
  |             
  |         
  |     </h:form>
  |     <!-- End Add New Messages -->
  |  

For the MessageManager
anonymous wrote : 
  | @Local
  | public interface MessageManager
  | {
  |    public void findMessages();
  |    public void select();
  |    public void delete();
  |    public void destroy();
  |    public void addMessage();
  | }
  | 

For the MessageManagerBean
anonymous wrote : 
  | public class MessageManagerBean implements Serializable, MessageManager
  | {
  | 
  |    @DataModel
  |    private List messageList;
  |    
  |    @DataModelSelection
  |    @Out(required=false)
  |    private Message selectedMessage;
  | 
  |     // --- Added ----- //
  |    @In(required = false, create = true)
  |    @Out(required=false)
  |    private Message message;
  |    
  |    @PersistenceContext(type=EXTENDED)
  |    private EntityManager em;
  |    
  |    @Factory("messageList")
  |    public void findMessages()
  |    {
  |       messageList = em.createQuery("from Message msg order by msg.datetime desc").getResultList();
  |    }
  |    
  |    public void select()
  |    {
  |       selectedMessage.setRead(true);
  |    }
  | 
  |    public void delete()
  |    {
  |       messageList.remove(selectedMessage);
  |       em.remove(selectedMessage);
  |       message=null;
  |    }
  |    
  |    @Remove @Destroy
  |    public void destroy() {}
  | 
  |    // --- Added ----- //
  |    public void addMessage() {
  |     message.setRead(false);
  |     message.setDatetime(new Date());
  |     em.persist(message);
  |     messageList.add(message);
  |     //messageList = em.merge(messageList);
  |     message = null;
  |    }
  | 
  | }
  | 

Do you see where I am going wrong ? As it stands I can add 1 message, but then
I cannot add a second and the input box never gets cleared. 

I am after a clean example that adds/removes etc ? Any ideas ? TIA

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3960728#3960728

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3960728



More information about the jboss-user mailing list