The Source for Java Technology Collaboration
User: Password:



Ed Burns

Ed Burns's Blog

Using JSP Immediate Expressions to access JSF Data

Posted by edburns on March 15, 2006 at 10:48 AM | Comments (7)

Here is an ultra-quick blog entry sharing something in JSF 1.2 about which I'm not sure many people are aware. Thanks to the unified EL, it is possible to refer to JSF managed beans and other JSF concepts using plain old JSP expressions in the page. For example, let's say you have a JSF app that is a bookstore. In the app is a managed bean that is a Map where the keys are ISBN numbers and the values are Book JavaBeans that have properties like author, title, ISBN, etc.

In JSF 1.1, to display any information from the book Map, you had to use JSF components. In JSF 1.2, you can use plain old JSP ${} expressions to access this data, like this:


The title is ${books["0072262400"].title}.  

Even though books is a managed bean, you can still access it without JSF.

Keep in mind that you can also access all the implicit objects, including JSF ones, in this manner. For example, if you wanted to use EL to get the locale of the current view, you could say:

${view.locale}

As a final example, if you wanted to get the remote user name of the current user using standard Servlet authentication APIs you could say:

${facesContext.externalContext.remoteUser}

Basically anything that conforms to JavaBeans naming conventions and is accessible from the FacesContext or UIViewRoot can be reached via the EL in this way.

Technorati Tags:

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first)

  • actually, to clarify this, you can't use contextual EL in this manner-- like inlining ${employee.name} within a dataTable. This can be done with a simple fix to JSF's implementation and setting the 'deferredSyntaxAllowedAsLiteral' page property in JSP 2.1 to get 'render-time' evaluation of inlined text w/ #{...} vs. build-time evaluation with the common ${...} syntax.

    Posted by: jhook on March 15, 2006 at 01:05 PM

  • hey,Edburns,when do JSF 1.2 release?I have waited it for two years.
    Actually,I think hybrid Programming(EL\JSTL\JSF) is very important in JSF 1.2.But must waiting for Glassfish or JBoss seam,still waiting...

    Posted by: forsoft on March 16, 2006 at 06:39 AM

  • JSF 1.2 will have its final release this Spring. As you know, however, it is currently available in the Java EE SDK at http://java.sun.com/javaee/downloads/

    Ed

    Posted by: edburns on March 16, 2006 at 11:22 AM


  • JH> actually, to clarify this, you can't use contextual EL in this
    JH> manner-- like inlining ${employee.name} within a dataTable. This
    JH> can be done with a simple fix to JSF's implementation and setting
    JH> the 'deferredSyntaxAllowedAsLiteral' page property in JSP 2.1 to
    JH> get 'render-time' evaluation of inlined text w/ #{...}
    JH> vs. build-time evaluation with the common ${...} syntax.


    Yes, I see, Jacob. I have simply inlining ${customer.name} into a
    dataTable demo I have and found that it does not work in the data table
    case. However, I do want to point out that one can use immediate
    expressions to reference JSF managed beans in all other cases than the
    data table case.

    Ed - JSF co-spec lead

    Posted by: edburns on March 31, 2006 at 05:29 AM


  • JH> actually, to clarify this, you can't use contextual EL in this
    JH> manner-- like inlining ${employee.name} within a dataTable. This
    JH> can be done with a simple fix to JSF's implementation and setting
    JH> the 'deferredSyntaxAllowedAsLiteral' page property in JSP 2.1 to
    JH> get 'render-time' evaluation of inlined text w/ #{...}
    JH> vs. build-time evaluation with the common ${...} syntax.


    Well, Jacob, I played around a bit with your suggestion and found
    that the fix to the JSF impl isn't so simple. I gather you're
    suggesting we special-case the ValueExpression callsites in the JSF tag
    layer to check:


    if isLiteral
    then
    See if the literal happens to be a real #{ } expression. If it does
    create a real (non-literal) expression from it, the way we do
    in jsf 1.1.


    This approach has problems because the places where you'd have to do
    this check are numerous. Furthermore, once you do the check you'd need
    some way to have the #{employee.name} value actually get turned into a
    real (non-literal) expression. I think we could do this
    because of the content-interweaving solution where the template text
    would be turned into a UIOutput. Therefore, we could modify the code
    that turns the template text into a UIOutput to actually turn it into an
    ValueExpression and set that as the value of the UIOutput. As a
    performance optimization, we could have that code inspect the literal
    text value to see if it contains any #{ characters and only then turn it
    into an expression.

    This is worth investigating further. I've created issue 164
    in the jsf-api public issue tracker and attached my change-bundle so
    far.

    Ed (JSF co-spec-lead)

    Posted by: edburns on March 31, 2006 at 06:30 AM

  • This approach has problems because the places where you'd have to do this check are numerous. Furthermore, once you do the check you'd need some way to have the #{employee.name} value actually get turned into a real (non-literal) expression. I think we could do this because of the content-interweaving solution where the template text would be turned into a UIOutput. Therefore, we could modify the code that turns the template text into a UIOutput to actually turn it into an ValueExpression and set that as the value of the UIOutput. As a performance optimization, we could have that code inspect the literal text value to see if it contains any #{ characters and only then turn it into an expression.


    acrobat
    ad-aware ad-aware
    adulte
    amateur
    amateur2
    amatrice
    anal
    antivirus
    antivirus-gratuit
    anus
    ares
    asian
    asiatique
    ass
    astuce
    auto
    avatar
    avatars
    baise
    bebe
    beurette
    bikini
    bisexuel
    bite
    black
    blague
    blagues
    blonde
    boob
    brune
    carte
    carte2
    carte3
    cartes
    cartes2
    cartes3
    celebrite
    chaleur
    chanson-gratuit


    chansons-gratuit
    charme
    chat-gratuit
    cheat
    cinema
    clip-gratuit
    clitoris
    clone
    cochon
    code-jeu
    coquin
    couille
    couple
    cul
    cul-gratuit
    diaporama
    diaporamas
    divx
    divx-gratuit
    download
    ecran-de-veille
    ecran-de-veille-gratuit
    ecrans-de-veille
    edonkey
    emoticone
    emoticone-gratuit
    emoticones
    emule
    emule-gratuit
    enculer
    enfant
    erotique
    erotiques
    erotisme
    etudiante
    exhibitionniste
    f1-rallye
    familiale
    famille


    fellation
    femme
    femme2
    fesse
    fetiche
    fetichisme
    film
    film2
    film-gratuit
    film-porno-gratuit
    films
    film-x-gratuit
    firefox
    fond-d-ecran
    fond-d-ecran-gratuit
    fonds-d-ecran
    football
    gay
    gay-gratuit
    girl
    golf
    gratuit
    gratuit2
    gratuit3
    gratuite
    gratuite2
    gratuite3
    gros
    grosse
    gros-sein-gratuit
    hard
    hardcore
    hentai-gratuit
    histoire
    homosexuel
    horoscope
    horoscope-gratuit
    horoscopes
    hot


    humour
    icone
    icq
    illusion
    image
    image2
    image-humour
    jeu
    jeu2
    jeu-adulte-gratuit
    jeu-de-voiture-gratuit
    jeu-enfant-gratuit
    jeu-gratuit
    jeu-gratuit-cadeaux
    jeune
    jeu-pc-gratuit
    jeu-video-gratuit
    jeux
    jeux2
    kazaa
    kazaa-gratuit
    latinas
    lesbian
    lesbienne
    limewire
    lingerie
    logiciel
    logiciel2
    logiciel-gratuit
    logiciels
    logiciels2
    logiciels-gratuit
    manga
    massage
    mature
    messenger
    messenger-gratuit
    models
    morpheus

    movie
    mp3-gratuit
    msn
    msn-gratuit
    mure
    music-gratuite
    musique-gratuite
    musiques-gratuites
    nero
    nero-gratuit
    noire
    nu
    nude
    nudiste
    orgasme
    orgie
    parole-gratuit
    paroles-gratuit
    partition
    partitions
    penis
    photo
    photo2
    photo-gay-gratuit
    photo-porno-gratuit
    photo-sexe-gratuit
    photo-sex-gratuit
    pied
    pipe
    poitrine
    porn
    porn-gratuit
    porno
    porno2
    pornographie
    porno-gratuit
    pps-ppt
    programme
    pussy


    rasee
    real-player
    recette
    recettes
    rousse
    sado
    safari
    salope
    sex
    sex2
    sexe
    sexe2
    sexe-amateur-gratuit
    sexe-gratuit
    sex-gratuit
    sex-gratuit-beurette
    sexuelle
    sexy
    shareaza
    skype
    sms-gratuit
    sodomie
    soluce
    solution-jeu
    spectacle
    sport
    sportive
    spybot
    suce
    suceuse
    sudoku-gratuit
    tarot
    tarot-gratuit
    tatouage
    tatouages
    teen
    tele
    telechargement
    telechargement2


    telechargement-antivirus
    telechargement-chanson
    telechargement-chansons
    telechargement-divx
    telechargement-emule
    telechargement-film
    telechargement-film-gratuit
    telechargement-gratuit
    telechargement-kazaa
    telechargement-logiciel
    telechargement-logiciel-gratuit
    telechargement-logiciels
    telechargement-messenger
    telechargement-movie
    telechargement-mp3
    telechargement-msn
    telechargement-music
    telechargement-musique
    telechargement-nero
    telechargement-parole
    telechargement-paroles
    telechargement-porn
    telechargement-porno
    telechargement-sex
    telechargement-sexe
    telechargement-x
    telechargement-xxx
    telecharger
    telecharger2
    telecharger3
    telecharger-antivirus
    telecharger-antivirus2
    telecharger-chanson
    telecharger-chansons
    telecharger-divx
    telecharger-emule
    telecharger-film
    telecharger-gratuit
    telecharger-jeu-gratuit


    telecharger-kazaa
    telecharger-logiciel
    telecharger-logiciels
    telecharger-messenger
    telecharger-movie
    telecharger-mp3
    telecharger-msn
    telecharger-music
    telecharger-musique
    telecharger-nero
    telecharger-parole
    telecharger-paroles
    telecharger-porn
    telecharger-porno
    telecharger-sex
    telecharger-sexe
    telecharger-x
    telecharger-xxx
    television
    tennis
    tit
    toon
    tourisme
    touristique
    tout-gratuit
    traducteur-gratuit
    transsexuelle
    truc
    tuning
    tv
    vacances
    video

    video2
    video-comique
    video-gratuit
    video-porno
    video-porno2
    video-porno-gratuit
    videos
    videos2
    videos-comiques
    video-sexe-gratuit
    video-sex-gratuit
    video-x-gratuit
    vlc
    voiture
    voyage
    voyager
    voyeur
    wallpaper
    webcam
    winamp
    winmx
    winrar
    winzip
    x
    x2
    x-gratuit
    xxx
    xxx-gratuit
    yoga

    acrobat
    ad-aware ad-aware
    adulte
    amateur
    amateur2
    amatrice
    anal
    antivirus
    antivirus-gratuit
    anus
    ares
    asian
    asiatique
    ass
    astuce
    auto
    avatar
    avatars
    baise
    bebe
    beurette
    bikini
    bisexuel
    bite
    black
    blague
    blagues
    blonde
    boob
    brune
    carte
    carte2
    carte3
    cartes
    cartes2
    cartes3
    celebrite
    chaleur
    chanson-gratuit


    chansons-gratuit
    charme
    chat-gratuit
    cheat
    cinema
    clip-gratuit
    clitoris
    clone
    cochon
    code-jeu
    coquin
    couille
    couple
    cul
    cul-gratuit
    diaporama
    diaporamas
    divx
    divx-gratuit
    download
    ecran-de-veille
    ecran-de-veille-gratuit
    ecrans-de-veille
    edonkey
    emoticone
    emoticone-gratuit
    emoticones
    emule
    emule-gratuit
    enculer
    enfant
    erotique
    erotiques
    erotisme
    etudiante
    exhibitionniste
    f1-rallye
    familiale
    famille


    fellation
    femme
    femme2
    fesse
    fetiche
    fetichisme
    film
    film2
    film-gratuit
    film-porno-gratuit
    films
    film-x-gratuit
    firefox
    fond-d-ecran
    fond-d-ecran-gratuit
    fonds-d-ecran
    football
    gay
    gay-gratuit
    girl
    golf
    gratuit
    gratuit2
    gratuit3
    gratuite
    gratuite2
    gratuite3
    gros
    grosse
    gros-sein-gratuit
    hard
    hardcore
    hentai-gratuit
    histoire
    homosexuel
    horoscope
    horoscope-gratuit
    horoscopes
    hot


    humour
    icone
    icq
    illusion
    image
    image2
    image-humour
    jeu
    jeu2
    jeu-adulte-gratuit
    jeu-de-voiture-gratuit
    jeu-enfant-gratuit
    jeu-gratuit
    jeu-gratuit-cadeaux
    jeune
    jeu-pc-gratuit
    jeu-video-gratuit
    jeux
    jeux2
    kazaa
    kazaa-gratuit
    latinas
    lesbian
    lesbienne
    limewire
    lingerie
    logiciel
    logiciel2
    logiciel-gratuit
    logiciels
    logiciels2
    logiciels-gratuit
    manga
    massage
    mature
    messenger
    messenger-gratuit
    models
    morpheus


    movie
    mp3-gratuit
    msn
    msn-gratuit
    mure
    music-gratuite
    musique-gratuite
    musiques-gratuites
    nero
    nero-gratuit
    noire
    nu
    nude
    nudiste
    orgasme
    orgie
    parole-gratuit
    paroles-gratuit
    partition
    partitions
    penis
    photo
    photo2
    photo-gay-gratuit
    photo-porno-gratuit
    photo-sexe-gratuit
    photo-sex-gratuit
    pied
    pipe
    poitrine
    porn
    porn-gratuit
    porno
    porno2
    pornographie
    porno-gratuit
    pps-ppt
    programme
    pussy

    rasee
    real-player
    recette
    recettes
    rousse
    sado
    safari
    salope
    sex
    sex2
    sexe
    sexe2
    sexe-amateur-gratuit
    sexe-gratuit
    sex-gratuit
    sex-gratuit-beurette
    sexuelle
    sexy
    shareaza
    skype
    sms-gratuit
    sodomie
    soluce
    solution-jeu
    spectacle
    sport
    sportive
    spybot
    suce
    suceuse
    sudoku-gratuit
    tarot
    tarot-gratuit
    tatouage
    tatouages
    teen
    tele
    telechargement
    telechargement2


    toc

    telechargement-antivirus
    telechargement-chanson
    telechargement-chansons
    telechargement-divx
    telechargement-emule
    telechargement-film
    telechargement-film-gratuit
    telechargement-gratuit
    telechargement-kazaa
    telechargement-logiciel
    telechargement-logiciel-gratuit
    telechargement-logiciels
    telechargement-messenger
    telechargement-movie
    telechargement-mp3
    telechargement-msn
    telechargement-music
    telechargement-musique
    telechargement-nero
    telechargement-parole
    telechargement-paroles
    telechargement-porn
    telechargement-porno
    telechargement-sex
    telechargement-sexe
    telechargement-x
    telechargement-xxx
    telecharger
    telecharger2
    telecharger3
    telecharger-antivirus
    telecharger-antivirus2
    telecharger-chanson
    telecharger-chansons
    telecharger-divx
    telecharger-emule
    telecharger-film
    telecharger-gratuit
    telecharger-jeu-gratuit


    telecharger-kazaa
    telecharger-logiciel
    telecharger-logiciels
    telecharger-messenger
    telecharger-movie
    telecharger-mp3
    telecharger-msn
    telecharger-music
    telecharger-musique
    telecharger-nero
    telecharger-parole
    telecharger-paroles
    telecharger-porn
    telecharger-porno
    telecharger-sex
    telecharger-sexe
    telecharger-x
    telecharger-xxx
    television
    tennis
    tit
    toon
    tourisme
    touristique
    tout-gratuit
    traducteur-gratuit
    transsexuelle
    truc
    tuning
    tv
    vacances
    video

    video2
    video-comique
    video-gratuit
    video-porno
    video-porno2
    video-porno-gratuit
    videos
    videos2
    videos-comiques
    video-sexe-gratuit
    video-sex-gratuit
    video-x-gratuit
    vlc
    voiture
    voyage
    voyager
    voyeur
    wallpaper
    webcam
    winamp
    winmx
    winrar
    winzip
    x
    x2
    x-gratuit
    xxx
    xxx-gratuit
    yoga

    Posted by: keriolder on March 04, 2007 at 02:55 PM

  • This is really great. I think Unified EL + content interweaving in JSF 1.2 bring a LOT of value a HTML and dynamic content generated by JSF artifacts are so easy to integrate in a JSF page. No more verbatim just plain HTML. Wonderful !!!

    Currently we are using JSF 1.1 and to address this handicap of not being able to use JSF EL in template text we did this:
    1. Created a TLD function that returns an Object and has a String argument
    2. Function creates a ValueBinding out of the argument and ultimately evaluates the expression.


    it looks something like

    ${e:jsfEL('#{MyBean.name}')}

    and can be used anywhere in the page. The syntax is a bit long, but it solves the problem but with JSF 1.2 and JSP 2.1 goodies we can use this much more naturally.

    Thank you,
    Marius

    Posted by: marius_danciu on August 12, 2007 at 04:26 AM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds