Often the most important part of the news is what they didn't tell.
There is no emoticon for what I am feeling!
Originally posted by Jeff Albertson:
While what Sergey writes is true, I think you will typically bind a text field on a form to a backing bean as follows:
As far as your servlet comment, I'm confused. If you have developed using Struts, you are familiar with the idea of controller servlet. It's the same in JSF: you will typically have FacesServlet as your one and only servlet.
There is no emoticon for what I am feeling!
Originally posted by Jeff Albertson:
Ah, the penny just dropped for me. I didn't see where you were asking about database access in your original post... Anyway, I think of a jsp's "backing bean" as being part of the presentation layer, since it has UI component bindings and event handlers, so what I do is have business beans as properties of the appropriate backing beans. Your mileage may vary: my business beans are POJO since I hibernate... it can look like this:
On a jsp page, I write <hutputText value="#{pc_backingX.beanY.someProperty}"/>. There are some options here. Perhaps the bean is loaded by calling getBeanY (so the setter is not needed) or the setter is always called first, say from an action on another, earlier page.
[ February 02, 2006: Message edited by: Jeff Albertson ]
There is no emoticon for what I am feeling!
Often the most important part of the news is what they didn't tell.
There is no emoticon for what I am feeling!
Originally posted by Jeff Albertson:
Let me see if I understand your context -- does this sound right? For my example I assume you will manipulate user records. There is a page, user.jsp, backed by a manager bean that maps to class UserBackingBean which will manipulate business objects of the POJO type UserBean to do basic CRUD operations. Your jsp page is a form with input fields for say, username, password, email, etc... and submit buttons for create, retrieve, update and delete, perhaps.
What I wrote before will have to be tweaked a little for this set up. When you come to this page, unless the calling page or action has set things up with a UserBean, I would start it to be ready for creation or retrieval: (Previously, I assumed you *already* data for a unique index)
UserBackingBean will have actions wired to the user.jsp's submit buttons, and would change user as needed -- for instance if you entered a user name and pressed retrieve, the action would select the user from the database and populate its fields. (Searching with multiple results would need a different UI, of course.) In the case of an update, I typically write code that does an UPDATE (then commits) then a SELECT to recreate the bean over again and redisplay it. I do this as a reassurance to both me and the user that what they typed ended up looking like *this* in the database. If you don't want to do the select, leave the bean alone -- succeeding calls to getUser will retrieve the previous UserBean. Important: this assumes your backing bean has session scope!
I don't understand you concern about ordering components on the page. Also, here are some other common concerns:
1. Accidentally inserting the same data because you resubmitted the page. Here,the most elegant solution is for each business bean to have a natural or business ID that translates to a uniqueness constraint in the database. For user records, perhaps they need to have a unique username.
2. Accidentally updating twice by resubmitting. It's usually a good idea to do optimistic locking generally speaking, and that will catch this.
3. Accidentally updating when you just meant to view data. This is another preference, but I don't like data to be perpetually in "update" mode. When I've not explicitly asking to update, I want the data displayed in "read only mode". I'm not a fan of locked or disabled input fields, so what I typically do is include a state property in my backing bean (READONLY, INSERTING, UPDATING,...) and in READONLY mode render hutputText instead of h:inputText. JSF makes that easy to do.
I hope this has answered your questions. I suggest you get something up a running to try things out -- create a simple table just for testing purposes with only a field fields, and a jsp page, backing bean and POJO to work with it. It will probably take less time to set that up than it took me to write this!
[ February 03, 2006: Message edited by: Jeff Albertson ]
There is no emoticon for what I am feeling!
There is no emoticon for what I am feeling!
You didn't tell me he was so big. Unlike this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|