0 Replies Latest reply on Oct 19, 2010 4:49 PM by Matthew Hibberd

    Editing object in data table using modal panel

    Matthew Hibberd Newbie

      I have a rich data table defined as follows:

      <rich:dataTable id="logEventList" var="logEvent" value="#{logEventList.resultList}" rendered="#{not empty logEventList.resultList}">

      On of the columns is a link to view comments associated with a log event. This pops up a modal dialog as follows:

      <rich:column styleClass="action">
           <f:facet name="header">Comments</f:facet>
           <a4j:commandLink ajaxSingle="true" oncomplete="Richfaces.showModalPanel('commentsModal');" value="Show Comments">
                <f:setPropertyActionListener target="#{commentHome.logEvent}" value="#{logEvent}" />

      The modal dialog is defined as:

      <rich:modalPanel id="commentsModal" width="320" height="220">
           <f:facet name="header">
                     <h:outputText value="Comments"></h:outputText>
           <f:facet name="controls">
                     <h:graphicImage value="/img/close.png" style="cursor:pointer" onclick="Richfaces.hideModalPanel('commentsModal')" />
                <h:panelGrid columns="1">
                     <a4j:outputPanel ajaxRendered="true">
                          <rich:dataTable id="commentList" var="comment" value="#{commentHome.logEvent.comments}">
                               <rich:column styleClass="action">
                                 <f:facet name="header">Comment</f:facet>
                                 <h:outputText value="#{comment.comment}" />
                             <rich:column styleClass="action">
                                 <f:facet name="header">Created</f:facet>
                                 <h:outputText value="#{comment.created}">
                                      <s:convertDateTime type="both" dateStyle="short"/>
                             <rich:column styleClass="action">
                                 <f:facet name="header">User</f:facet>
                                 <h:outputText value="#{comment.user.name}" />
                          <h:inputText value="#{commentHome.instance.comment}" />
                          <a4j:commandButton value="Add Comment" action="#{commentHome.persist}" reRender="commentsModal" />

      Code for CommentHome:

      public class CommentHome extends EntityHome<Comment>
           private static final long serialVersionUID = -4730594523236501903L;
           @In(scope = ScopeType.SESSION)
           private User user;
           private LogEvent logEvent;
           protected Comment createInstance() {
                final Comment comment = new Comment();
                return comment;
           public final LogEvent getLogEvent() {
                return logEvent;
           public final void setLogEvent(LogEvent logEvent) {
                this.logEvent = logEvent;

      For each log event that i click in the table, the comments show in the modal dialog correctly and for the correct log event. The problem I'm having is creating a new comment using the input text on the modal dialog. At the point where createInstance() and persist() are called, the logEvent is null. Can anyone help me figure out how to 'remember' the log event is selected in the table to apply to the newly created comment? I've tried
      a few things with conversations, but I must be missing something pretty obvious here.