How do I get and set cookies with JSF?

How do I get and set cookies in a JSF managed bean?
Regards,
Al Malin

Below is how I did it...I am receptive to improvements.
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)facesContext.getExternalContext().getSession(false);
HttpServletRequest request = (HttpServletRequest)facesContext.getExternalContext().getRequest();
HttpServletResponse response = (HttpServletResponse)facesContext.getExternalContext().getResponse();
String cookieName = "myCookieName";
Cookie requestCookie = null;
Cookie[] cookies = request.getCookies();
logger.info("looking for cookie...");
if (cookies != null)
for (int i = 0; i < cookies.length; i++)
if (cookies.getName().equals(cookieName))
requestCookie = cookies[i];
logger.info(cookieName + " = " + requestCookie.getValue());
logger.info("done looking for cookie");
Cookie responseCookie = new Cookie(cookieName, "myCookieValue");
responseCookie.setPath("/");
response.addCookie(responseCookie);

Similar Messages

  • How do I get and set column attributes in a table or a treetable with Java?

    Using 11.1.1.4.0
    Hi,
    How do I get and set column attributes in a table or a treetable with Java? For a simple example, say I have a table and want certain roles to see all columns (including address), and other roles can see only certain columns (no address). In a Java method, I want to test if a table's column visible attribute is true and if so, set it to false before rendering it.
    Thanks in advance,
    Troy

    Hi,
    this use case would be a perfect example for using seeded MDS customization. Instead of checking what users are allowed to see or not upon rendering time, you have a customization class and thus the framework doing this for you.
    http://www.oracle.com/technetwork/developer-tools/adf/learnmore/31-mds-sample-169173.pdf
    In this paper and sample, specific users see different layouts. It also contains a customization class that shows how this can leverage ADF Security
    Frank

  • How do I get and set the double field in a Double?

    Thanks - this has to be easy but I cant find documentation

    It's immutable, so you have to provide the value when you create it:
    Double a = new Double(18.76);
    Double b = new Double("18.76");
    Double c = Double.valueOf(18.76);
    Double d = Double.valueOf("18.76");
    Double e = Double.parseDouble("18.76");Going from Double to double is easy -- I'm surprised you didn't see it in the API:
    double x = a.doubleValue();Again, Doubles are immutable, so there is no way to change the double value of a Double object.

  • How to get and set custom tag attributes

    How do i get and set custom tag attributes from a jsp page?

    Not sure if this is what your looking for, but....
    example...
    < taglibprefix:testtag attribute1="x" attribute2="y">
    ...of course, the attributes have to be defined in your taglib (.tld) file

  • My main PC with my Itunes Library just crashed.  I still have all my music on Apple TV, Ipod Touch (Gen 2), and Iphone 4 (verizon).  How can I get everything set up on a new PC and working ?

    My main PC with my Itunes Library just crashed.  I still have all my music on Apple TV, Ipod Touch (Gen 2), and Iphone 4 (verizon).  How can I get everything set up on a new PC and working ?

    I downloaded Itunes 10.2 on new desktop, ran sync with my ipod touch (Gen 2) and have all my music on new PC.  Just can't get it to sync with my Apple TV (Gen1).  I have made music purchases on Apple TV and cannot get them to Ipod/Iphone?  Help

  • My old appleID use email with domain already deactivate. So I changed my appleID and primary email and now I can not access iCloud with iOS7. ICloud shows my old appleID but I can't change it. How do I get iCloud to work with my updated ID?

    My old email that using register for apple ID cannot access/check any mail because that domain already deactivate.
    So I changed my appleID and primary email and now I can not access iCloud with iOS7. ICloud shows my old appleID but I can't change it. How do I get iCloud to work with my updated ID?

    Hi ccharat,
    Welcome to the Apple Support Communities! It sounds like you did a good job editing your Apple ID and primary email address, but you didn’t sign out of iCloud on your iOS device before hand. What you may need to do in this situation is go back to the Apple ID website and edit your Apple ID and primary email address back to the email address that is signed in with iCloud (there is no need to verify the account after editing it back to the old account, just changing it back is enough). Once your Apple ID is back to the original account, delete the iCloud account from the iOS device and be sure to keep all info on the device when prompted. After you delete the iCloud account, go back to the website and edit your Apple ID and primary email address back to the new address. Once it is back to the account you would like, you can sign into the iCloud on the iOS device with that new account and merge all of the data when prompted. Please use the following article as a reference.
    iOS 7: If you're asked for the password to your previous Apple ID when signing out of iCloud
    http://support.apple.com/kb/ts5223
    Change your Apple ID temporarily
    If signing out and back in to iMessage or FaceTime didn't help, try these steps:
    Change your Apple ID to the Apple ID you used previously. You shouldn't need to verify the email address.
    Go to Settings > iCloud. Complete these steps only if the Find My [Device] setting is turned on:
    Scroll down and tap Delete Account, then tap Delete to confirm.
    Tap “Keep on My [Device]” or “Delete from My [Device].” In either case, your data remains in iCloud and will be updated on your device when you sign in to iCloud again.
    Enter the password for your previous Apple ID.
    Change your Apple ID to the new email address that you want to use. You'll need to verify the email address.
    Return to Settings > iCloud and sign in with your new Apple ID.
    I hope this helps,  
    -Joe

  • My iPod Classic is seen by Windows but not by iTunes.  I have reset it, gone to disk mode and it won't show up in iTunes.  There appears to be music on it in a file called MUSICSAVE.  How can I get this to work with iTunes again?

    My iPod Classic is seen by Windows but not by iTunes.  I have reset it, gone to disk mode and it won't show up in iTunes.  There appears to be music on it in a file called MUSICSAVE.  How can I get this to work with iTunes again?

    1. Update iTunes to the latest version. Plug in your iPod. If iTunes still can't recognize it, then in iTunes in the top left corner click help> run diagnostics. On the box that comes up, check the last two things. Click next and it should identify your iPod.
    2. Click on your windows start menu. Type in "services". Click on it and when it pops up, on the bottom of it click on "standard". Now Scroll down to find "Apple Mobile Device" Right click it when you see it and click on "Start". When it has started, close iTunes and replug in your iPod and it should show up.
    3. Check the USB cable
    4 Verify that Apple Mobile Device Support is installed
    5. Restart the Apple Mobile Device Service and verify that the Apple Mobile Device USB Driver is installed.
    6. If you just want to add some photos, songs and movies from computer to your devices, you can use an iTunes alternative to do the job
    7. Check for third-party software conflicts.
    <Link Edited By Host>

  • Acrobat 7, needed with FrameMaker 7: How do I get and install an "Adobe PDF printer instance?"

    In FrameMaker, when I try to save a FrameMaker file as a PDF file, I get the following message: "FrameMaker could not find Adobe PDF printer instance, which must be installed to execute "Save as PDF" command".  I have a sinking feeling that I deleted that printer instance from my list of printers, thinking I did not need such a printer. I have tried uninstalling and reinstalling FrameMaker 7, Acrobat 7 and Reader 9. All reinstalled successfully, EXCEPT still no Adobe PDF printer instance. Thus my question: how do I get and install that Adobe PDF printer instance?
    .( I am using a new computer. I still have my old computer available, with the Adobe PDF printer instance on it. If I could find where in the old machine (Windows XP)  the files are for it, I could copy them to the new machine).
    Thanks in advance  for any advice.

    Just curious,
    What is the new machine's OS (& is it 32-bit or 64-bit)?
    Be well...

  • When I go to update and it gets to the backup part it gives me error -43 and says to complete it it will take all the stuff off my iPod how do I get it to update with out loosing everything on my 64 gb iPod touch

    When I go to update and it gets to the backup part it gives me error -43 and says to complete it it will take all the stuff off my iPod how do I get it to update with out loosing everything on my 64 gb iPod touch

    You have a 1st generation iPod Touch.
    It can be updated to 3.1.3 by purchase. See here Purchasing iOS 3.1 Software Update for iPod touch (1st generation)

  • How do I get iCloud to work with my mac that has snow lepard and is pre intel?

    How do I get iCloud to work with my mac that has snow lepard and is pre intel?

    Richard Kerns wrote:
    And it kills me that a friend who has pc computers and just has an iphone and ipad can breeze through all this with no problem and he still has XP.  So Apple goes back and helps old OS for pc but not for it's own kind!!!
    Richard, I agree with you 1,000%. I wrote this in a forum a few weeks ago, when a user was complaining about Snow Leopard not supporting iCloud:
    Why is it that if I bought a Mac before July of this year, I must pay to upgrade my operating system in order to take advantage of iCloud? Meanwhile, a Windows Vista SP2 user, who bought a new computer in May 2009, already has everything they need on their computer to use iCloud.
    Why was it possible for Apple to write a free iCloud Control Panel that was compatible with existing versions of Windows, but Mac users must buy an entirely new operating system?
    If Apple gave Mac users the same amount of backwards compatibility that it gives to Windows users, people with OSX 10.5 (Leopard) would be able to use iCloud. That's something to think about the next time you go to purchase a new computer.
    (P.S. Something else to think about: If you bought a Mac before October 2007 (when OSX 10.5 was introduced), your computer won't run iTunes 10.5 unless you buy an upgrade. But a PC user, who purchased their computer as long ago as Sept. 2004(!), can run iTunes without an OS upgrade.)
    I got so angry thinking about this, that I ended up writing an angry note to Apple on their feedback page. After repeating what I just wrote here, I asked them to commit to providing at least the same level of support to Mac users that they do for PC users when it comes to their cross platform products (iPhone, iPad, iCloud, Apple TV, Safari, iTunes, etc.) And, really, is that so much to ask?
    I wish I knew how to start a petition requesting that Mac users get comparable treatment as PC users. But then again, shouldn't that go without saying?
    Please leave feedback about this revolting double standard on the Apple feedback page. They should be thinking long and hard about why their own customers are treated worse than the customers of their competition.

  • Dear Customer Service Team,  I bought a twelve-month Dreamweaver CC program with monthly payment that I have paid via bank transfer and there would be a question about the activation. How could I get the license key with which I can activate my account? I

    Dear Customer Service Team,
    I bought a twelve-month Dreamweaver CC program with monthly payment that I have paid via bank transfer and there would be a question about the activation. How could I get the license key with which I can activate my account? I can not find it and now I only have access to the trial version.
    Thank you for your help in advance.
    Kind Regards,
    G. Zsolt

    There is no serial number require for Creative Cloud products, you may activate the products using your email address and password which is associated with Adobe. If your Dreamweaver asking for serial number, then make sure you are signing in with correct email address.
    You may also refer below link
    Sign in, activation, or connection errors | CS5.5 and later

  • Email messages from my icloud account update on all my devices showing if they have been read and if a reply has been sent.  This does not happen with my tinyworld (TalkTalk) email account.  Can I (how can I) get this to work with TinyWorld?

    Email messages from my icloud account update on all my devices showing if they have been read and if a reply has been sent.  This does not happen with my tinyworld (TalkTalk) email account.  Can I (how can I) get this to work with TinyWorld?

    You have to look at the email protocol being used.  the Apple email system uses IMAP, does Tinyworld use IMAP or POP?
    Does the email system permit delivery receipts to be requested?
    Just some of the things one needs to determine from the information provided by the email service provider.

  • I lost my iphone, got a new sim card and put it in my boyfriend's old iphone. When I synch it in itunes it will only synch with his stuff and not mine. Any ideas how I can get it to synch with my itunes??

    I lost my iphone, got a new sim card and put it in my boyfriend's old iphone. When I synch it in itunes it will only synch with his stuff and not mine. Any ideas how I can get it to synch with my itunes??

    Are you using a Mac? It sounds like you are using his computer to sync to. If this is the case, then it will sync to all of his stuff unless a new user is created with your personal stuff on it.
    When you want to sync your iPhone to that computer, switch to your user first, and then everything will sync with your stuff. If he wants to hook up his iPhone to sync it, then he needs to switch back to his own username first.

  • HT1766 I have had this i-phone almost a year and the last update crashed it.  I back up to i-cloud but this is not a new phone.  How do I get into set-up to restore from i-cloud?

    I have had this i-phone almost a year and the last update crashed it.  I back up to i-cloud but this is not a new phone.  How do I get into set-up to restore from i-cloud?

    From your OLD computer...
    Copy your ENTIRE iTunes FOLDER to an External Drive... and then from the External Drive to your New Computer..
    Full Details Here  >  http://support.apple.com/kb/HT1751
    Also see this migrate iTunes library post by turingtest2

  • We've had our MBP for a year, set up with my Apple ID. Got an iPad recently and set up with another Apple ID. Would now like to sync the two and set up iCloud/PhotoStream. How to do since have two different Apple IDs?

    We've had our MBP for a year, set up with my Apple ID. Got an iPad recently and set up with husband's Apple ID. Would now like to sync the two and set up iCloud/PhotoStream between the two. How to do since have two different Apple IDs? Thanks!

    Just out of curiosity, why did you elect to use a different id?.  That seems to always make things difficult.  If you have not had the pad for long, or have not bought a lot of stuff Nader the new id, you might want to think about erasing all content, turn off find my phone, wiping the pad and starting over.
    You can sync 2 different ids ( at least move pictures, books and music back and forth) if you are syncing through I tunes on your computer, but I don't think you can cross feed I cloud streams.

Maybe you are looking for