8 Replies Latest reply on Dec 13, 2006 9:29 AM by supert24 supert24

    how retrieve current UIComponent

    supert24 supert24 Newbie

      How to I retrieve the current enclosing UIComponent within a triggered action method of my Seam component?

        • 1. Re: how retrieve current UIComponent
          Pete Muir Master

          I think you would have to use an action listener (which gets passed an action event). You can then do actionEvent.getComponent();

          • 2. Re: how retrieve current UIComponent
            Ciro Cavani Novice

            Well, I think this is completely off topic for Seam, but may be worth.

            I use this in action method (of Seam component):

            UIComponent form = FacesContext.getCurrentInstance().getViewRoot().findComponent("id_of_form_in_your_page");
            
            UIInput input = (UIInput) form.findComponent("id_of_component_you_want");
            input.setSubmittedValue(null);
            


            for this, in MyFaces, you need set id for ui components you want.

            based on:

            http://wiki.apache.org/myfaces/ClearInputComponents

            • 3. Re: how retrieve current UIComponent
              Gavin King Master

               

              I use this in action method (of Seam component):


              Why would you do it this way? Better to use binding="#{myModel.attribute} in the page.

              For the original question, I think Pete's answer is the right one.

              • 4. Re: how retrieve current UIComponent
                Ciro Cavani Novice

                No good reason. Maybe because other way need more one bean or get/set on action bean... and is very like ASP.NET.

                But I agree that using binding is better and I will try it.

                Thanks,

                • 5. Re: how retrieve current UIComponent
                  Jarkko Lietolahti Novice

                  Hello,
                  I've a slight problem working with Seam enabled (not stricly related to seam ;) Portlets, JSF and Iceface. I think that each portlet has their own JSF view, anyone knows if this is correct?

                  Now, I use Seam to help those portlets communicate (through session, maybe one day I'll get the conversation scope to work too) with each other. With the inclusion of AJAX (Icefaces) I'm having some trouble getting screen updates at correct times. Like e.g. when drag-n-dropping something from one portlet to another. After dropping an draggable object to other portlet the backing bean (Seam enhanced POJO/SFSB) has got the correct id of JSF component, now however the drag initiated from other portlet (with it's own jsf view) and that JSF view doens't known anything the other view (from where I got the id anyways).

                  Is there are way to query for all JSF views to find a component?
                  I admit, it's quite unclear for me how the JSF works internally (how the views are structured etc), so bear if the problem is too silly.

                  • 6. Re: how retrieve current UIComponent
                    supert24 supert24 Newbie

                     

                    "gavin.king@jboss.com" wrote:
                    I use this in action method (of Seam component):


                    Why would you do it this way? Better to use binding="#{myModel.attribute} in the page.

                    For the original question, I think Pete's answer is the right one.


                    What is "myModel" and what is "attribute"? is "myModel" my Seam component and "attribute" some class attribute with an "@In" annotation? And of what data type is it?

                    • 7. Re: how retrieve current UIComponent
                      Gavin King Master

                      myModel is a Seam component, and attribute is a property of that component that definitely does NOT have an @In!

                      • 8. Re: how retrieve current UIComponent
                        supert24 supert24 Newbie

                         

                        "gavin.king@jboss.com" wrote:
                        myModel is a Seam component, and attribute is a property of that component that definitely does NOT have an @In!


                        Ok, i have now in my JSF file:

                        <h:dataTable var="item" value="#{buy_ActionShowMenu_menu_WEB_OUT.menuItems}" id="id_of_component_you_want" binding="#{CustomerWeb.datUI}">
                        
                        ..
                        <h:column>
                        <s:button value="ADD" action="#{CustomerWeb.buy_showMenu_Resume}" />
                        </h:column>
                        </h:dataTable>
                        


                        and in my Seam component:
                         public UIData datUI;
                        
                         public UIData getDatUI() {
                         return datUI;
                         }
                        
                         public void setDatUI(UIData datUI) {
                         this.datUI = datUI;
                         }
                         public String buy_showMenu_Resume() {
                        
                         if (datUI != null)
                         buy_ActionShowMenu_item_WEB_IN = (MenuItem) datUI.getRowData();
                        ..
                        
                         }
                        
                        


                        My datUI is always null. Can you help?

                        (please dont asked me why I not use @DataModelSelection .. this is actually what I try to do with pure JSF means because of restrictions of our contractors. - But we are allowed to use @In stuff and so on)