• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Accessing a UI component in a managed bean

 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using a data table in jsf and I want to access the rows selected by the user.However I want my logic to that all in my managed bean rather than in th pagecode(backing beans).How can I do it?.Aim is to separate the messy page code and my logic.How can I iterate through the rows selected by user.Help needed.

In anticipation.
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can easily achieve this using ExtendedDataModel in Richfaces component.

http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the getRowData() method on your data table to get the selected row.
 
Dishpal Bhaluja
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know I can get rowdata using that function but how can I get that UIComponent,Datatable.

Supposing I am clicking on a check box to select a particular row.Then if Im calling an action listner its registered as an event generated by checkbox and then I cant get the reference to Datatable.I need to get that reference and use the function ,rowdata.

As I suppose my managed bean to be free from codes that access these components.Can you please suggest a better way to organise the entire thing for clarity.
 
Saloon Keeper
Posts: 28316
207
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Offhand, I'd say you're trying to do things inside out and it's making things excessively complex.

JSF is based on Inversion of Control. In IoC, you normally don't have your beans go out and get things or do things. Instead, they wait for things to be injected into them and for requests to be made of them.

Another way of stating it is that the controlling logic is provided by the framework - the bean only provides the action logic and data storage.
<hr/>
You should separate business logic from the backing bean. It's good practice. But the way this is normally done is to implement the logic bean as a separate POJO which is injected into the backing bean either by JSF or an equivalent framework such as Spring. The backing bean's action processors then invoke the business bean's methods as needed,

I have no idea what "selected rows" means. JSF is not a client/server architecture nor is any other web application regardless of platform or programming language. A JSF backing bean can only receive events in a batch as an HTTP GET or POST request dispatches them - there's no back-and-forth like in client/server (and this is why I always stress that JSF is not a true MVC architecture). More to the point, I don't know what you mean by saying a row is "selected". There is a "current row" as a bean receives updates from the client, but this is enumerated by the framework, but that's an enumeration of all rows. There's no selection involved, just fields that updated or not.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry ressurecting the topic but I have the same problem. I have an IceFaces <ice:dataTable> that iterates from a List (here called "dataList") and generates a table.
dataList has the attributes: id, name, category, scenario and scope.

The table must show 2 columns:
- The "name" of the current data from the list;
- A commandButton that redirects to a page to see it's details (the other attributes);

The question is: how set the "id" attribute in the Managed Bean with the data's "id" from the row wich button was clicked.

Like this:

ROW1 | Button1
ROW2 | Button2
ROW3 | Button3
ROW4 | Button4
ROW5 | Button5

Button3 is clicked, the id "3" is passed to the managed bean, the form redirects to the detailed view of the data and retrieves the "id" of the row 3... Hope I made myself understood.

Tim, as you seem to be the guru around here... where can I get detailed information on the use of JSF managed beans, using FacesContext and PhaseListener kind of stuff? I only find simple examples with them but without information on -what- is really getting done.

Thanks a lot!
 
If you're gonna buy things, buy this thing and I get a fat kickback:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic