Friday, May 1, 2009

Working with Managed Beans

Going directly into the request objects getParameter method isn’t the best way of figuring out what a user has typed into a textfield, or which checkbox they have clicked or which radio button they have selected.

In fact, by using our previous method for pulling information out of a textfield, we skippout out on many of the most important, and most core functions, that JSF provides us.

For example, say the user didn’t type anything into the textfield at all? we’d probably want to validate the user input before it even gets to our processing logic that we have in our ‘do’ method. Or perhaps in a slightly different scenario, say a textfield contained a number with commas after every third digit? We’d probably want to convert that number into a proper, Java data type like a BigDecimal or a long before passing it to the appropriate method of a managed bean. Our previous method of pulling textfield using the identifiers assigned through JSF bypasses all of these options.

The fact is, there is a much, much simpler way to get the data that a user typed into a form input field on a web page into your JSF application, and it involves some fairly simple coding in your managed bean.

No comments:

Post a Comment

Followers