skip to content »

Updating the bean value jsf

updating the bean value jsf-89

One of the nicest feature of Prime Faces is you can add some parameters to your ajax calls ( callbacks ) and can decide on what to update while executing your actions on your managed beans.Think of following common scenario, we want to create a new user object with a dialog and show it in a datatable when user clicks on save button and do all these stuff with Ajax.

updating the bean value jsf-51updating the bean value jsf-71

as you can pass objects here, you can access them in your javascript methods in the client side.Admittedly, putting all your Managed Beans in Session Scope may be a working solution for some problems encountered while developing web applications with JSF.But it bears a high potential for undesired behavior, which is mostly not noticed until real problems arise.This article lists some routine tasks for JSF developers and gives tips and tricks on how to pass values efficiently without having to pollute the session-object.The intended audience for this article are novice JSF developers as well as developers that are interested in alternative solutions to common problems.Let’s think you as a developer want to do this using a p:dialog as follows: so what this code does it, when user clicks on save, the dialog should be closed, a message should be shown for successful creating and the p:datatable which shows all the users should be updated.

what happens if user just clicks save button w/o entering any data?

Problems caused by wrong Bean Scopes are often hard to trace and require profound knowledge of the JSF framework (and the fundamental principles of web applications in general).

This is why particularly developers new to JSF get easily in trouble by excessively using Session Scoped Beans.

So let’s define the requirement more precisely and try to implement it.

We want to open a dialog when we want to create a new user for the system, the username and password are required fields and when user does not enter any data to these fields and click save, the dialog should stay visible and messages shown inside the dialog.

There are a few simple questions to consider when dealing with Session Scope: With these considerations about session pollution and the resulting risks let’s take a look at common scenarios in JSF development.