This content has been marked as final.
Show 3 replies
-
1. Re: Showing updated entity on postback
hstang Dec 27, 2006 6:19 PM (in response to nbhatia)Hi,
I'm not familiar with seam-gen code. But can you provide the rendered page source, as well as your entity + action source.
It does appear that the new child is added fine, but just not rendering ? -
2. Re: Showing updated entity on postback
norman.richards Dec 27, 2006 9:56 PM (in response to nbhatia)Do you add the new the new Post to the Thread? (thread.addPost(newPost), or something to that effect?)
-
3. Re: Showing updated entity on postback
nbhatia Dec 28, 2006 12:39 AM (in response to nbhatia)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(); } }