tags:

views:

29

answers:

1

Hello.

I'm currently building my first JSF 2 application and I have some questions regarding flow of data between views.

Background

The application keeps track of competences of IT-consultants. To illustrate my questions, I will just describe a small part of it. A Competence entity has a many-to-one relation to a Area entity, putting the different competences in groups. I have views to handle these: Competence.xhtml, EditCompetence.xhtml and EditCompetenceArea.xhtml. These are backed up by a ManagedBean, AdminCompetenceController.

Competence.xhtml lists all Areas in a table, and lists all Competences in an Area if the user clicks on its row. It also has a new-button for Competences and Areas, and an Edit-button for each Competence and Area. these leads to EditCompetence.xhtml and EditCompetenceArea.xhtml respectivly, where the user can fill in information about a Competence or and Area.

Questions

  • What is the recommended way to handle flow of information between these pages? For example: EditCompetenceArea.xhtml needs to know which Area it should edit (or if it should make a new one). Should I have one backing bean per view or one for all of them? Should it be Session scoped and keep track of the selected Area/Competence with variables? Or should it be View scoped and send the id of the selected object with viewParams? Is it even possible to use Request scope? I've tried several of these and have run into practical problems with each method.

  • Is it possible to use viewParam to transfer information between views using different backing beans?

  • Is it possible to use viewParam with a Request scoped backing bean? The data seems to disappear from the bean before I can use it in the postback.

Also, if anyone can recommend any reading material (preferably free, online) regarding more general design patterns rather than specific smaller problems in JSF 2, I would really appreciate it.

A: 

To retain data in conversations with the same view, put the bean in view scope. The data will get lost after you navigate to a different view.

To retain data in conversations with different views, either put the bean in session scope to keep it alive among all requests/views, or use <h:inputHidden>, <f:setPropertyActionListener>, etc to retain request scoped data in subsequent request.

In your particular case, I'd go with single main @ViewScoped bean and a single CRUD view wherein the display table and the edit form is included/rendered conditionally.

BalusC