jsfprimefacesprimefaces-extensions

PrimeFaces Extension - pe:sheet not Updating on Change


I am unsure how one updates a pe:sheet without directly editing a cell. Currently, when I make a modification to a cell, the data in the underlying list is not modified, and when I modify the underlying list, the front end is not updated. How should I user sync these two?

Here is the HTML:

<script type="text/javascript">
    function sheetExtender() { 
       this.cfg.enterMoves = {row: 1, col: 0}; 
    }
</script>
<pe:sheet id="mySheet" widgetVar="mySheet" value="#{myView.objList}"
    var="obj" rowKey="#{obj.listIndex}" style="color: #757575;" height="400"
    showRowHeaders="true" sortOrder="ascending" width="1000" extender="sheetExtender">
    <p:ajax event="change" listener="#{myView.onChange}" update="mySheet"/>
    <pe:sheetcolumn headerText="X" value="#{obj.x}" colType="checkbox"/>
    <pe:sheetcolumn headerText="Y" value="#{obj.y}" />
    <pe:sheetcolumn headerText="Z" value="#{obj.z}" />
</pe:sheet>  

And the change handler:

public void onChange(SheetEvent event) {
    Sheet sheet = event.getSheet();
    List<SheetUpdate> updates = sheet.getUpdates();

    SheetUpdate sheetUpdate = updates.get(0);
    Integer rowId = (Integer) sheetUpdate.getRowKey();
    Integer colId = (Integer) sheetUpdate.getColIndex();
    String oldValue = (String) sheetUpdate.getOldValue();
    String newValue = (String) sheetUpdate.getNewValue();
    
    sheet.appendUpdateEvent(rowId, colId + 1, "DUMMY", null, "DUMMY");
    
    sheet.commitUpdates();
}

I cannot find any particular method or widget function to keep these two in sync. If you know the correct method to do this, please let me know how you found it.

Thanks!


Solution

  • @Gumpf you have everything correct...you can only edit cells from the UI front end.

    Changing the values in the backing bean will NOT reflect in the Sheet unless you update="sheet" to redraw the entire sheet again. The whole purpose of the Sheet is to not act like an Editable datatable where if you had a 10x10 editable DataTable it would submit 1000 values on Form Submit every time. If you had a 20x20 then it wouldn't work as Most servers stop you at 1000 Form Submit items.

    So the Sheet is designed just to update a cell or cells at a time to update your backing bean WITHOUT having to redraw the sheet. What you want to do by updating your backing bean values and have it reflect in the Sheet the only way that will work is update="sheet" to force the whole Sheet to re-render after updating your backing bean values which might not be what you want. Or it might be....