• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF 1.2 Facelets - Component ID form1:dataTable:j_id101 has already been found in the view

 
Solomon Gnanadurai
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have links in datatable when clicked calls the backing session bean (CustomerAndAccountInfo) and populate some text fields in the screen to edit the table data.
<h:dataTable binding="#{CustomerAndAccountInfo.dataTable}" id="dataTable" border="1" value="#{CustomerAndAccountInfo.currentService.packageVO}" var="packageList" styleClass="ct02" headerClass="ch02" rowClasses="row1,row2" cellspacing="0">

<h:column>
<f:facet name="header">
<hutputText value="Action Type" />
</f:facet>
<h:inputHidden value="#{packageList.id}"></h:inputHidden>
<h:commandLink action="#{CustomerAndAccountInfo.editDataItem}" styleClass="hiddenlink">
<hutputText value="#{packageList.actionType}" > </hutputText>
</h:commandLink>

</h:column>
In editDataItem() I am able to get the values from datatable but sometimes it throws
Root cause of ServletException. java.lang.IllegalStateException: Component ID form1:dataTable:j_id101 has already been found in the view
I looked around and added the below code in editdataitem() but didn’t fix the issue.
if (dataTable != null) {
UIComponent abc = dataTable.getParent();
abc.getChildren().remove(dataTable);
dataTable=null;
}

I also tried to bind the datatable to PackgeVO but its object is null in the bean editDataItem() method.
I am using JSF1.2 and facelets. Any help would be greatly appreciated. Thanks
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Helpful hint: use our editor's "Code" button to wrap special tags around your sample code and XML. It makes them easier to read.

One of the biggest problems with JSF is that everybody is used to having to do a lot of complicated work to get things done and JSF is designed very much with the idea that you shouldn't have to do a lot of complex work. Or, as Alan Kay once said: "Simple things should be simple and complex things should be possible."

In the case of adding and removing rows from a datatable, that means you don't need to actually go in and meddle with the UI elements, just update the datamodel. When the table is re-rendered, it will reflect the datamodel.

So, assuming a ListDataModel:


To remove the row that was clicked on:



By the way, package name elements ("CustomerAndAccountingInto") should not begin with upper-case letters.
 
Solomon Gnanadurai
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

My data model looks like this:



CustomerAndAccountInfo session bean has the property ServiceVO and editDataItem() method like this



As you can see the commented lines I was trying to get the RowData from HtmlDataTable which is working fine but I get exception sometimes: Component ID form1:dataTable:j_id101 has already been found in the view.
And I also tried to cast the List to ListDataModel as above but it throws ClassCastException. I am not sure how to get packageVO.getCurrentRow() and packageVO.getWrappedData() from the List object
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot use a Java array or Collection object directly as a dataTable model object. You have to wrap it in a JSF DataModel object such as a ListDataModel or ArrayDataModel. That object would be what the value attribute on the dataTable page tag references.

The reason for this is that in addition to holding the data itself, the datamodel also maintains the cursor used to track the rows of the table.

 
Solomon Gnanadurai
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, currently I am using the PackageVO list in so many other parts of the code and my datamodel looks like the below. Can you suggest me exactly what code changes I have to make? Thanks
 
Solomon Gnanadurai
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, thanks for your suggestion to use ListDataModel. I followed this post on how to use ListDataModel http://numberformat.wordpress.com/2010/08/25/using-jsf-to-display-table-data/ and I have resolved the issue. I will update this thread if I ran across again the intermittent issues I had before. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic