Dynamic columns table with checkboxes: doesn't work

UI Components for JSF
Post Reply
bitec
Posts: 44
Joined: 20 Jan 2011, 21:34
Location: Russia

06 Feb 2011, 16:32

hi.

I've spent plenty of time trying to make this thing work... Hope anyone will help me.

I have the dataTable with dynamic columns and checkboxes inside:

Code: Select all

<p:dataTable value="#{k3DriveExperienceStorage.dynamicData}" id="expTable" var="exp">
						<p:columns var="column" columnIndexVar="colIndex" value="#{expTableCols}">
							<f:facet name="header">
								<h:outputText value="#{column}" />
							</f:facet>
							<h:outputText value="#{exp[colIndex].formattedExp}" rendered="#{colIndex eq 0}" />
							#{exp[colIndex].id}
							<h:selectBooleanCheckbox value="#{exp[colIndex].checked}" rendered="#{colIndex != 0}">
							
							<!-- 
								disabled="#{empty exp[colIndex].ratio or polisBean.agesExpDisabled}"
								 -->
								
								<p:ajax listener="#{polisBean.updateDriveExperiences}" update="mess" process="expTable" />
							</h:selectBooleanCheckbox>
						</p:columns>
					</p:dataTable>
expTableCols is the list of arrays of necessary objects (the same as in the showCase), which contain boolean field "checked". This thing is rendered ok, but when I try to submit the request, I recieve the following error:

Code: Select all

javax.faces.component.UpdateModelException: javax.el.PropertyNotFoundException: /polises/calculator.xhtml @98,94 value="#{exp[colIndex].checked}": Target Unreachable, 'null' returned null
	at javax.faces.component.UIInput.updateModel(UIInput.java:839)
	at javax.faces.component.UIInput.processUpdates(UIInput.java:722)
	at javax.faces.component.UIData.iterate(UIData.java:1431)
	at javax.faces.component.UIData.processUpdates(UIData.java:1067)
	at org.primefaces.component.datatable.DataTable.processUpdates(DataTable.java:603)
	at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1108)
	at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1108)
	at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1108)
	at javax.faces.component.UIForm.processUpdates(UIForm.java:270)
	at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:476)
	at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:175)
	at javax.faces.component.UIForm.visitTree(UIForm.java:343)
This happens on update model phase, and seems that the component doesn't set the "exp" variable properly when iterating over data rows. Will investigate this but the help is highly appreciated!
JSF: Mojarra 2.1 | PrimeFaces 2.2.1 | Glassfish 3.1

bitec
Posts: 44
Joined: 20 Jan 2011, 21:34
Location: Russia

06 Feb 2011, 17:26

As I can see now the row variable "exp" is set correctly, but the "colIndex" variable is never set inside the component (processUpdates() method in the org.primefaces.component.datatable.Datatable class does not override the default behaviour of the UIData component and iterates through the column components (single Columns object) which also iterates through children (htmlSelectBooleanCheckbox). But during this iteration I cannot see any moment, where the column index would be set, that's why the value expression fails to be evaluated....

Great pity, that's one of the most useful components is read only.. Will try to create my custom component for these needs.
JSF: Mojarra 2.1 | PrimeFaces 2.2.1 | Glassfish 3.1

bitec
Posts: 44
Joined: 20 Jan 2011, 21:34
Location: Russia

06 Feb 2011, 19:15

I've solved the exception after writing custom DataTable component (just extended the primeFaces DataTable and overriden the processUpdates() method). But now I face another problem: the p:columns renders all children checkboxes with the same ids ! That's why the wrong checkbox is populated during decode phase and only the first checkbox is checked :(. Setting id=#{colIndex}_bool for each checkbox doesn't help as all checkboxes are rendered as "form_id:_bool" ids....
JSF: Mojarra 2.1 | PrimeFaces 2.2.1 | Glassfish 3.1

bitec
Posts: 44
Joined: 20 Jan 2011, 21:34
Location: Russia

07 Feb 2011, 10:03

Unfortunately I could not solve the last problem, although everything seemed so good after I overrode the "iterate" method of UiData... When rendering the datatable the Columns component iterates through the columns list and renders chidlren component (checkbox in my case). But on each iteration this component is the same! Only the evaluated value of this component differs, but the component itself has the same id. That's why these components cannot be used for taking actions...

Here is the piece of DataTableRenderer code:

Code: Select all

protected void encodeDynamicCell(FacesContext context, DataTable table, Columns columns) throws IOException {
        ResponseWriter writer = context.getResponseWriter();
        String columnVar = columns.getVar();
        String columnIndexVar = columns.getColumnIndexVar();
        int colIndex = 0;

        for(Object column : (Collection) columns.getValue()) {
            context.getExternalContext().getRequestMap().put(columnVar, column);
            context.getExternalContext().getRequestMap().put(columnIndexVar, colIndex);
            UIComponent header = columns.getFacet("header");

            writer.startElement("td", null);
            writer.startElement("span", null);
            [b]columns.encodeAll(context);[/b]
            writer.endElement("span");
            writer.endElement("td");

            colIndex++;
        }

        context.getExternalContext().getRequestMap().remove(columnVar);
        context.getExternalContext().getRequestMap().remove(columnIndexVar);
    }
Each time the columns.encodeAll(context); is called, it processes the same component(s), new ones not created.

I tried to use the facelet UiRepeat approach and add the index of current iteration to the generated content somehow (see RepeatRenderer for more details), but I failed to understand completely, how it does it.. I think PrimeFaces should take into account the UiRepeat approach for handling children of p:columns component to enable action behaviour for such kind of tables. So far this table is not of very large benefit and I will use the simple datatable so far, but expecting the feedback from PF team on this issue!

Thanks.
JSF: Mojarra 2.1 | PrimeFaces 2.2.1 | Glassfish 3.1

marcos.alcantara
Posts: 8
Joined: 28 Jul 2010, 19:30

21 Feb 2011, 13:57

hi bitec,

how you solved the problem of submit dynamic inputs?

thanks.
primefaces 3.0M4, JDK 1.6, glassfish v3.1.1

davti
Posts: 9
Joined: 27 Feb 2010, 01:37

07 Mar 2011, 12:12

how you solved the problem of submit dynamic inputs?

I'd like to know the answer to that one also...

davti
Posts: 9
Joined: 27 Feb 2010, 01:37

07 Mar 2011, 12:13

I am having exactly the same issue with a h:selectBooleanCheckbox in a data table richFaces solved the issue by appending the columnIndexVar to the componentId <h:selectBooleanCheckbox id="salesChannel#{index}"

regards,

Tim

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

07 Mar 2011, 14:23

p:colums has event processing limitation as of 2.2.1

See;

http://code.google.com/p/primefaces/iss ... il?id=1715

sbhrgv
Posts: 1
Joined: 07 Feb 2012, 07:50

07 Feb 2012, 07:57

Has this issue been resolved ?? I am still getting the same error javax.el.PropertyNotFoundException: create.xhtml @84,98 value="#{user.ordersMap[orders]}": Target Unreachable, 'BracketSuffix' returned null. I am using primefaces 3.0.M3

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 34 guests