Correct - the child is added fine, but the rendered page does not show the 
newly added child. The reason is that the Thread and Posts are fetched from the 
database during the Apply Request Values phase, and only later in the Invoke 
Application phase the new Post is inserted.

Here's the source for the rendered page - Thread.xhtml:


  | <body>
  | <ui:composition template="/layout/template.xhtml">
  | 
  |     <ui:define name="body">
  | 
  |         <div id="PageSubtitle">Thread</div>
  | 
  |         <h:messages globalOnly="true" styleClass="message" 
id="globalMessages"/>
  |     
  |         <div id="List">
  |             <h2>#{threadHome.instance.title}</h2>
  | 
  |             <h:outputText value="No posts" rendered="#{empty 
threadHome.posts}"/>
  |         
  |             <div class="Post">
  |                 <ui:repeat value="#{threadHome.posts}" var="post" 
rendered="#{not empty threadHome.posts}">
  |                     <div class="Body">#{post.body}</div>
  |                 </ui:repeat>
  |             </div>
  |         </div>
  | 
  |     <h:form>
  |         <div class="NewPost">
  |             <div class="Post" >
  |                 <div class="Body">
  |                     <h:inputTextarea id="body"
  |                                     rows="4"
  |                                     cols="20"
  |                                 required="true"
  |                                    value="#{postHome.instance.body}"/>
  |                 </div>
  |             </div>
  |         </div>
  | 
  |         <div class="Info">
  |             <h:commandButton id="save" 
  |                           value="Post Reply"
  |                          action="#{postHome.persist}"
  |                      styleClass="Button" />  
  |         </div>
  |     </h:form>
  | 
  | 
  | </ui:define>
  | 
  | </ui:composition>
  | </body>
  | 

This is ThreadHome:


  | @Name("threadHome")
  | public class ThreadHome extends EntityHome<Thread> {
  | 
  |     @In(value = "#{forumHome.instance}", required = false)
  |     Forum forum;
  | 
  |     public void setThreadId(Long id) {
  |             setId(id);
  |     }
  | 
  |     public Long getThreadId() {
  |             return (Long) getId();
  |     }
  | 
  |     @Override
  |     protected Thread createInstance() {
  |             Thread result = new Thread();
  |             result.setForum(forum);
  |             return result;
  |     }
  | 
  |     public List<Post> getPosts() {
  |             return getInstance() == null ? null : new 
ArrayList<Post>(getInstance()
  |                             .getPosts());
  |     }
  | 
  | }
  | 

and finally here's PostHome, which contains the persist action which is called 
from Thread.xhtml.


  | @Name("postHome")
  | public class PostHome extends EntityHome<Post> {
  | 
  |     @In(value = "#{threadHome.instance}", required = false)
  |     Thread thread;
  | 
  |     public void setPostId(Long id) {
  |             setId(id);
  |     }
  | 
  |     public Long getPostId() {
  |             return (Long) getId();
  |     }
  | 
  |     @Override
  |     protected Post createInstance() {
  |             Post result = new Post();
  |             result.setThread(thread);
  |             return result;
  |     }
  | 
  |     @Override
  |     public String persist() {
  |         if (this.instance.getDateCreated() == null) {
  |             this.instance.setDateCreated(new java.util.Date());
  |         }
  |         return super.persist();
  |     }
  | }
  | 

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

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3996574
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to