1

guys. I am doing on filing cabinet. I have separated schema - list of fields with mandatory and other flags. And then I have List of cabinet cards - they are Lists od Data and Data can be Simple - one value or Multiple - N values. I am mapping Schema fields to Data according to ordering. So assume I have 3 fields - author, book, number of pages. Author can be multiple. So in List on the first place I have MultipleData, on the other two SimpleData. And when I am reading it from MongoDB it is ok. It is Datatable with inner ui:repeat for MultiplaData situations. So I print:

Author: Author1, Author2, Author3...

Book: Book

Number of pages: 62

However when i try to add something, it is not working. I had to replaced inner ui:repeat because it was throwing arrayindexoutofbound exception, so i replaced it with h:dataTable.

This is my code

<h:form>
        <h3>Add new data</h3>
        <hr/>
        <h:dataTable value="#{filingCabinetManagerBean.filingCabinet.schema.fields}" var="schemaField" style="vertical-align: top">

            <h:column><h:outputText value="#{schemaField.fieldTitle}:" style="font-size: 20px;font-weight: bold"/></h:column>
            <h:column>
                <ul>
                    <h:dataTable value="#{filingCabinetManagerBean.newCabinetCard.cardData.get(filingCabinetManagerBean.filingCabinet.schema.fields.indexOf(schemaField)).data}" var="data"  rowStatePreserved="true">
                        <h:column>         
                            <li>
                                <h:inputText value="#{data}"/>
                            </li> 
                        </h:column> 
                        <h:column>

                            <p:commandButton value="Add field" actionListener="#{filingCabinetManagerBean.addMultipleDataField(filingCabinetManagerBean.filingCabinet.schema.fields.indexOf(schemaField))}"
                                             update="@form"  rendered="#{schemaField.repeatable and filingCabinetManagerBean.newCabinetCard.cardData.get(filingCabinetManagerBean.filingCabinet.schema.fields.indexOf(schemaField)).data.lastIndexOf(data) == (filingCabinetManagerBean.newCabinetCard.cardData.get(filingCabinetManagerBean.filingCabinet.schema.fields.indexOf(schemaField)).data.size()-1)}"/>

                        </h:column>

                    </h:dataTable>
                </ul>     
            </h:column>

        </h:dataTable>

        <p:commandButton value="Add data" 
                         action="#{filingCabinetManagerBean.addNewCabinetCard(testBean.selectedDB)}" update="@all" />
    </h:form>

Of course I am prefilling newCabinetCard variable with appropriate number of Strings, so it fits correctly to schema. Problem is that when i press Add data button, I save only empty strings, no matter what I write into input boxes.

I am using sessionscoped bean with property newCabinetCard - place to store those new values. When i fill those values for example with "abc" strings through code, I can see them but when I change it and save it - I save only those initial "abc" strings. It seems like input text cannot take values which I type into them. But I have another pages, when I am using inputTexts and they work well, I assume that this has to do something with dataTable.

I am asking for your help.

Thank you.

Xenon
  • 189
  • 1
  • 1
  • 14

1 Answers1

0

3 months ago I've found a solution. A variable "data" was only String and JSF need to have set/get methods to write/read from the variable. And of course String does not have them, so I created an encapsulated class MyString with a String variable in it and set/get methods for that variable. Now everything works perfectly.

Xenon
  • 189
  • 1
  • 1
  • 14