• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF bean & display out of sync issue  RSS feed

 
Ronan Dowd
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, am new to JSF so apologies if this question is a little broad.
In my app, I've one page (for simpliclities sake). When i click a button, a new row should be added automatically to a table
at the bottom of the page. The button submit submits back to the JSP. The JSF bean (myBean) involved updates
a list (rowList) in the bean to add a new entry to it (i.e. which represents the new table row being added).

So when i click the button, it should update the list in the bean and
then the page should refreshes showing the new row. But whats happening is that the first click
doesn't add a new row (even though it's added to the list in my bean). If I click a 2nd time then the row is added.

I'm using JSTL to render the page (code fragment below)

<c:forEach var="individualRow" items="${myBean.rowList}">
..iterate over the list are render each row's data
</c:forEach>

Has anyone seen an issue broadly similiar to this before? i.e. it's as if the value of "items" (in the jstl) is out
of date.

Any help would be great,
thanks, Ro
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSTL is generally going to cause you problems. You'd be better off using a dataTable tag. Do that, and add the new row to the dataTable's model and the page will update correctly without the need to put logic on the View.
 
Ronan Dowd
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Great stuff, am trying that and it seems to work so far. I'm getting the correct number of rows.

One other thing. I want to be able to know, on each iteration, what the iteration count is?. Is there a way i can get this from some attribute of the h:dataTable ?
i.e. is there a way it keeps an index of it?

Thanks, Ro
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're thinking in logic terms. A dataTable isn't logic - it's a 2-dimensional display. I could get into mumbling about being idempotent and stuff like that, but the upshot is that as far as the View is concerned, there's no iteration any more than an MS-Word document is iterations.

However, I presume you mean you want a row number for display purposes. Since a dataTable simply presents the model that backs it, that means that you need a row number in the model. This may mean that you need to front your actual data items with decorators that include a row number property.

Of course, if you're just thinking of row numbers as in "which row did I click on?", JSF already knows. It's available from the getSelectedRow methods of the DataModel when an action is performed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!