Is there an idiots guide to JSF and scope somewhere?

I am getting very confused with scope and JSF.
I have a page that just displays customer details (from CustomerBean extends Customer) with a button that should allow the user to change the customer details. Both pages use the same backing bean (is that recommended?).
customerDetail.jsp --> editCustomer.jsp
If I set the scope of CustomerBean to session, editCustomer sees the same customer as customerDetail. It seems to me that I shouldn't really be using session scope as I don't want a particular customer to hang around once I have finished with him. So what should I be doing?
Should customerBean be request scoped? If so how does editCustomer see it?
Or should I somehow destroy the session scoped customerBean when I have finished with it?
I also notice that some example jsps out there have a hidden field for the ID - should I simply look up the customer again from the database in editCustomer?
I also tried to add a <h:inputHidden value="#{customerBean}"/> but that broke my jsp.
I have bought and read the J2EE tutorial but I am still confused as to what the recommended way to drag the same Object through two jsp pages.
It's probably very simple but it's doing my head in ;-)
- David

Yeah, forming a model in your head to explain something can be painful, sometimes. This question has come up before, including where I work, and I've never really seen a comprehensive answer, so I'll just write one. :)
This is kind of a basic servlet concept, so I'll talk mostly about servlets. JSF is just flavor on top of this.
The lifetime of the request is: from the time the user hits "submit" until the time the response is fully rendered, whatever page that is.
So, you have a form the user has filled out and he/she hits "submit".
The HTTP POST request goes to the server (open port 80, write some "key: value" headers to satisfy the HTTP protocol requirements, followed by a stream of text that represents the users' form field values, wait for a response) which then proceeds to process it by parsing the incoming data and making a bunch of subroutine calls. The last set of subroutine calls basically involves a bunch of println() calls to write HTML into an output stream, which is the response the requesting browser is listening for. When that stream is done, the browser displays the html.
There's nothing that says the html that's displayed is the same as the html that originally held the form the user submitted. The first page is essentially garbage that somehow generated some form fields. The server could care less what it was, all it wants is the key=value pairs.
You could, if you were so inclined, code all those println()s yourself. That's straight servlet programming. It's totally under your control. You could code println( "<html><body>Hi, Mom!</body></html>"); and be done.
Or, you could write a JSP that, when compiled, turns into essentially a subroutine chock full o' println()s, and you could call that subroutine.
You do that with RequestDispatcher.forward(). It's just a subroutine call. (But don't do any more scribbling on the output stream after it returns, 'cause the stream's essentially been closed.)
It's all a big call tree with one thread of execution, single entry, single exit. One of the nice things about servlets is that the infrastructure makes available to you, in a contextual sorta way, the original request parameters plus whatever attributes you choose to attach to the request as your proceed w/your processing, kind of like charms on a charm bracelet (via ServletRequest.setAttribute()). (When I say "contextual", I mean the ServletRequest is passed in as a parameter to Servlet.service() so you can sling it around in your call tree.) Attributes you choose to attach while processing incoming form data are available later (for instance... in the subroutine that has all those println()s you so carefully coded up or allowed the JSP compiler to generate for you).
When the call tree is done (you've finally printed "</html>", marked the output stream "done" somehow and shipped all that HTML back out to the browser), the ServletRequest object that held the incoming form parameters plus whatever attribute cruft it accumulated is garbage collected. (I could write something poetic about Elysium and gamboling among daisies, but... nah.) So, the lifetime of that data associated w/the ServletRequest is the duration of that request-processing call tree.
JSF gives you a nice bunch of automatically-generated request attributes, corresponding to your request-scoped managed beans. It even very kindly transfers (via the value bindings) incoming form parameters into properties of beans which are attributed onto your ServletRequest, automagically.
So, if, in your JSP, you bind your form data to request-scoped bean properties (not the bean itself, but the bean's properties), those exact same bean properties will be visible on whatever JSP you eventually wind up on and it will be available to whatever intervening logic you code up ("Invoke Application" phase), and when the request is done, it all vanishes into thin air.
To be more specific to your question: yes, I believe it is recommended to have the same bean between pages. That's kind of the whole point. If you find yourself at the end of a request trying to destroy session data that was created at the beginning of that request, you should probably be using request scoping, not session.
I could be wrong, but I don't think you can bind an entire bean to an html element value. You bind bean properties. Of course, there's nothing to say that a bean property couldn't be... another bean!
In your particular case, I guess you have a bunch of display-only strings that come from your customer bean, plus a hidden "key" field somewhere. You could bind that hidden field to the customer.key property and Customer.setKey() would do whatever's necessary to get the rest of the data into the bean. That could be a d/b lookup or a map or array (cache) fetch. Or you could have a "current customer" in your session (that would have to be session-scoped, because you paint the detail screen w/one request and then paint the "edit" screen w/the same customer but in a different request). That "current customer" concept might cause you some problems later when you go multi-window or multi-frame in your webapp (truuuuuuuust me).
Also, I'm not sure why you need a CustomerBean separate from Customer. Can you just make Customer a bean and be done with it?
Holy cow, what an essay this turned out to be.
John Lusk.

Similar Messages

  • Can I use a Photoshop CS6 guide book I got in college to learn CC, or is there too many differences between CS6 and CC?

    I have a guide book I got in college to help me learn Photoshop CS6, but I never finished the class. My question is: Can I use this book to learn Photoshop CC or is there too much diversity between CS6 and CC?

    caj50932876 wrote:
    Thanks! I appreciate you answering so quickly!
    That's OK.  We race to be the first responder, because we are sad geeks, and first responder sounds like something from a TV reality program.  Benjamin actually has flashing lights and a siren on his computer.

  • Hey there! well i from india and i m facing problem connecting my debit card to the itune store ,as the very option is not there, can someone guide me how to get it connected , i have a mastercard debit card with me .please help me

    hey there! well i from india and i m facing problem connecting my debit card to the itune store ,as the very option is not there, can someone guide me how to get it connected , i have a mastercard debit card with me .please help me

    if you are signed in to iTunes with your AppleID, click on the AppleID > view account > payment information > enter in your information

  • Last time i used FFsync it didnt ask me about any key! there was a phrse only which it didnt work now so i generate a new code as ur guide shows me and now i lost all my data! i need them alot, i adopted on your servies :( i need my data so badly plz help

    Last time i used FFsync it didnt ask me about any key! there was a phrse only which it didnt work now so i generate a new code as ur guide shows me and now i lost all my data! i need them alot, i adopted on your servies :( i need my data so badly plz help

    Lord K.  Thank you. Yes I am within the 90 time period, however I travel Intertionally and I can not receive not make a call to Apple. I was just at the Genius Bar in Chicago and they said, don't worry about it.  It just floats out there, however, I can not recover my messages on a flash drive. I need to go back to my old computer which I don't have with me.  My messages were in folders for a lawsuit.  It is going to take an incredible amount of work for me to, you have no Idea.  We are talking thousands of pages!  I the defendent will have them during discovery so I am not so worried.  However, I can not bring them to him on a Flashdrive when I meet with him without an extraordinary amount of presssure on my part.  THis is not just some little email issue. This is suing EXPEDIA and Tripadviosr.com

  • Does someone out there have the absolute idiots guide of how to backup my calender data?

    Does anyone out there have to idiots guide of how to back up my calender?

    You haven't said, but I'll assume you are using iCloud for your calendars, so here are Apple's instructions for a variety of use cases: http://support.apple.com/kb/HT4910

  • Idiots guide to connecting xp pro to os 10.2 server?

    Anyone have a link for an idiots guide to connecting an xp pro pc to a 10.2 server? I try to use xps network setup - \\servername\foldername hit enter then it asks for a user name and password. I enter our generic building wide user name & pw, it thinks for a while then just pops back up looking for user name & pw. Are there any things in xp that I have to turn on/off for this to work etc?

    10.2 is now seriously dated and will be quite problematic because it's significantly different in many respects from 10.3 and 10.4, making it harder for those with experience with them (10.3 and 10.4) to effectively help.
    If you can at all, I'd try to find a copy of 10.3 Server to purchase.
    Otherwise... you need to setup "Password Server" in 10.2 Server (not running by default) to properly support Windows users. Anything else will be pain.
    And then each Windows user will need to have their password type set to "Password Server" in the “User Password Type popup (see Workgroup Manager).
    You'll want to use the Open Directory Assistant in /Applications/Utilities
    But be sure to read the documentation.
    http://manuals.info.apple.com/AppleSupportArea/Manuals/servers/MacosxserverAdmin10.2.3.PDF
    http://docs.info.apple.com/article.html?artnum=50525
    Message was edited by: davidh

  • JSF and SSL

    I am kind of a new guy to JSF and i have never used SSL or anything similar so forgive me if my question sounds stupid
    I searched the forums for using https in JSF pages but there is no HOw-to guide or something.
    Can anyone let me know what i need in order to make online web application use SSL (import libraries? edit xml?)
    For the record i am currently using Netbeans with a Glassfish server
    Thank you

    SSL is not front-end/web-app dependent, it is application server dependent. Some application server comes out of the box with SSL support, such as Tomcat and Glassfish. For configuring SSL in Glassfish, just read its documentation.
    Here are some pointers: http://www.google.com/search?q=glassfish+ssl

  • Idiots guide to audiobooks

    Is anyone aware of an idiots guide to using audiobooks ?
    I have just started with this and so far am finding dificulties in loading tracks into the audiobook section. At the moment they keep going into the music section and as my immediate priority is books I am ignoring music.
    I also experience difficulty in hearing the books as once a section of say 17 tracks ends it goes back to the begining. If I am listening to say disk 6 on completion it goes back to 5 and restarts from there instead of advancing on to disk 7.
    Can anyone please set me on the right road ?

    See this...
    http://discussions.apple.com/thread.jspa?messageID=607433&#607433
    btabz

  • Please, please, please an idiots guide please!!

    /Please, please, please an idiots guide please!!; I have been fannying around now for 3 days .. how the hell do I transfer a video from my videos to the Zen X-fi thru Centrale? It just does not explain how to do this, I have been clicking and trying to drag and drop for 3 days!
    ?Please explain in a simple , 2, 3 etc not some garbled computer jargon, I wont understand you :-( .. somebody please explain, I'm going nuts here!!
    Also ... what 'format' do I change my videos to out of curiosity to work in a Zen or does Centrale do this once I sort out where I take and put my videos from ... God its confusing, please help Creative!!!

    A [url="http://support.creative.com/kb/ShowArticle.aspx?sid=54748">guide [/url]already exists in the Zen X-Fi support area of the site. Did you try it's
    Since I don't have a Zen X-Fi, and thus don't have or use Centrale, I can't atest to its accuracy or completeness. But at least someone took a stab at it. There also appears to be a stand-alone video converter application available in the Zen X-Fi download area.
    Regarding your "format" question, that isn't easy to answer without involving the jargon you asked be avoided. Modern video "formats" aren't simple. They are basically containers that hold other things (namely the video stream and the audio stream). The video stream and audio stream are encoded separately using completely unrelated techniques. They are then bundled together under a "wrapper" like AVI, M4V, etc. Thus you need to know specifically what coder-decoders (codecs) were used to create the internal streams and what codecs the player itself supports.
    An analogy can be found in chinese "buns". Externally they all look alike, but in one case the filling could be a sweet rice paste and in another it could be octopus. Knowing what's inside can make all the difference.

  • Please , help me for apple id.......  i made new id but there is a credite card option and that's why i am not able to download any free application for iphone,.....so,.....what i do about this problem..???

    please , help me for apple id.......  i made new id but there is a credite card option and that's why i am not able to download any free application for iphone,.....so,.....what i do about this problem..???

    You can create an Apple ID without a credit card by following this guide exactly: http://support.apple.com/kb/ht2534.  Note that you have to start by downloading a free app, then create the ID.

  • Is there a compatibility guide for SSDs in the late 2011 macbook pro model?

    Is there a compatibility guide for SSDs in the late 2011 macbook pro model? I'm looking to purchase a 15.4" Late 2011 Macbook pro and was looking a SATA3 SSD that was supported (outside of the ones provided by Apple). Does anyone have any success stories they wish to share? I assume the problem with secondary bay and SATA3 has still not been resolved.

    Have you looked at the OWC web site?  They specialize in Mac peripherals and they have a good line of SSDs and secondary bays as well.  My experience with them has been good but I am not ready for SSDs.  For my needs the cost/benefits are not there.
    Ciao.

  • JSP, JSF, and ADF

    I've just started playing around with this and was looking for samples/tutorials to help. Of the tutorials/samples I've seen, they appear to fall short of explaining an end-end example and stick mostly to JSF and the backing bean - usually displaying static data within a JSP and navigation. I'm a bit confused on how to call custom methods in my business services (application modules) and in turn use the view objects to fetch data from my database and display the results within a JSP using the JSF components.
    I realize the latest preview JDeveloper is without ADF but while I had time I was hoping to play around with ADF Faces to hit my development database. Guess I'm trying to make sense of how JSP, JSF, Business components, and my db connection all play together in order to set up a decent starting point for an app.

    You could use Jdeveloper 10G and play around with ADF Faces, look at the demos, and the sources behind them.
    There are a couple of papers on OTN like...
    Working with ADF Faces in JDev 10g:
    http://www.oracle.com/technology/products/jdev/howtos/10g/adfjsf/how-to-adf-faces-10gjdev.htm
    Roadmap for ADF Faces:
    http://www.oracle.com/technology/products/jdev/collateral/papers/9.0.5.0/adfuix_roadmap/adfuix_roadmap.html
    And many more... as I could find upon search...
    http://www.oracle.com/ultrasearch/wwws_otn/searchotn.jsp?p_Action=Search&p_Query=adf+faces
    The visual editing support for 'The ADF Model access through ADF Faces bindings' is under development (hence no tutorials), and will be available in future release (could be post 10G release).
    -Udupa

  • How to persist parent  and child tree node data through JSF and Hibernate

    Dear dudes,
    I'm a novice to JSF and Hibernate
    Actually i want to create a tree structure where for each child node, i should have the parent node reference in my form and then when i save, i need to save the corresponding child node data in the database.
    node-1
      node 1-1
         node 1-11a
      node 1-2
    node-2
       node 2-1
       node2-2Whenever i click node 1-1 the corresponding parent node ( node-1) reference should appear in my form and when i save this data this data should be saved under parent node and the tree should be re-rendered.
    How this can be accomplished and if there are any URL's please refer.

    Everybody need not face the same problem you faced. And moreover, everyone out here have their own issues to solve. If people are helping out here, its cause of their passion. Please try to be polite.
    First of all, what is that you have tried on the issue? Could you please share your work so that we can try to fill the gaps?

  • Can any one tell me what is JSF and where  why is it used

    hi
    can any one give me a brief introduction on JSF and where and why is it used.. if there is any good tutorial/documentation pls give me the links
    sanjay

    Java Server Faces Resources (by James Holmes):
    http://www.jamesholmes.com/JavaServerFaces/
    JavaServer Faces FAQ (by Kito D. Mann):
    http://www.jsfcentral.com/

  • Is there a user guide for Robohelp 7?

    I've used Robohelp before, but now am faced with having to create a stylesheet.  I've tried using the Help but it seems to make assumptions that I've done created .css before.  For example, the kinds of things that I can find no information on:
    What is the Design Editor?  I can't seem to find it to be able to create an external style sheet.
    In the "Create a style sheet" topic, you must first click style sheet, but the style sheet button isn't enabled.
    Bottom line: I'm looking for all inclusive documentation that will give me concepts and procedures for creating a style sheet.
    Thanks for your assistance.

    Thank you so much for sharing these resources with me.  I have viewed
    Adobe's tutorials on a number of topics and where their documentation
    falls short of the mark, the tutorials are excellent.  I can't wait to dig
    into them.
    ~~~~~~~~~~~~~~~~~~~~~~~~
    Mary K. Greer
    Information Developer - Learning Management Solutions
    Intelligent Automation Solutions Client Services
    407.771.8187
    lwright18 <[email protected]>
    07/21/2009 01:22 PM
    Please respond to
    [email protected]
    To
    Mary Greer/CIMG/CVG@CVG
    cc
    Subject
    Is there a user guide for Robohelp 7?
    Hi..
    I COMPLETELY understand your frustration, because i've just gone through
    the same ordeal.
    Its impossible to figure out how to import frame files into RH and how to
    use style sheets from the on-line help, because as you said, you only get
    bits and pieces of information out of context, and many of the
    descriptions of settings don't explain what they are for/do. Its the same
    old paradox; the only way you can understand the on-line help is if you
    already understand the product; in which case you wouldn't need the online
    help. 
    What finally helped me to get a basic grasp of the mysteries of style
    sheets, etc. was the tutorial: "Adobe Technical Communication Suite
    Getting Started series - Part 3: FrameMaker 8 and RoboHelp7: …" @
    http://www.adobe.com/devnet/robohelp. (it runs about an hour and a half).
    It explains how to enter and apply custom style sheet settings, mapping,
    etc. and should probably clear up your confusion.
    The only thing I STILL not certain about though, is what relationship, if
    any, template (.htt) files have to do with anything, and whether they
    relate to .css files. So i'd appreciate it if another poster can shed some
    enlightenment on that.

Maybe you are looking for

  • Can't add spry in a template-based page

    Hi, I am working with DW CS3 and building content for a page created from a template. I made sure i clicked in editable place before inserting the spry but DW keeps feeding back an error message asking to unlock the head tag or adding the spry direct

  • How to modify  a table without  setting system to modifiable

    Hi All Is there a way to modify a table without setting the system to modifiable either in SCC4 or SE06. We locked SCC4 in our system , however one tables are not able to modify. table name YAUTM Is there a way to bypass this? Edited by: Shou Woon We

  • Cannot view photos in iPhoto 09

    I have iLife 09 and am new to the Mac world. I am wondering why iPhoto will not allow me to see pictures I was once able to. I used some of my photos in iMovie and iDVD, and they worked just fine. I went back in to view the pictures and edit them for

  • Download link not available for second download

    I am trying to download lightroom on a second computer.  When I go into my orders and click on downloads, the link isn't available.  Not sure what to do

  • How do I set a song from my music folder as a ringtone?

    I have downloaded a song onto my phone from iTunes but I cannot find a way to set it as my ringtone. It was not downloaded as a ringtone, just as a song. Is this something that can be done?