1 2 Previous Next 22 Replies Latest reply on Sep 14, 2011 9:44 AM by ionutbarau

    EL expression for id attributes?

    grimholtz

      Hi,

      Is there any way to use an EL expression for id and viewId attributes? Example:

      <a4j:commandButton id="#{fooBean.id}" />
      


      <a4j:include viewId="#{barBean.viewId}" />
      


      Thank you for any advice,
      grimholtz

        • 1. Re: EL expression for id attributes?

           

          "grimholtz" wrote:

          <a4j:commandButton id="#{fooBean.id}" />
          


          Yes. but only if you use Facelets. However, ${fooBean.id} is possible in case of JSF 1.2 (with Facelets or not)

          "grimholtz" wrote:


          <a4j:include viewId="#{barBean.viewId}" />
          


          Yes

          • 2. Re: EL expression for id attributes?
            grimholtz

            Hi Sergey,

            I'm using Facelets and JSF 1.2, but in both examples the id resolves to null. But I know the id isn't null... If I output it with:

            <h:outputText value="#{fooBean.id}/>

            or
            <h:outputText value="#{barBean.viewId}/>


            the id is shown correctly (not null). Must I use ${fooBean.id} and ${barBean.viewId} for both to work with <a4j:commandButton/> and <a4j:include/> ?

            Thank you.

            • 3. Re: EL expression for id attributes?

              it is resolved to null on what JSF lifecycle phase? 2nd or 6th?

              • 4. Re: EL expression for id attributes?
                grimholtz

                 

                "SergeySmirnov" wrote:
                it is resolved to null on what JSF lifecycle phase? 2nd or 6th?

                Good question. Where should I look in the a4j/richfaces logging for that information?

                • 5. Re: EL expression for id attributes?

                  You can put the phase tracker into the classpath to see it. For example, you cat take the ready-to-use one from http://www.jsftutorials.net/faces-config/phaseTracker.html

                  • 6. Re: EL expression for id attributes?
                    ziphyre

                    Yep, same problem here
                    (not exactly)

                    <div id="message_#{msg.id}_body"></div>
                    <a4j:commandLink id="message_#{msg.id}_send" />
                    <h:outputLink id="message_#{msg.id}_send" />

                    renders to:
                    <div id="message_45_body"></div>
                    <a4j:commandLink id="messages:message__send" />
                    <h:outputLink id="message___send" />


                    the difference from grimholtz' is in my case <h:outputLink> ids aren't correct also...

                    Using richface 3.2.0.SP1
                    facelets with seam 2.0.2

                    • 7. Re: EL expression for id attributes?
                      grimholtz

                      Update: I created a PhaseListener and output the EL expression in all phases. It's not obvious to me that it's null in phase 2 or 6, but I'm still investigating.

                      • 8. Re: EL expression for id attributes?
                        nbelaevski

                        Hello,

                        The following code:

                        <rich:tabPanel id="#{capitalsBean.capitalsOptions[0].value}_1" switchType="server" styleClass="top_tab" contentClass="content_tab" headerClass="header_tabs_class" inactiveTabClass="inactive_tab" activeTabClass="active_tab">
                         <rich:tab label="Usage">
                         <ui:include src="/richfaces/listShuttle/listShuttle.xhtml"/>
                         </rich:tab>
                         <ui:include src="/templates/include/tagInfo.xhtml">
                         <ui:param name="path" value="rich/listShuttle"/>
                         </ui:include>
                         </rich:tabPanel>
                        
                        outputs correct id="Montgomery_1", so this feature should be working. Maybe msg.id is null or that is an issue of Facelets version you are using?

                        I've tried on: RichFaces 3.2.1, Facelets 1.1.14

                        • 9. Re: EL expression for id attributes?
                          ziphyre

                          Hi,

                          I'm using richfaces 3.2.0 with facelets 1.1.14

                          id can't be null because this code :

                          <div id="m_#{msg.id}"><div>
                          <a4j:commandLink id="m_s_#{msg.id}" />


                          renders

                          <div id="m_1"></div>
                          <a4j:commandLink id="m_" />


                          So, it's ok for div but not for a4j:commandLink...


                          • 10. Re: EL expression for id attributes?
                            grimholtz

                             

                            So, it's ok for div but not for a4j:commandLink...

                            But Sergey says it *should* work for a4j:commandLink !

                            • 11. Re: EL expression for id attributes?
                              grimholtz

                               

                              So, it's ok for div but not for a4j:commandLink...

                              But Sergey says it *should* work for a4j:commandLink !

                              • 12. Re: EL expression for id attributes?
                                ziphyre

                                But it ain't...

                                I don't know if it's relevant but this:

                                <a4j:commandLink id="message_#{msg.id}_title" styleClass="mClass_#{msg.id}" />

                                renders as:
                                <a id="hotspotForm:messages:0:message__title" class="mClass_45" />


                                PS: And sorry, in my previous posts I wrote down in examples that <a4j:commandLink id="m_s_#{msg.id}"/> renders as <a4j:commandLink id="m_"/>. Although the output is obviously an <a.../>. The problem is on ids only, not the tag itself

                                • 13. Re: EL expression for id attributes?
                                  ziphyre

                                  grimholtz,

                                  In my case, I needed these unique ids for javascript access on the browser. So I applied a (ugly) workaround using prototype library. It's specifying unique class names with #{msg.id}

                                  <a4j:commandLink styleClass="message_#{msg.id}" />
                                  and than accessing these components with, a for example, a parent div with a unique id like:
                                  $('id_of_the_parent_div').getElementsByClassName('mClass_#{msg.id}')[0]



                                  hope this helps..




                                  • 14. Re: EL expression for id attributes?
                                    ziphyre

                                    sorry:

                                    $('id_of_the_parent_div').getElementsByClassName('mClass_#{msg.id}')[0]


                                    1 2 Previous Next