1 2 Previous Next 16 Replies Latest reply on Jan 21, 2010 8:29 PM by nathan dennis

    Any Seam example using JSF binding attribute?

    Thai Dang Vu Apprentice

      My SFSB


      @Stateful
      @Name("customerList")
      public class CustomerListImpl implements CustomerList {
          @Logger
          protected Log log;
      
          @PersistenceContext(type= PersistenceContextType.EXTENDED)
          protected EntityManager entityManager;
      
          @DataModel
          protected List<Customer> customers;
      
          protected HtmlScrollableDataTable dataTable;
          protected SimpleSelection selection;
      
          public void viewSelectedRows() {
              Iterator<Object> iterator = selection.getKeys();
              while (iterator.hasNext()) {
                  Object key = iterator.next();
                  dataTable.setRowKey(key);
                  Object customer = dataTable.getRowData();
                  customer = null;
              }
          }
      
          @SuppressWarnings("unchecked")
          public void findCustomers() {
              customers = entityManager.createQuery("select c from Customer c").getResultList();
          }
      
          @Destroy
          @Remove
          public void destroy() {
          }
      
          public HtmlScrollableDataTable getDataTable() {
              return dataTable;
          }
      
          public void setDataTable(HtmlScrollableDataTable dataTable) {
              this.dataTable = dataTable;
          }
      
          public SimpleSelection getSelection() {
              return selection;
          }
      
          public void setSelection(SimpleSelection selection) {
              this.selection = selection;
          }
      }


      My local interface:


      @Local
      public interface CustomerList {
          void viewSelectedRows();
          void findCustomers();
          void destroy();
          HtmlScrollableDataTable getDataTable();
          void setDataTable(HtmlScrollableDataTable dataTable);
          SimpleSelection getSelection();
          void setSelection(SimpleSelection selection);
      }


      My xhtml (I know that this is not suggested because the dataTable and selection are conversational-scoped):


          <a4j:form>
              <rich:scrollableDataTable value="#{customers}" var="customer" width="70px" height="200px"
                                        selectedClass="selectedRow" binding="#{customerList.dataTable}"
                                        selection="#{customerList.selection}">
                  <rich:column width="48px">
                      <f:facet name="header">ID</f:facet>
                      <h:outputText value="#{customer.id}"/>
                  </rich:column>
              </rich:scrollableDataTable>
              <p/>
      
              <a4j:commandLink value="View Selected Rows" action="#{customerList.viewSelectedRows}"
                               reRender="selectedRowBox"/>
          </a4j:form>
          <p/>
      
          <h:panelGroup id="selectedRowBox">
              
          </h:panelGroup>


      When I accessed that xhtml page, I got exceptions:


      javax.servlet.ServletException: /customers.xhtml @16,73 binding=#{customerList.dataTable}: Target Unreachable, identifier 'customerList' resolved to null
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
           at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:333)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)


      If I don't use binding and selection attributes in the <rich:scrollableDataTable>, I don't see exceptions and I can click on the View Selected Box and go to the viewSelectedRows method.


      What did I do wrong?

        • 1. Re: Any Seam example using JSF binding attribute?
          Chris Lambert Newbie

          Hi
          Did You resolve this issue?
          I have similar problem
          regards
          Chris

          • 2. Re: Any Seam example using JSF binding attribute?
            Arbi Sookazian Master

            Generally, we don't use binding attribute to bind data from our business/persistence tiers to JSF layer.  This couples your view layer with your business/persistence layer unnecessarily.  Binding JSF with backing bean may be useful if you need to dynamically re-construct a UI component (but the need for this is very rare).


            So.......


            The following is bad practice:


            <rich:scrollableDataTable value="#{customers}" var="customer" width="70px" height="200px"
                                              selectedClass="selectedRow" binding="#{customerList.dataTable}"
                                              selection="#{customerList.selection}">
            



            Instead do this:


            <rich:scrollableDataTable value="#{customers}" var="customer" width="70px" height="200px"
                                              selectedClass="selectedRow">
            



            Referring to the value attribute, you can outject a ListDataModel instance via @DataModel in your backing bean or return a List directly from your business method.  The List or ListDataModel is typically a collection of some sort that consists of entities that are looped thru when the dataTable is rendered as HTML table with rows, columns, etc.


            • 3. Re: Any Seam example using JSF binding attribute?
              Sara Mendu Newbie

              Without sepcifying the binding attribute, the ScrollableDataTable works but I am not able to achieve the Pagination in the table when you scroll. Are there any alternative options to achieve the same without binding it to the ScrollDataTable and use its features.


              Please help...

              • 4. Re: Any Seam example using JSF binding attribute?
                Sainath Nair Newbie

                Arbi Sookazian wrote on May 05, 2009 01:38:


                Generally, we don't use binding attribute to bind data from our business/persistence tiers to JSF layer.  This couples your view layer with your business/persistence layer unnecessarily.  Binding JSF with backing bean may be useful if you need to dynamically re-construct a UI component (but the need for this is very rare).

                So.......

                The following is bad practice:

                <rich:scrollableDataTable value="#{customers}" var="customer" width="70px" height="200px"
                                                  selectedClass="selectedRow" binding="#{customerList.dataTable}"
                                                  selection="#{customerList.selection}">
                



                Instead do this:

                <rich:scrollableDataTable value="#{customers}" var="customer" width="70px" height="200px"
                                                  selectedClass="selectedRow">
                



                Referring to the value attribute, you can outject a ListDataModel instance via @DataModel in your backing bean or return a List directly from your business method.  The List or ListDataModel is typically a collection of some sort that consists of entities that are looped thru when the dataTable is rendered as HTML table with rows, columns, etc.





                Actually I wanted to create a dynamic panel which will contain sql IDs of the foreign key values in my jsf page. So I wanted to use binding in my jsf! Can you tell me the right way?

                • 5. Re: Any Seam example using JSF binding attribute?
                  nathan dennis Expert

                  i have the same issue. not with a scrollingDataTable, but with other components. I realize that this is not common design to move JSF component creation into managed beans, BUT there are time you need this type of functionality. A WORKING EXAMPLE added to the seams examples would be great. if not a simple post here on the forum on how to correctly implement this functionality would be exponentially appreciated.  


                  the documentation in the manual is lack luster to say the least. about the only think i got out of that was... it doesnt work with a CONVERSATION BEAN... So use EVENT and inject it. which leads us to a whole set of problems with maintaining stuff for AJAX calls because we cant inject a conversation bean into the event bean responsible for the logic to build the components. im glad to know im not the only person trying to make this work with seam, and frustrated that the project is this old and this question has never been made into an example.


                  help if you can.

                  • 6. Re: Any Seam example using JSF binding attribute?
                    Tim Evers Master

                    the documentation in the manual is lack luster to say the least. about the only think i got out of that was... it doesnt work with a CONVERSATION BEAN... So use EVENT and inject it. which leads us to a whole set of problems with maintaining stuff for AJAX calls because we cant inject a conversation bean into the event bean responsible for the logic to build the components. im glad to know im not the only person trying to make this work with seam, and frustrated that the project is this old and this question has never been made into an example.

                    help if you can.


                    Just because you can't inject a CONVERSATION scoped bean into a conversation doesn't mean you can't inject the EVENT scoped bean into your CONVERSATION scoped bean and manipulate it in there. The solution I have below is very hacky and probably wrong on many different levels but I haven't had time to do a whole lot of research on how to do it 'right'.


                    This is the bean that I bind to in my xhtml


                    @Name(RefDataAdminFactory.SEAM_ID)
                    @Scope(ScopeType.EVENT)
                    @AutoCreate
                    public class RefDataAdminFactory {
                        public static final String SEAM_ID = "RefDataAdminFactory";
                        
                        private HtmlPanelGrid grid = new HtmlPanelGrid();
                        
                        public HtmlPanelGrid getGrid() {
                            SimpleDynamicRefDataController<?> dynRefDataController = 
                                (SimpleDynamicRefDataController<?>) Component.getInstance(SimpleDynamicRefDataController.class);
                            if (null != dynRefDataController) {
                                this.grid.getChildren().clear();
                                this.grid.getChildren().add(
                                    dynRefDataController.generateFieldsHtmlFragment());
                            }
                            return grid;
                        }
                    
                        public void setGrid(HtmlPanelGrid grid) {
                            this.grid = grid;
                        }
                        
                        public void addComponent(UIComponent component) {
                            this.grid.getChildren().clear();
                            this.grid.getChildren().add(component);
                        }
                        
                    }
                    



                    The getGrid() tries to get my default value but this was a hack to just get it working as it wasn't high on my list of priorities... but maybe this can help you get going.


                    And then in my CONVERSATION scoped bean I inject this bean. I then build up the component tree I want to put in the panel grid and then just call refDataAdminFactory.addComponent(myComponentThatIBuilt);


                    refDataFact.addComponent(generateFieldsHtmlFragment());
                    



                    Where generateFieldsHtmlFragment() does a whole bunch of work creating components.


                    • 7. Re: Any Seam example using JSF binding attribute?
                      Tim Evers Master

                      This is what it SHOULD have said



                      Tim Evers wrote on Jan 18, 2010 05:43:


                      Just because you can't inject a CONVERSATION scoped bean into an EVENT doesn't mean you can't inject the EVENT scoped bean into your CONVERSATION scoped bean and manipulate it in there.
                      • 8. Re: Any Seam example using JSF binding attribute?
                        nathan dennis Expert

                        thanks for the response...


                        that is sort of what i was working on. yeah. it will definitely work the first render with the event bean injected into the conversation bean. i had done that previously. the issue was running into was i wanted to recreate UI components base on a ajax call to the conversation bean. i didnt think of using Component.getInstance() in the event bean.


                        that would fetch the correct conversation bean into the event bean? if that is true i would still have access to all the data to correctly render the components. as before though, im not sure that it will work on the ajax call. seems like it would have one of the same problems i was having before. i'm pretty sure that all that phase talk about the phase seams restores the conversation and when UI bindings are render would be applicable here.


                        i will look at it closer tomorrow and try to follow up with a test case.

                        • 9. Re: Any Seam example using JSF binding attribute?
                          Tim Evers Master

                          As long as your ajax call is made to a conversation scoped bean then I'm pretty sure that what I've written will work. Because the conversation scoped bean will make a call to the event scoped bean and replace the components inside the UIComponent it holds. Thus your page should end up with the correct data.


                          Component.getInstance only works after the restor view phase... hence the if != null. Because during the restore view phase the conversation scope has not been restored.


                          Anyways, I'm off for the day. Hope you get things working :)

                          • 10. Re: Any Seam example using JSF binding attribute?
                            nathan dennis Expert

                            yep that works. strangely enough,, very small variations do not. what a pain. thanks for the help. im going to go try to make this work on a must larger scale.

                            • 11. Re: Any Seam example using JSF binding attribute?
                              I need a real name Newbie

                              I got the same problem for using binding




                              javax.el.ELException: /conversation.xhtml @22,52 binding="#{dataTableScrollerBean.table}": java.lang.IllegalArgumentException: argument type mismatch
                              




                              Anybody can provide sample codes to solve this problem?

                              • 12. Re: Any Seam example using JSF binding attribute?
                                nathan dennis Expert

                                Tim Evers answered with example. there is a working example right above your post. the only question was the NPE associated with the ajax call which, if the above example is followed exactly,,, will also work. i was having trouble because i wasnt following the example in its entirety.

                                • 13. Re: Any Seam example using JSF binding attribute?
                                  Tim Evers Master

                                  I need a real name wrote on Jan 20, 2010 21:39:


                                  I got the same problem for using binding



                                  javax.el.ELException: /conversation.xhtml @22,52 binding="#{dataTableScrollerBean.table}": java.lang.IllegalArgumentException: argument type mismatch
                                  




                                  Anybody can provide sample codes to solve this problem?


                                  Well, I'm not sure the exception you are getting is from not following my example. It could be caused by you binding to a variable of the wrong type. You may need to give us the code that you are binding to as well.

                                  • 14. Re: Any Seam example using JSF binding attribute?
                                    nathan dennis Expert

                                    well argument type mismatch mean you are using the wrong data type. post some of the relevant parts of your code and we can help out.  i didnt read the end part of your error because in the previous line you said i got the same problem.  we were fighting a Target Unreachable, identifier error. not a data type mismatch. two very different problems.

                                    1 2 Previous Next