0

I need help in implementing CRUD operations. My application contains a table of objects. Each object is described by a list of properties(values). One property is modified with a custom JSF editor, depending on the property type.

When the user adds a new account, the list of editors is determined from the object's type, and displayed in a form using custom:include tags. This custom tag is used to dynamically include the editors <custom:include src="#{editor.component}">. The component property points to the location of the JSF editor.

Every editor has a managed bean that implements a ValueHolder interface and inherits a AbstractEditor class. AbstractEditor contains a updateEditor method.

public interface ValueHolder {  
    String EDITOR_VALUES = "editorValues";  
    public Object getValue();  
} 

I use a session map, with the editor name as key and editor value as values. When the user modifies a property, the updateEditor method is called and the map is updated with the new value of the editor.

The problem is with the scope of the beans behind the editors. If I use @SessionScoped beans, the code that initializes the editor is not called again and I can't handle the add/edit actions. The @SessionScoped works only for adding. I have tried with @RequestScoped, but the beans are called very often and I don't know if that is really good.

I am using JSF2, PrimeFaces 3.0.M4 and Spring Web Flow for navigation.

Seitaridis
  • 4,459
  • 9
  • 53
  • 85
  • `@RequestScoped` is what you need to use for something like this, but if you don't like that the beans are called a lot of times, you can use a `@SessionScope` and "reset" it (manually!) at the end of the `updateEditor()` method to "simulate" the initialization! – StepTNT May 14 '12 at 15:04

2 Answers2

1

Have you looked at using @ViewScoped beans? The view scoped beans remain in scope as long as you continue to return to the same page. This looks like what you are doing.

Alternatively, if you are using CDI, you could use @ConversationScoped to keep the bean in scope while you are doing the updates. This has a definite beginning and end. This will allow you to determine when the bean goes out of scope.

John Yeary
  • 1,112
  • 22
  • 45
  • The view contains the table with objects. When I add/edit an object a an modal window appears over that table. I can't use @ViewScoped beans because that view doesn't change. It changes only when I navigate to another view. – Seitaridis May 15 '12 at 05:44
  • How can I use the @ConverstionScoped in my context? – Seitaridis May 15 '12 at 05:47
  • The `@ConversationScoped` bean would start a conversation when the user edits an object, and the conversation would end when the user saves the object as an example. – John Yeary Jul 06 '12 at 16:55
0

I have kept the @SessionScoped beans. The bean has its name stored in the session and it is the same name as the filename of the editor. This way there is an association between the editors and the beans.

A initialize method was added to theValueHolder interface. This method is called when an object is added/modified.

Seitaridis
  • 4,459
  • 9
  • 53
  • 85