0

I am trying to update values in an h:dataTable and have reached my limit in request parameters allowed in a single POST. After firebugging it I see that the whole table is being sent for an update on a single row. I tried moving the h:form to surround just the a4j:commandButton but this does not update the property value. I thought of using f:ajax, but everything I've seen mentioned there talks about changes in ManagedBeans. The problem with that is that the backing class is used in standard Java applications also so I want to keep it as a nice clean POJO and not add dependencies on Java EE specific libraries.

UPDATE

As requested by @Luiggi Mendoza I have broken down the problem into an SSCCE with two Java classes and a single xhtml:

testDT.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"> 

<h:head></h:head> 
<body>
    <rich:panel id="props">

      <h:form>
      <h:dataTable value="#{propertyEditor.properties}" var="prop">
        <h:column>
          <f:facet name="header">
            <h:outputText value="Value"/>
          </f:facet>
          <h:inputText value="#{prop.value}">
            <f:ajax/>
          </h:inputText>
        </h:column>
        <h:column>
          <a4j:commandButton
              value="Update Property"
              action="#{propertyEditor.updateProperty(prop.id)}"
              render="props"
              execute="@this"/>
        </h:column>
      </h:dataTable>
    </h:form>
    </rich:panel>
</body> 
</html>

PropertyEditor.java

package com.test;

import java.io.Serializable;
import java.util.ArrayList;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named
@SessionScoped
public class PropertyEditor implements Serializable
{

  private ArrayList<Property> properties = new ArrayList<Property>();

  public PropertyEditor() {}

  @PostConstruct
  private void initProperties() {
    for (int i = 0; i < 510; i++) {
      Property p = new Property(i,"key"+i,"value"+i);
      properties.add(p);
    }
  }

  public ArrayList<Property> getProperties() {
    return properties;
  }

  public void updateProperty(int id) {
    System.out.println("we are updating: " + id);
  }

}

Property.java

package com.test;

public class Property
{
  private int id;
  private String key;
  private String value;
  public Property(int id, String key, String value)
  {
    super();
    this.id = id;
    this.key = key;
    this.value = value;
  }
  public int getId()
  {
    return id;
  }
  public void setId(int id)
  {
    this.id = id;
  }
  public String getKey()
  {
    return key;
  }
  public void setKey(String key)
  {
    this.key = key;
  }
  public String getValue()
  {
    return value;
  }
  public void setValue(String value)
  {
    this.value = value;
  }

}

Also, here are my config files (beans.xml, faces-config.xml, and web.xml):

beans.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:plidm="urn:java:org.jboss.seam.security.management.picketlink"
       xmlns:security="urn:java:org.jboss.seam.security"
       xmlns:s="urn:java:ee"
       xsi:schemaLocation="
      http://java.sun.com/xml/ns/javaee
      http://jboss.org/schema/cdi/beans_1_0.xsd">

</beans>

faces-config.xml:

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">

</faces-config>

web.xml:

<?xml version="1.0"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <display-name>DataTableSubmit1</display-name>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
      <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
</web-app>

I also have the following jars in my WEB-INF/lib directory:

common-annotations.jar
commons-beanutils.jar
commons-collections.jar
commons-digester.jar
commons-logging.jar
cssparser-0.9.5.jar
guava.jar
jsf-api-2.0.4-b09.jar
jsf-impl-2.0.4-b09.jar
jstl.jar
richfaces-components-api-4.2.0.Final.jar
richfaces-components-ui-4.2.0.Final.jar
richfaces-core-api-4.2.0.Final.jar
richfaces-core-impl-4.2.0.Final.jar
sac-1.3.jar
standard.jar

I am running on JBoss 7.1.1.Final using Java 1.6. This still submits the whole table every time I try to update 1 row. I know I could increase the number of allowed request parameters but that seems like a total hack. The response message I get when looking at it in firebug is:

<?xml version='1.0' encoding='UTF-8'?>
<partial-response><error><error-name>class java.lang.IllegalStateException</error-name><error-message><![CDATA[More than the maximum number of request parameters (GET plus POST) for a single request ([512]) were detected. Any parameters beyond this limit have been ignored. To change this limit, set the maxParameterCount attribute on the Connector.]]></error-message></error></partial-response>

Thanks

geoff dix jr
  • 43
  • 1
  • 8

1 Answers1

0

Assumming your updateProperty method receives an int parameter (or the type of prop.id), then you have to use action instead of actionListener.

Solution:

<h:dataTable value="#{propertyEditor.properties}" var="prop">
    <!-- columns with data -->
    <h:column>
        <a4j:commandButton value="Update Property"
            action="#{propertyEditor.updateProperty(prop.id)}"
            render="props notif"/>
    </h:column>
</h:dataTable>

And your managed bean:

@ManagedBean
@ViewScoped
public class PropertyEditor {

    //attributes, constructor, getters, setters and other methods...

    public void updateProperty(int id) {
        //current implementation...
    }
}

If you work with CDI, is basically the same approach, just different annotations:

@Named
@SessionScoped
public class PropertyEditor {

    //attributes, constructor, getters, setters and other methods...

    public void updateProperty(int id) {
        //current implementation...
    }
}

Refer to the differences between both here: Differences between action and actionListener

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • Thanks for the reply Luiggi. As I said in my post I do not want to make my POJO (Property class) a `@ManagedBean` because it is used in standalone applications as well. `PropertyEditor` is a Seam object annotated with `@Named` and `@SessionScoped`. It handles the updates and does implement the method `public void updateProperty(int id)`. The problem is not that the code doesn't work at all, the problem is that it doesn't work when the size of the table grows beyond a couple hundred. I'm looking for a way to submit just one row, not the whole table. – geoff dix jr Mar 27 '13 at 20:50
  • @geoffdixjr the problem was the JSF code. I placed the `@ManagedBean @ViewScoped` since I didn't know if you used CDI, so I assumed to answer with JSF related annotations. As you can see in my edit, the JSF code is the same, you just have to change the annotations (and see the light). – Luiggi Mendoza Mar 27 '13 at 20:54
  • 1
    @geoffdixjr also, since you're using RichFaces, why don't use `` that supports pagination by nature? – Luiggi Mendoza Mar 27 '13 at 20:56
  • I remain in the darkness. I tried changing it to action and get the same result - too many request parameters, the whole table. I updated my question to include the editor class, maybe that will help. As far as using ``, these are the changes I made as part of migrating the application from JBoss 4.2 to JBoss 7 so there was a lot of trial and error along the way and I may have overlooked that. Also, in the case of these properties I find it easier to view them on one page (for now at least). Thank you for the tip. – geoff dix jr Mar 27 '13 at 21:19
  • @geoffdixjr try adding `execute="@this"` on the ``. – Luiggi Mendoza Mar 27 '13 at 21:44
  • Thanks for the suggestion Luiggi, unfortunately I get the same result. – geoff dix jr Mar 27 '13 at 21:51
  • @geoffdixjr it would be better if you post the [SSCCE](http://sscce.org) or your JSF code to try to reproduce it and look what problem could you have. – Luiggi Mendoza Mar 27 '13 at 21:53
  • I have edited my post and provided an SSCCE that reproduces the problem. Hopefully that will help in determining what is going wrong. I still feel like it must be something simple, but at this point that does not appear to be the case. – geoff dix jr Mar 28 '13 at 13:22