DataTable : "j_idt6" must be inside a form element.

UI Components for JSF
Post Reply
Bwang
Posts: 7
Joined: 23 Aug 2011, 08:27

23 Aug 2011, 08:40

Hi All,
I use primefaces-3.0.M2.jar, mojarra-2.1.2, Apache Tomcat 7.0 to use DataTable.
Here is my java code:

Code: Select all

@ManagedBean(name="carBean")
@SessionScoped
public class CarBean implements Serializable{
    private static final long serialVersionUID = 1L;
    private List<Car> cars = new ArrayList<Car>();
    public List<Car> getCars() {
         cars.clear();
         cars.add(new Car("A0001", "Mercedes", "Maroon", 1979));
         cars.add(new Car("A0002", "Volkswagen", "Maroon", 1994));
        return cars;
    }
    public static class Car{
        String model;
        String manufacturer;
        String color;
        int year;
        public Car(String model, String manufacturer,
                String color, int year) {
            this.model = model;
            this.manufacturer = manufacturer;
            this.color = color;
            this.year = year;
        }
...//getters and setters
}
And here is the xhtml file:

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml"   
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
    </h:head>
    <h:body>
        <h1>JSF 2 dataTable example</h1>
        <p:dataTable value="#{carBean.cars}" var="car" >
            <p:column>
                <f:facet name = "header">
                    <h:outputText value="Model"/>
                </f:facet>
                <h:outputText value="#{car.model}"/>
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value ="Manufacturer"/>
                </f:facet>
                <h:outputText value="#{car.manufacturer}"/>
            </p:column>
            <p:column>
                <f:facet name="header">
                    <h:outputText value="Color"/>
                </f:facet>
                <h:outputText value="#{car.color}"/>
            </p:column>
            <p:column>
                <f:facet name = "header">
                    <h:outputText value="Year"/>
                </f:facet>
                <h:outputText value="#{car.year}"/>
            </p:column>
        </p:dataTable>
    </h:body>
</html>
But when I access this page, I got the error message:
Aug 23, 2011 2:32:35 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/hello.xhtml]
javax.faces.FacesException: DataTable : "j_idt6" must be inside a form element.
at org.primefaces.component.datatable.DataTableRenderer.encodeScript(DataTableRenderer.java:112)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:94)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1763)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)

But if I replace the default DataTable tag, it works.
Can you help me or provide some references?

Bin Wang
Mojarra 2.1.2, PrimeFaces 3.0.M2, Tomcat 7.0.16

t_tobi
Posts: 27
Joined: 15 Aug 2011, 14:50

23 Aug 2011, 08:44

Try this

Code: Select all

...
<h:body>
        <h1>JSF 2 dataTable example</h1>
         <h:form>
            <p:dataTable value="#{carBean.cars}" var="car" >
           ...
           </p:dataTable>
       </h:form>
    </h:body>
...

Bwang
Posts: 7
Joined: 23 Aug 2011, 08:27

23 Aug 2011, 08:53

It works. :D
Thank you, t_tobi.

Bin Wang
t_tobi wrote:Try this

Code: Select all

...
<h:body>
        <h1>JSF 2 dataTable example</h1>
         <h:form>
            <p:dataTable value="#{carBean.cars}" var="car" >
           ...
           </p:dataTable>
       </h:form>
    </h:body>
...
Mojarra 2.1.2, PrimeFaces 3.0.M2, Tomcat 7.0.16

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 21 guests