2D Input Datatable

UI Components for JSF
Post Reply
f.cardoso
Posts: 4
Joined: 07 Jun 2011, 11:34

22 Jun 2011, 01:34

I need to do some input on datatable which its datamodel wraps an ArrayDataModel out of a List:

Code: Select all

// 2DBean.java
List<Item> items[ ];
// some other code...
DataModel<List> my2DModel = new ArrayDataModel<List>(items) ;

//The rest if the code intializes the above objects, plus a List of <String> columnNames for my 2D datatable.

So, I came up with this solutiion using p:columns, which works fine at displaying my datatable and all it's input h:selectOnMenus:

Code: Select all

<p:dataTable value="#{2DBean.my2DModel}" var="items" id="2DataTable">
                                <p:columns value="#{my2DModel.columnNames}"
                                           var="column" columnIndexVar="colIndex">
                                    <f:facet name="header">
                                        <p:outputPanel>
                                            #{column}
                                        </p:outputPanel>
                                    </f:facet>

                                    [b]<h:selectOneMenu value="#{myInnerArrayList[colIndex].someProperty}" style="width:100%">
                                             <f:selectItems value="#{2Dbean.itemsAvailableSelectOne}" />  
                                    </h:selectOneMenu> [/b] 
                                </p:columns>

                                <f:facet name="footer">
                                                <p:commandButton value="Apply">
                                                    <p:ajax event="click" process="2DataTable" listener="#{2Dbean.doSomething}"/>
                                                </p:commandButton>
                                </f:facet>
                            </p:dataTable>
Problem is I'm getting this exception when I try to submit the form:

javax.el.PropertyNotFoundException: ... value="#{myInnerArrayList[colIndex].someProperty Target Unreachable, 'null' returned null


Does anyone have a clue on what am I possibly doing wrong?

MilenaMMay
Posts: 13
Joined: 31 May 2011, 17:15

22 Jun 2011, 14:19

1) As you declare var="items" in your dataTable you have to access that and not "myInnerArrayList" (where should this variable be set?)
I'd try:

Code: Select all

<h:selectOneMenu value="#{[b]items[/b][colIndex].someProperty}" style="width:100%">
                                             <f:selectItems value="#{2Dbean.itemsAvailableSelectOne}" />  
2) Have you checked that colIndex is correctly set by the columnIndexVar?

f.cardoso
Posts: 4
Joined: 07 Jun 2011, 11:34

23 Jun 2011, 09:16

Yes, you are right MilenaMMay.

I'm actually doing things right on my actual code. Got it wrong when I tried to create an abstract sample of what I'm actually doing. Thanks for trying to point that out to me anyway. :-)

My datatable is currently defined like this:

Code: Select all

<p:dataTable
                                value="#{horarioController.itensHorarioModel}" var="itensDoHorario" >
And I get the exception while submiting the form with:

Code: Select all

<h:selectOneMenu value="#{itensDoHorario[colIndex].disciplina}" >
                                        <f:selectItems value="#{disciplinaBean.itemsAvailable}" />
                                    </h:selectOneMenu>


Whereas in the sample, I meant it to be:

Code: Select all

[b]<h:selectOneMenu value="#{items[colIndex].someProperty}" style="width:100%">
                                             <f:selectItems value="#{2Dbean.itemsAvailableSelectOne}" />  
                                    </h:selectOneMenu> [/b]
Column index var is set OK:

Code: Select all

<datatable...>

<p:columns value="#{horarioBean.colunasDoHorario}"
                                           var="coluna" columnIndexVar="colIndex">
To make sure of that, I had my datatable doing ouput of itensDoHorario[colIndex].someOtherInitializedProperty, instead of input and the table came out fine with the expected data.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 19 guests