1
votes

I have primefaces dataTable whose rows I would like to edit. I do submit the Id for the row and display the values in a panel to be edited. Using the same object, if I print out the values using h:outputText, I see the values. p:inputText does not show the value. If I refresh the page using the browser reload button, form value shows up just fine. Below is the condensed version of my code.

Model

@Entity
@Table(name = "TICKET")
public class Ticket extends AuditTrail implements Serializable 
{
    private static final long serialVersionUID = 1L;

    private static Logger log = Logger.getLogger(Ticket.class);

    @Id
    @SequenceGenerator(name = "TICKET_TICKETID_GENERATOR", sequenceName = "TICKET_SEQ")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "TICKET_TICKETID_GENERATOR")
    @Column(name = "TICKET_ID", unique = true, nullable = false, precision = 0)
    private Long ticketId;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "ticket")
    @OrderBy(clause = "createdBy")
    private Set<Comment> comments = new LinkedHashSet<Comment>(0);
}

@Entity
@Table(name = "COMMENT_LOG")
public class Comment extends AuditTrail implements java.io.Serializable {

    // Fields

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "COMMENT_LOG_ID", unique = true, nullable = false, precision = 0)
    @SequenceGenerator(name = "COMMENT_COMMENTID_GENERATOR", sequenceName = "COMMENT_SEQ")
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "COMMENT_COMMENTID_GENERATOR")
    private Long commentId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "TICKET_ID")
    private Ticket ticket;

    @Column(name = "COMMENT1", nullable = false, length = 300)
    private String comment1;

}

Controller

@Named("ticketBean")
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class TicketBean implements Serializable
{
 private Ticket ticket = new Ticket();
 private Comment comment = new Comment();
 /**
   * getters & setters
       */
    public void editComment(long commentId) 
    {
        for (Comment editComment: ticket.getComment())
        {
            if ( editComment.getCommentId().longValue() == commentId)
            {
                this.comment = editComment;
                changeButtonValue("tabView:commentForm1:submitAddComment", "Save");             
                break;
            }
        }
    }
}

XHTML

   <h:form prependId="false" id="commentForm1">
    <p:panel id="panelComment">
    <h:outputText value="#{ticketBean.comment.comment1}"/>
    <p:inputTextarea styleClass="textarea" value="#{ticketBean.comment.comment1}" 
                        rows="4" 
                    cols="60"
                    maxlength="255" 
                    counter="counter2"
                    counterTemplate="{0} characters remaining." 
                    id="comment1"
                    required="true"
                    requiredMessage="Comment is required"/>
<br />
<h:outputText id="counter2" style="font-size:8pt;" />
<p:commandButton id="submitAddComment" value="Add" 
actionListener="#{ticketBean.addComment()}"
                                         ajax="true"
                                         style="font-size:11pt;" process="panelComment"
                                         update=":tabView:commentForm1" />

<p:dataTable id="ticketCommentsList" var="com"
         value="#{ticketBean.ticket.comments.toArray()}"
         paginator="true" dynamic="true" rows="10"
         paginatorPosition="bottom" lazy="true"
         paginatorAlwaysVisible="false" widgetVar="projTable"
         paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                                rowsPerPageTemplate="10,15,20" styleClass="prime-datatable">

    <p:column id="comment1" headerText="Comment">
            <h:outputText value="#{com.comment1}" />
        </p:column>                             
    <p:column>
       <f:facet name="header">Edit</f:facet>
    <p:commandLink  action="#{ticketBean.editComment(com.commentId)}"                                               
                        ajax="true" value="Edit" 
                        update=":tabView:commentForm1" 
                        immediate="true"/>
         </p:column>
    </p:dataTable>
</p:panel>  
</h:form>

why would <h:outputText value="#{ticketBean.comment.comment1}"/> print out the value but <p:inputTextarea value="#{ticketBean.comment.comment1}"/> not show the value?

Thanks for your help.

1
Why ajax=false and immediate=true?Leo
actually I had it as ajax=true. I was trying out to see if ajax=false would make any differenceuser3520171
I will answer my own question. Sees like I accidentally deleted the process="@this" that I had in the commandLink. <p:commandLink action="#ticketBean.editComment(com.commentId)}" ajax="true" value="Edit" process="@this" update=":tabView:commentForm1" immediate="true"/>user3520171

1 Answers

1
votes

Seems like I accidentally deleted the porcess="@this" I had in the commandLink

<p:commandLink  action="#ticketBean.editComment(com.commentId)}"                                                                                
            ajax="true" 
            value="Edit"                              
            process="@this" 
            update=":tabView:commentForm1" 
            immediate="true"/>