0

I'm making a datatable where you can add exrta rows. In this extra rows, there's a inputtext. After putting something in the inputtext, this value should be saved to a list. But it's not. I tried in the method below using Sting as a parameter, but then to a list was saved : "javax.faces.component.html.HtmlInputText@23sdf" and thing like that. When I changed method to javax.faces.component.html.HtmlInputText method below returns null.

here's code of table:

    <h:dataTable value="#{correct.newPowody}" var="z" binding="#{table}" >
    <h:inputText binding="#{custom}" value="#{z}">
        <f:ajax event="blur" listener="#{correct.newPowodyAdder(table.rowIndex, custom)}"
                                    execute="@this" render="@form"/>
    </h:inputText>
    </h:dataTable>

here is my correct bean code:

    public void newPowodyAdder(int rowIndex, javax.faces.component.html.HtmlInputText powod) {
        String value = powod.getValue().toString();
        this.newPowody.set(rowIndex, value);
    }
}

this method just should add data from inputtext into a list. Thank you for help

Lukas Novicky
  • 921
  • 1
  • 19
  • 44

1 Answers1

2

This code really isn't making any sense. It's an overcomplicated attempt to fix the simple problem of String class being immutable. Don't use <h:inputText value="#{string}". Just use brace notation [] in EL to reference a list item by index like so value="#{bean.strings[index]}":

<h:dataTable binding="#{table}" value="#{correct.newPowody}">
    <h:column>
        <h:inputText value="#{correct.newPowody[table.rowIndex]}" />
    </h:column> 
</h:dataTable>

That's all. No ajax listener method mess necessary.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • i do used like this but in my array data will not stored i used RequestScope any problem with this scope – Rookie007 Feb 13 '14 at 10:23