0

I have a datatable with 3 rows. Each row is a text area. I want to auto save the contents in them. I tried using primefaces poll. Poll gets triggered only when process="@form" but then the content in the textarea does not get passed to the backing bean. And if I change process=":tabView:tab2form:table1", poll does not get triggered. Here is my code

    <p:dataTable id="table1" var="reportCommentary" value="#{managedBean.reportCommentaries}" >  
        <p:column headerText="Report Commentary Edit">
            <h:outputText value="Commentary:" />
            <p:inputTextarea id ="commentaryEditor" 
                             maxlength="#{managedBean.maxCommentaries}"      
                             value="#{reportCommentary}"
                             rows="20"
                             cols="100"
                             widgetVar="commentaryEditor" 
                             autoResize="false"
                             counter="counter"/>
           <h:outputText id="counter"/>
        </p:column>
    </p:dataTable>
    <p:poll interval="30" 
            listener="#{managedBean.onCellEdit}"
            partialSubmit="true" 
            process=":tabView:tab2form:table1"/>

And my backing bean (Session Scoped):

public void onCellEdit(){
     // it never comes here

}

Any help will be really appreciated.

ziMtyth
  • 1,008
  • 16
  • 32
anch
  • 1
  • 2

1 Answers1

0

Try This Basic Cell Editing in DataTable and Remove <p:poll> for this. Write editable="true" and editMode="cell" in <p:dataTable>

Java code :

public void onCellEdit(CellEditEvent event) {
//your code 
}

.xhtml code:

<p:dataTable id="table1" var="reportCommentary"
value="#{managedBean.reportCommentaries}"editable="true" editMode="cell">
<p:ajax event="cellEdit" listener="#{managedBean.onCellEdit}" />
                <p:column headerText="Report Commentary Edit">
                    <h:outputText value="Commentary:" />
<p:cellEditor>
                         <f:facet name="output">

<p:inputTextarea id ="commentaryEditor"
                        maxlength="#{managedBean.maxCommentaries}"      
                        value="#{reportCommentary}"
                        rows="20"
                        cols="100"
                        widgetVar="commentaryEditor" 
                       autoResize="false"
                       counter="counter"/>
 </f:facet>
  <f:facet name="input"> 
<p:inputTextarea id ="commentaryEditor"
                        maxlength="#{managedBean.maxCommentaries}"      
                        value="#{reportCommentary}"
                        rows="20"
                        cols="100"
                        widgetVar="commentaryEditor" 
                       autoResize="false"
                       counter="counter"/>
</f:facet>
                    </p:cellEditor>

                        <h:outputText id="counter"/>
                </p:column>
            </p:dataTable>
ArgaPK
  • 455
  • 1
  • 9
  • 22
  • Thank you for responding. But I have a few problems with this. 1. Th event will be called when the user clicks on enter which is not what I want. I want the entered data to be automatically saved every few seconds. 2. The event does not get the new value. I think it's because my managedbean is session scoped. – anch Sep 13 '17 at 15:34
  • @anch The event will definitely gets the new value. change your managed bean into View Scoped. – ArgaPK Sep 14 '17 at 11:52
  • yeah, I cannot do that. There are many other classes referring it which are also session scoped. It may mess up a few things. In any case, this event behavior is not exactly what I am looking for. – anch Sep 14 '17 at 17:46
  • This is not a scope issue, I think. I noticed primefaces poll working in SessionScope. https://stackoverflow.com/questions/28179687/sessionscoped-bean-instantiated-over-and-over. But this question is on primefaces 5.10 whereas I am using 5.2. Maybe that's where the problem lies. – anch Sep 15 '17 at 15:31
  • @anch Ok , i would like to suggest you to upgrade your primefaces version, PF 6.1 , it may then solve all the problems. – ArgaPK Sep 17 '17 at 12:47
  • Unfortunately, this is a legacy software that I am modifying so I cannot update the version. I have taken a different approach where I am fetching the component from the view map. I'll post my solution below. Thanks for your help. – anch Sep 18 '17 at 13:44