Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

using a commandButton in a datatable column to edit row of data.  RSS feed

 
Tim Resh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a data table that has a column with a commandbutton that you click to edit the row of data. the edit portion of the datatable is a panelGrid called userDetails which should show up once the edit button is clicked however it does not show up as expected. I have another commandbutton that is NOT in the datatable to create a new record and it causes the userDetails to show as expected. I use the rendered="#{userController.showUserDetails}" to control when the userDetails displays. When I click the Edit button the action listener target is set to target="#{userController.selectedUser}" where I set the rendered showUserDetails to true. I have debug the listener and it is setting the showUserDetails to true but the panel does not show up. Any ideas?

Thanks
Mark


 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you'll find that replacing


with


may help. The re-rendering attributes of JSF use the JSF ids, not the underlying HTML ids.

Also, you've made things complicated by using the "rendered" attribute on the anonymous "User Details" panel, but making AJAX update the userDetails panelGrid. I recommend that you move the ID "userDetails" to the panel and give the panelGrid a new id. If you say "update="userDetails"" for the panelGrid, but the last rendering of the containing panel object has set to "rendered="false"", then userDetails will not be updated because its parent was not updated.


 
Tim Resh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim, I tried making your changes but I am getting an error
14-Sep-2015 18:34:12.875 SEVERE [http-nio-8080-exec-2] com.sun.faces.application.view.FaceletViewHandlingStrategy.handleRenderException Error Rendering View[/rem40/usersEdit2.xhtml]
javax.faces.FacesException: Cannot find component for expression "userDetails" referenced from "form:j_idt40:0:selectButton".


Here is the current code:



You suggest that I am making it complicated by using the rendered attribute on the panelgrid. How should this work and what direction should I have taken?


Thanks
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I got distracted by the "Controller" in your backing bean name. Sorry, no matter what NetBeans thinks, backing beans are not Controllers, they are Models.

Anyway, your original reference (":form:userDetails") was correct after all, You're crossing Naming Container boundaries. I think in some contexts the full ID is only required if the target ID is ambiguous, but this isn't one of them.

Speaking of IDs, dataTables are also Naming Containers, so it's a good idea to give them explicit id's too.

Aside from the ID issues and name distractions, what I see as the main problem is that you are attempting to do an AJAX re-rendering of a component (panelGrid)that's contained within another container (panel) that [i]isn't[/b] being re-rendered. Since the outer container was set up with the show/hide (rendered) attribute, re-rendering the inner component would do no good, since its container remained un-rendered. Changing to the new ID scheme should resolve that.

So with any luck, setting your commandbutton's "update" target back to ":form:userDetails" should make everything work.
 
Tim Resh
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim, you have been extremely helpful.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!