1 2 Previous Next 15 Replies Latest reply on Aug 28, 2009 11:35 AM by Shervin Asgari

    how to display all XHTML files in jsf page

    karunakaran t Newbie

      hi there,


      I'm implementing an admin page in my seam project. so i want to give user rights to each and every page, for that i want to list all xhtml files in my jsf page or is there any alternate for that, if so plz reply me as soon as possible.


      Thanks in advance,

        • 1. Re: how to display all XHTML files in jsf page
          Shervin Asgari Master

          I wanted the same thing and asked about this earlier and I got the answer This is not possible. However you can do this creating a script that lists all the xhtml pages and push those in the db or show them directly. Hackish, but works.

          • 3. Re: how to display all XHTML files in jsf page
            Stuart Douglas Master

            It should be possible. Have a look under section 30.1 'Deploying Custom Resources'.

            • 4. Re: how to display all XHTML files in jsf page
              Shervin Asgari Master

              Interesting. Too bad no one answered my post. I will share my findings

              • 5. Re: how to display all XHTML files in jsf page
                Shervin Asgari Master

                Hmmm I seem to have problems. I have no idea what to do in the required methods.




                public Set<FileDescriptor> getResources() {
                          
                }
                
                public void postProcess(ClassLoader classLoader) {
                          
                }
                
                public void setResources(Set<FileDescriptor> resources) {
                          
                }



                Any ideas?

                • 6. Re: how to display all XHTML files in jsf page
                  Stuart Douglas Master

                  Extend AbstractDeploymentHandler, something like:


                  package org.jboss.seam.deployment;
                  
                  import org.jboss.seam.contexts.Contexts;
                  
                  
                  public class MyDeploymentHandler extends AbstractDeploymentHandler
                  {
                     
                     private static DeploymentMetadata FILE_METADATA = new DeploymentMetadata()
                     {
                  
                        public String getFileNameSuffix()
                        {
                           return ".xhtml";
                        }
                        
                     };
                  
                     public static final String NAME = "mydeploymenthandlername;
                     
                     public String getName()
                     {
                        return NAME;
                     }
                     
                  
                     public DeploymentMetadata getMetadata()
                     {
                        return FILE_METADATA;
                     }
                     
                  }
                  
                  



                  • 7. Re: how to display all XHTML files in jsf page
                    Shervin Asgari Master

                    Thanks Stuart. However, I still get the same NullPointerException




                    public class CustomDeploymentHandler extends AbstractDeploymentHandler {
                    
                         private static DeploymentMetadata CUSTOM_METADATA = new DeploymentMetadata() {
                              public String getFileNameSuffix() {
                                   return ".xhtml";
                              }
                         };
                    
                         public String getName() {
                              return "customDeploymentHandler";
                         }
                    
                         public DeploymentMetadata getMetadata() {
                              return CUSTOM_METADATA;
                         }
                         
                    }






                    @Name("startupDeployment")
                    @Scope(ScopeType.APPLICATION)
                    @Startup
                    public class StartupDeployment {
                         
                         @In("#{deploymentStrategy.deploymentHandlers['customDeploymentHandler']}")
                         private CustomDeploymentHandler myDeploymentHandler;
                    
                         @In("#{hotDeploymentStrategy.deploymentHandlers['customDeploymentHandler']}")
                         private CustomDeploymentHandler myHotDeploymentHandler;
                    
                         @Logger
                         private Log log;
                         
                         @Create
                         public void create() {
                              for (FileDescriptor fd : myDeploymentHandler.getResources()) {
                                   handleXhtml(fd);
                              }
                    
                              for (FileDescriptor f : myHotDeploymentHandler.getResources()) {
                                   handleXhtml(f);
                              }
                         }
                    
                         public void handleXhtml(FileDescriptor fd) {
                              log.info("Filedesc #0 #1", fd.getName(), fd.getUrl());
                         }
                    
                    }



                    And a seam-deployment.properties



                    # For standard deployment
                    org.jboss.seam.deployment.deploymentHandlers=mypackage.CustomDeploymentHandler
                    # For hot deployment
                    org.jboss.seam.deployment.hotDeploymentHandlers=mypackage.CustomDeploymentHandler



                    I get nullpointer on myDeploymentHandler. Seems it doesnt inject it correctly.

                    • 8. Re: how to display all XHTML files in jsf page
                      Shervin Asgari Master

                      Sorry my bad. I had forgot to put the properties file in the build.xml to be copied over.

                      • 9. Re: how to display all XHTML files in jsf page
                        Shervin Asgari Master

                        I copied the deployment-properties file to the myproject.ear/META-INF/ folder and after debug it seems it only finds the debug.xhtml file. I wonder why....

                        • 10. Re: how to display all XHTML files in jsf page
                          Tomasz Wilczynski Newbie

                          Wouldn't this work?




                               public List<String> getXhtmls() {
                                    return getResources( "/", ".xhtml" );
                               }
                               
                               protected List<String> getResources( String path, String suffix ) {
                                    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
                                    Set<String> resources = context.getResourcePaths( path );
                                    List<String> filteredResources = new ArrayList<String>();
                                    for ( String resource : resources ) {
                                         if( resource.endsWith( ".xhtml" ) ) {
                                              filteredResources.add( resource );
                                         } else if( resource.endsWith( "/" ) ) {
                                              filteredResources.addAll( getResources( resource, suffix ) );
                                         }
                                    }
                                    return filteredResources;
                               }





                               <h:dataTable value="#{someBean.xhtmls}" var="page">
                                    <h:column>
                                         <h:outputText value="#{page}" />
                                    </h:column>
                               </h:dataTable>





                          • 11. Re: how to display all XHTML files in jsf page
                            Tomasz Wilczynski Newbie

                            Sorry, typo. Should've been



                                 public List<String> getXhtmls() {
                                      return getResources( "/", ".xhtml" );
                                 }
                                 
                                 protected List<String> getResources( String path, String suffix ) {
                                      ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
                                      Set<String> resources = context.getResourcePaths( path );
                                      List<String> filteredResources = new ArrayList<String>();
                                      for ( String resource : resources ) {
                                           if( resource.endsWith( suffix ) ) {
                                                filteredResources.add( resource );
                                           } else if( resource.endsWith( "/" ) ) {
                                                filteredResources.addAll( getResources( resource, suffix ) );
                                           }
                                      }
                                      return filteredResources;
                                 }



                            Cheers!

                            • 12. Re: how to display all XHTML files in jsf page
                              Shervin Asgari Master

                              So is that instead of the custom deployment?

                              • 14. Re: how to display all XHTML files in jsf page
                                karunakaran t Newbie

                                hi shervin can u post the code for displaying all XHTML files in jsf page, plz its very urgent.


                                thanks in advance.

                                1 2 Previous Next