You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Jaroslav Rychna <ja...@centrum.cz> on 2005/08/23 09:16:02 UTC

dataTable and columns doesn't update my model

Hi, 
I use dataTable and columns to create dynamic table. I use the code which is in examples, but when I edit values in table, these values doesn't propagate into my model.

What i want to do is this:
1. when I visit the page, the table shows and I can change the input texts in it
2. then I press button, which is bound to action setMezery in my bean
3. in method setMezery I want see changed values

What I'm doing wrong? I spend many hours on it with no progress.

Thanks for help,
jarin

Here is my code in jsp:

<x:dataTable var="tabulka" value="#{modelH.radky}" preserveDataModel="true">
   <x:columns value="#{modelH.sloupce}" var="sloupec">
          <x:outputText value="#{modelH.columnValue.sedadlo}" />
          <x:inputText value="#{modelH.columnValue.cena}" />
    </x:columns>
</x:dataTable>
<h:commandButton id="asNastavitM" action="#{modelH.setMezery}" value="#{bundle.tl_nastavit_mezery}" />

and in my bean i have:
...
    private DataModel rows;   
    private DataModel columns;

    public Object getColumnValue() {
        Object columnValue = null;
        if (rows.isRowAvailable() && columns.isRowAvailable()) {
            columnValue = ((List) rows.getRowData()).get(columns.getRowIndex());
        }
        return columnValue;
    }

    public void setColumnValue(Object value) {
         if (rows.isRowAvailable() && columns.isRowAvailable()) {
            ((List) rows.getRowData()).set(columns.getRowIndex(), value);
        }
    }

     private void createDataModel() {
         // vytvor datovy model  - columns
        Hlediste hled = (Hlediste) scena.getHlediste(0).get(0);
        List columns = ((Rada) hled.getRady().get(0)).getSedadla();
        this.columns = new ListDataModel(columns);

        // vytvor datovy model - rows,columns
        List rowList = new ArrayList();

        ArrayList rady = hled.getRady();
        Iterator i = rady.iterator();
        while (i.hasNext()) {
            Rada rada = (Rada) i.next();

            ArrayList sedadla = rada.getSedadla();
            Iterator j = sedadla.iterator();

            ArrayList radka = new ArrayList();
            while (j.hasNext()) {
                Sedadlo sedadlo = (Sedadlo) j.next();
                SedadloBack sedadloBack = new SedadloBack(sedadlo);
                radka.add(sedadloBack);
            }
            rowList.add(radka);
        }

        rows = new ListDataModel(rowList);
    }

    public String setMezery() {
        try {
            int index = 0;
            rows.setRowIndex(index);
            while (rows.isRowAvailable()) {
                List list = (ArrayList) rows.getRowData();
                Iterator i = list.iterator();
                while (i.hasNext()) {
                    SedadloBack back = (SedadloBack) i.next();
                    log.info(""+back.getCena());
                }
                index++;
                 rows.setRowIndex(index);
                log.info("index "+index);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "ko";
        }
        return "ok";
    }