11 Replies Latest reply on Dec 31, 2012 8:37 AM by kenfinni

    How to get ID (namespace) generate by JBoss Portlet Bridge?

    guga.java

      Hi to all,

       

      JBoss Portlet Bridge generates a random ID as namespace for all JSF components (ok is following the spec), but how to get this ID which was generated?

       

      for example, JPB generate this for all my portlet

       

       

      <div class="pbr-body" id="pbG7f75e5d6_2d6d9f_2d4dff_2dac3c_2dc2e7b8ea2ea5_j_id1">

         

        

      All my components inherit this id

        • 1. Re: How to get ID (namespace) generate by JBoss Portlet Bridge?
          kenfinni

          That ID is generated by ExternalContext.getNamespace().

           

          As to if there is a way to retrieve it, I'm not sure as I've never needed to.

           

          What is it that you need to do which requires you to retrieve it?

          • 2. Re: How to get ID (namespace) generate by JBoss Portlet Bridge?
            guga.java

            I need retrieve it because I need to work on client side too with javascript where in some cases I can't use css class to retrieve JSF components

            • 3. Re: How to get ID (namespace) generate by JBoss Portlet Bridge?
              kenfinni

              You may have some luck using the Portlet Bridge JSF taglib to set the namespace into a hidden field, that you can then retrieve from JS.

               

              Add a tab namespace of: xmlns:pbr="http://jboss.org/portletbridge" to your JSF facelet, and then set the value of something to hold the namespace using: <pbr:namespace />

               

              Let me know if that works

              • 4. Re: How to get ID (namespace) generate by JBoss Portlet Bridge?
                guga.java

                Unfortunately it did not work.

                 

                Portlet Bridge render this is pbG7f75e5d6_2d6d9f_2d4dff_2dac3c_2dc2e7b8ea2ea5_j_id1

                 

                <pbr:namespace> render this id G7f75e5d6_2d6d9f_2d4dff_2dac3c_2dc2e7b8ea2ea5

                 

                Is not the same =/

                • 5. Re: How to get ID (namespace) generate by JBoss Portlet Bridge?
                  kenfinni

                  My apologies, I wasn't completely clear in my previous comment.

                   

                  You will not be able to get exactly the same value, as the last portion of it (j_id1) is generated by JSF and there is no way to know what it will generate for you.  You can choose to set an id on the component directly, and then JSF will not need to generate a random id number for that component.

                   

                  As for the initial part of the id, you have everything you need to construct it yourself, simply prefix the result of <pbr:namespace> with "pb" and then suffix it with "_" followed by the id generated by JSF, or set by you.

                  • 6. Re: How to get ID (namespace) generate by JBoss Portlet Bridge?
                    guga.java

                    First of all thanks for your attention!

                     

                    Ok, I understood in the first time. But the end of ID is not generated because of a JSF component that I did not put the ID, this div with ID generate by Portlet Bridge is automatically generated before any component JSF that I have used.

                    • 7. Re: How to get ID (namespace) generate by JBoss Portlet Bridge?
                      kenfinni

                      Can you show the xhtml code that shows the outer most bits of the page and the div that generates the id?

                       

                      Anything inside the div you don't need to include

                      • 8. Re: How to get ID (namespace) generate by JBoss Portlet Bridge?
                        guga.java

                        <?xml version="1.0" encoding="ISO-8859-1"?>

                        <f:view xmlns="http://www.w3.org/1999/xhtml"

                            xmlns:h="http://java.sun.com/jsf/html"

                            xmlns:f="http://java.sun.com/jsf/core"

                            xmlns:ui="http://java.sun.com/jsf/facelets"

                            xmlns:a4j="http://richfaces.org/a4j"

                            xmlns:pbr="http://jboss.org/portletbridge"

                            xmlns:rich="http://richfaces.org/rich">

                         

                            <h:head >

                                <meta http-equiv="Content-Type"

                                    content="text/html; charset=iso-8859-1" />

                                <h:outputStylesheet library="css" name="bootstrap.min.css" />

                                <h:outputStylesheet library="css" name="jquery-ui-1.9.2.custom.min.css" />

                                <h:outputScript library="js" name="jquery-ui-1.9.2.custom.min.js" />

                                <h:outputScript library="js" name="legislacao.js" />

                         

                        <style>

                        .rf-ntf-err .rf-ntf-ico {

                            background-image: url("/MME-PORTLETS/resources/imagens/error-icon.png");

                            display: block;

                        }

                        </style>

                         

                        <script type="text/javascript">

                        function MarcarTodosCheckbox(){

                            $("input[type=checkbox]").each(function() { this.checked = true; });

                        }

                        </script>

                         

                            </h:head>

                            <h:body >

                            <pbr:namespace/>

                                <div class="container master-container">

                        • 9. Re: How to get ID (namespace) generate by JBoss Portlet Bridge?
                          kenfinni

                          Am I correct in saying that the div with the ID you mentioned previously actually exists around the div in your facelet that has the style class set?  That is what I would expect to see.

                           

                          The reason for the extra div, and why it has a JSF id of j_id1, is because the Portlet Bridge wraps the content of <h:body> from a facelet inside a div element.  It does this because there can be no <body> tag returned from JSF to the UI, as the portal page has already generated one.

                           

                          The div has a JSF id because it is generated from within JSF page rendering, even though it's not a JSF component.

                           

                          Hope that answers your questions.

                           

                          I don't think it should be a problem if that div has a generated id, as you shouldn't need to interact with that generated div for any reason.

                          • 10. Re: How to get ID (namespace) generate by JBoss Portlet Bridge?
                            guga.java

                            Thanks again for your help!

                             

                            My problem is not with the div but with the ID the prefix all my JSF Components

                             


                            By what I understood to get this prefix ID I just always use "pb<pbr:namespace/>j_id1" is it?

                             

                            in my humble opinion there could be a more "correct way" to do this

                            • 11. Re: How to get ID (namespace) generate by JBoss Portlet Bridge?
                              kenfinni

                              The "j_id1" portion of the id is generated by JSF.

                               

                              You will see values like the above, but with the count being incremented, for all components in the JSF page that do not have an ID assigned to them within the facelet code.

                               

                              That's how JSF ensures that the IDs on all html tags are unique and can be referenced through JS.  Portlet Bridge prefixes the JSF value with "pb" followed by the namespace value, as discussed previously.

                               

                              All you'd need to do is retrieve the latter portion of the ID that is generated by JSF, or set an ID onto the component in the facelet if possible.