13 Replies Latest reply on May 12, 2010 5:09 AM by nbelaevski

    Binding problem with richfaces and maven

    derkd

      Hi all,

       

      I have a problem binding my extendedDataTableModel to my view. I heard from Ilya that bindings should be avoided but I guess when you need a selection from the table you will have to bind it according to this example: {quote}http://anonsvn.jboss.org/repos/richfaces/branches/community/3.3.X/samples/richfaces-demo/src/main/java/org/richfaces/demo/extendedDataTable/ExtendedTableBean.java{quote}

       

      I use the latest stable jboss tools with maven and added the

       

      {code:xml}<dependency>

            <groupId>org.richfaces.framework</groupId>

            <artifactId>richfaces-impl</artifactId>

            <scope>provided</scope>

          </dependency>{code}

       

      to my ejb pom.xml, everything compiles but at the deployment I get the class not found error for the ExtendedDataTableModel.

      So I replaced above xml with this:

      {code:xml}<dependency>

            <groupId>org.richfaces.framework</groupId>

            <artifactId>richfaces-impl</artifactId>

            <scope>compile</scope>

          </dependency>{code}

       

      Everything compiles and deploys fine, except when calling the page I get a :

      {code}

      javax.el.ELException: /mapAdmin.xhtml @107,57 binding="#{mapsAction.stateTable}": java.lang.IllegalArgumentException: argument type mismatch{code}

       

      How can I solve this issue?

       

      Regards,

       

      Derk

        • 1. Re: Binding problem with richfaces and maven
          derkd

          When setting every RF lib in the war and pom.xml to provided and added al the RF to the EAR file everything compiles and deploys.

          But I now get the following error:

           

          {code}javax.el.ELException: Function 'rich:clientId' not found{code}


          I make use of the #{rich:clientId} RF javascript library. This worked before the pom.xml modifications. I guess adding all the RF libs to the EAR is also not the sollution

          • 2. Re: Binding problem with richfaces and maven
            nbelaevski

            Derk,

             

            Components should not be bound to EJB beans, use managed beans instead.

             

            Correct layout is:

             

            richfaces-api in EAR; richfaces-impl & richfaces-ui - in WAR.

            1 of 1 people found this helpful
            • 3. Re: Binding problem with richfaces and maven
              derkd

              Thanks for your answer Nick. So what you are saying is that I should add the java classes to the /java dir in my war project instead of ejb?

               

              so only entities should be in my ejb project or also session (controller) beans?

               

              the component classes which I can bind to my view (ExtendedTableModel) should be in my war project?

              • 4. Re: Binding problem with richfaces and maven
                nbelaevski

                Models can be used by EJB beans, components cannot be. What is the fully-qualified name for ExtendedTableModel? I cannot find such class in RF 3.3.3.Final.

                • 5. Re: Binding problem with richfaces and maven
                  derkd

                  {code}

                  import org.richfaces.model.ExtendedTableDataModel;{code}

                  • 6. Re: Binding problem with richfaces and maven
                    nbelaevski

                    Ok, it's in richfaces-impl. Try moving richfaces-impl from WAR to EAR.

                    • 7. Re: Binding problem with richfaces and maven
                      derkd

                      Already tried that one, it compiles and deploys fine but gives me an error that it can't find rich:clientId which I am using in my page

                       

                      {code}#{rich:clientId}{code}

                       

                      {code}

                      javax.el.ELException: Function 'rich:clientId' not found{code}
                      • 8. Re: Binding problem with richfaces and maven
                        nbelaevski

                        Looks like you need to use managed beans then.

                        • 9. Re: Binding problem with richfaces and maven
                          derkd

                          I guess I already tried this, let me explain by code:

                          I have an EAR project and this is my action bean "MapsAction.java" and this one is within my EJB project:

                           

                           

                          {code}

                          package nl.dddn.planningsystem.session; @Name("mapsAction") @Scope(ScopeType.CONVERSATION) public class MapsAction {            @In(create = true)      private DistrictHome districtHome;      @DataModel(scope = ScopeType.PAGE)      private List<District> districts;            @DataModel(scope = ScopeType.PAGE)      private List<Marker> markers;            private ExtendedTableDataModel<District> districtTable;            private SimpleSelection districtSelection;            private long selectedDistrictId;                  private List<Marker> newMarkers;            @Logger      private static Log log;                  @WebRemote      @Transactional      public District addDistrict(District district) {           log.debug("entered addDistrict()");           try {                log.debug("try addDistrict()");                districtHome.setInstance(district);                districtHome.persist();                return district;           }catch (Exception e) {                log.error(e);                return null;           }      }            @WebRemote      @Transactional      public Marker addMarker(Marker marker) {           log.debug("entered addMarker()");           try {                log.debug("try addMarker()"); //               districtHome.setInstance(district); //               districtHome.persist();                if(newMarkers == null) {                     log.debug("marker is null");                     newMarkers = new ArrayList<Marker>();                }                newMarkers.add(marker);                log.debug("markers size: " + newMarkers.size());                return marker;           }catch (Exception e) {                log.error(e);                return null;           }      }                              @WebRemote      @Transactional      public void removeMarker(String lng, String lat) {           log.debug("entered removeMarker()");           try {                log.debug("try removeMarker()");                                Iterator<Marker> iter = newMarkers.iterator();                while(iter.hasNext()) {                     Marker marker = iter.next();                     if(lng.equals(marker.getLng()) && lat.equals(marker.getLat())){                          iter.remove();                          return;                     }                }                                //return foundDistrict;           }catch (Exception e) {                log.error(e);                //return null;           }      }                  public void takeDistrictSelection() {           log.debug("takeDistrictSelection");                      Iterator<Object> iterator = getDistrictSelection().getKeys();         while (iterator.hasNext()) {              Object key = iterator.next();             districtTable.setRowKey(key);             if (districtTable.isRowAvailable()) {                 District district = (District) districtTable.getRowData();                    markers = district.getMarkers();                    zoom = district.getZoom();                    selectedDistrictId = district.getId();             }         }                 }                  @WebRemote      @Transactional      public District getDistrict(Long id) {           District district = null;           if(id != null && id != 0) {                districtHome.setId(id);                district = districtHome.getInstance();           }           return district;      }            public List<District> getDistricts() {           return districts;      }      public void setDistricts(List<District> districts) {           this.districts = districts;      }      public SimpleSelection getDistrictSelection() {           return districtSelection;      }      public void setDistrictSelection(SimpleSelection districtSelection) {           this.districtSelection = districtSelection;      }      public List<Marker> getMarkers() {           return markers;      }      public void setMarkers(List<Marker> markers) {           this.markers = markers;      }      public List<Marker> getNewMarkers() {           return newMarkers;      }      public void setNewMarkers(List<Marker> newMarkers) {           this.newMarkers = newMarkers;      }      public ExtendedTableDataModel<District> getDistrictTable() {           if (districtTable == null) {                districtTable = new ExtendedTableDataModel<District>(new DataProvider<District>(){                     private static final long serialVersionUID = 5054087821033164847L;                     public District getItemByKey(Object key) {                          for(District district : districts){                               if (key.equals(getKey(district))){                                    return district;                               }                          }                          return null;                     }                     public List<District> getItemsByRange(int firstRow, int endRow) {                          return districts.subList(firstRow, endRow);                     }                     public Object getKey(District item) {                          return item.getTitle();                     }                     public int getRowCount() {                          return districts.size();                     }                                     });           }           return districtTable;      }      public void setDistrictTable(ExtendedTableDataModel<District> districtTable) {           this.districtTable = districtTable;      }      public long getSelectedDistrictId() {           return selectedDistrictId;      }      public void setSelectedDistrictId(long selectedDistrictId) {           this.selectedDistrictId = selectedDistrictId;      }       }
                          {code}

                           

                           

                          Now what I want is to click on a row in the table so that it will give me the row data (in this case an District object). As far as I know I need to bind the table to an ExtendedTableDataModel but that is bad practice according to you and Ilya. How can I do this without binding it? And also I like to know what I am doing wrong, why can't I just bind it in this MapsAction? I has got to be possible because you guys did this in an example.

                           

                          Some extra informations, I have set project up using JBoss Tools with the Maven facet. To have the ExtendedTableModel class in my EJB project I had to add the richfaces-impl to my ejb project as provided. But when I deploy this I get a ClassNotFound exception, I guess this is because the EJB and WAR project are loaded isolated? Also when adding all the jars to the EAR /lib it compiles and deploys fine except I get the error rich:clientId (#{rich:clientId} the javascript method of RF) not found which I am using in my .xhtml pages.

                           

                          regards,

                           

                          Derk

                          • 10. Re: Binding problem with richfaces and maven
                            derkd

                            I solved my problem by using the key of the SimpleSelection and the loaded list in the datatable. When you know the index of the row that has been clicked you can get the data from the list by using states.get(selection.getKey());

                             

                            in my case the takeStateSelection looks like this:

                             

                             

                            {code}public String takeStateSelection() {

                                 log.debug("takeStateSelection");

                                 if(stateSelection != null) {

                                      log.debug("stateSelection != null");

                                      getSelectedStates().clear();

                                      if (getStateSelection().isSelectAll()) {

                                           getSelectedStates().addAll(states);

                                      } else {

                                           Iterator<Object> iterator = getStateSelection().getKeys();

                                           while (iterator.hasNext()) {

                                                Object key = iterator.next();

                                                getSelectedStates().add(states.get((Integer)key));

                                                State state = getSelectedStates().get(0);

                                                regions = state.getRegions();

                                                markers = state.getMarkers();

                                                zoom = state.getZoom();

                                                selectedStateId = state.getId();

                                      }

                                 }

                                 return "takeStateSelection";

                            }{code}

                             

                            getSelectedStates is an empty arraylist where I add the states which are selected in the table.

                             

                            So my problem is partly solved, I still want to know how I can bind components to my beans!!!!! Is the combination of using the RF javascript and binding a component to your bean possible (putting al RF libs in the ear lib)? I didn't managed to get working

                             

                            Regards,

                             

                            Derk

                            • 11. Re: Binding problem with richfaces and maven
                              nbelaevski

                              Derk,

                              To have the ExtendedTableModel class in my EJB project I had to add the richfaces-impl to my ejb project as provided. But when I deploy this I get a ClassNotFound exception, I guess this is because the EJB and WAR project are loaded isolated?

                              "provided" .jar files are not packaged with your application, they're just for compilation/unit tests. You should use default scope instead.

                               

                              I still want to know how I can bind components to my beans!!!!!

                              Components should not be bound to EJB beans, but to managed beans. Models should be available for EJB beans, but they should be all in richfaces-api.jar, so that's an error that ExtendedTableDataModel is in richfaces-impl.

                               

                              Also when adding all the jars to the EAR /lib it compiles and deploys fine except I get the error rich:clientId (#{rich:clientId} the javascript method of RF) not found which I am using in my .xhtml pages.

                              Right, at least richfaces-ui should be in web module.

                              1 of 1 people found this helpful
                              • 12. Re: Binding problem with richfaces and maven
                                derkd

                                Hi Nick,

                                 

                                 

                                {quote}"provided" .jar files are not packaged with your application, they're just for compilation/unit tests. You should use default scope instead.{quote}

                                 

                                Yes I'm aware of that, thanks.

                                 

                                 

                                {quote}Components should not be bound to EJB beans, but to managed beans. Models should be available for EJB beans, but they should be all in richfaces-api.jar, so that's an error that ExtendedTableDataModel is in richfaces-impl.{quote}

                                 

                                ok so what you are saying is that this is wrong in RF and should be fixed in a next release of RF?

                                • 13. Re: Binding problem with richfaces and maven
                                  nbelaevski

                                  ok so what you are saying is that this is wrong in RF and should be fixed in a next release of RF?

                                  Yes, that's a thing causing problems, so we need to address it. Now we are working on 4.x release, so that is something to consider during models design.