0 Replies Latest reply on Oct 19, 2010 4:49 PM by matt.hibb

    Editing object in data table using modal panel

    matt.hibb

      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}" />
           </a4j:commandLink>
      </rich:column>



      The modal dialog is defined as:



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



      Code for CommentHome:



      @Name("commentHome")
      public class CommentHome extends EntityHome<Comment>
      {
           private static final long serialVersionUID = -4730594523236501903L;
           
           @In(scope = ScopeType.SESSION)
           private User user;
           private LogEvent logEvent;
           
           @Override
           protected Comment createInstance() {
                final Comment comment = new Comment();
                comment.setUser(user);
                comment.getLogEvents().add(logEvent);
                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.


      Thanks!