3 Replies Latest reply on Feb 27, 2012 5:03 PM by Josh Schneider

    Resource Mapping (again) in RichFaces 4.2.0 Final

    Josh Schneider Newbie

      I'm going to try to keep my posts about this issue to a minimum now that there's a final release and new documentation - thanks!

       

      1) Observation: I tried simply including a /META-INF/resources/static-resource-mappings.properties file in my project to invoke resource mapping. No go. The documentation is pretty light now, so is something actually missing here (like a resource location context-param)? If I add these two context params:

       

      <context-param>

              <param-name>org.richfaces.resourceMapping.mappingFile</param-name>

              <param-value>/META-INF/richfaces/custom-mapping.properties</param-value>

          </context-param>

          <context-param>

              <param-name>org.richfaces.resourceMapping.location</param-name>

              <param-value>#{facesContext.externalContext.requestContextPath}/resources/#{resourceLocation}</param-value>

          </context-param>

      and then put my mappings in custom-mapping.properties, things work, assuming I include mapping statements like "jquery.js=js/jquery.js" (resolves to my project's folder: "project/resources/js/jquery.js" - good). Not sure what I'm missing in the documentation.

       

      2) However, if I try to map a resource that's not in the root of the RichFaces staticResources folders, within the components-ui.jar (e.g., status.js is within the folder "org.richfaces"), the mapping doesn't seem to work. I've tried mappings like "status.js=local_file.js", "org.richfaces/status.js=local_file.js", and "org.richfaces:\status.js=local_file.js", but no luck with any of the three. Any ideas?

       

      3) Is there any way to map directly to a resource in another library's resources? For instance, I'm trying to map jquery.js to PrimeFaces' jquery.js, but I can't figure out how to do it or if it's possible. If I copy the PF version to my locally mapped resources, of course, I can successfully do it. Just wondering if there's a syntax for doing it directly (from the documentation, it sounds like the left side of the mapping can include a library reference, but maybe the right side can't).

       

      Thanks.

        • 1. Re: Resource Mapping (again) in RichFaces 4.2.0 Final
          Lukáš Fryč Master

          Josh Schneider wrote:

           

          1) Observation: I tried simply including a /META-INF/resources/static-resource-mappings.properties file

           

          Hi Josh, nice catch, the documentation is wrong here:

          https://github.com/richfaces/core/blob/develop/impl/src/main/java/org/richfaces/resource/ResourceMappingConfiguration.java#L44

          (resources != richfaces)

           

           

          Josh Schneider wrote:

           

          2) However, if I try to map a resource that's not in the root of the RichFaces staticResources folders, within the components-ui.jar (e.g., status.js is within the folder "org.richfaces"), the mapping doesn't seem to work. I've tried mappings like "status.js=local_file.js", "org.richfaces/status.js=local_file.js", and "org.richfaces:\status.js=local_file.js", but no luck with any of the three. Any ideas?

           

          Thanks.

          I think the right format should be (as you need to escape ":" character as separated between library and resource name):

           

          org.richfaces\:status.js=local_file.js
          

           

           

          Josh Schneider wrote:

           

          3) Is there any way to map directly to a resource in another library's resources? For instance, I'm trying to map jquery.js to PrimeFaces' jquery.js, but I can't figure out how to do it or if it's possible. If I copy the PF version to my locally mapped resources, of course, I can successfully do it. Just wondering if there's a syntax for doing it directly (from the documentation, it sounds like the left side of the mapping can include a library reference, but maybe the right side can't).

          The section "Mapping resource name to relative URL" covers this aspect:

          http://docs.jboss.org/richfaces/4.2.X/4.2.0.Final/Developer_Guide/en-US/html/chap-Developer_Guide-Advanced_features.html#d0e1705

           

          In fact, you can point to the library using e.g. following mapping:

           

          jquery.js=primefaces/jquery/jquery.js
          

           

          I hope I'm right here with the PrimeFaces library being "primefaces:jquery:jquery.js" ;-)

          1 of 1 people found this helpful
          • 3. Re: Resource Mapping (again) in RichFaces 4.2.0 Final
            Josh Schneider Newbie

            Thanks for the detailed response, Lukáš. And sorry, I now have two kind of duplicate posts (https://community.jboss.org/thread/195450)

             

            A couple of follow-ups:

             

            1)

            Hi Josh, nice catch, the documentation is wrong here:  https://github.com/richfaces/core/blob/develop/impl/src/main/java/org/richfaces/resource/ResourceMappingConfiguration.java#L44  (resources != richfaces)

            This wasn't working for me last time I tried, but I'll try again. At least it's clear to me that this file (static-resource-mappings.properties) is supposed to be picked up automatically, without any other configuration. The rest of this discussion is now in another post: https://community.jboss.org/thread/195450

             

            2)

            I think the right format should be (as you need to escape ":" character as separated between library and resource name):

            Sorry, I mistyped. You are correct, and this kind of mapping does work.

             

            3) I will try this again, also. Not sure whether I got the path exactly right, but yes, the particular file is within a folder called jquery in the primefaces jar.

             

            Finally, from another reply, you say that as of RF 4.2, jquery isn't inlcuded in the packed.js. This is good to know, and a great idea that all JSF libraries should emulate. I still think I may end up doing all my optimization with either RichFaces' or PrimeFaces' maven plugin, but it may be very helpful down the line to be able to point to a CDN, if desired, and still use RF optimization.

             

            I'll take a look at the new packed.js to see whether the same holds true for the jquery-ui. One issue is that neither RF or PF utilizes the entire UI, and, in fact, it's a general issue that most people won't use all the UI features, instead opting for a custom download. If both projects could specify exactly what they do use from the UI, people could make their custom builds, including the necessary resources for the JSF lib, and load them from a local, static location. Using a CDN in this case makes little sense, since you'd have to pull down the entire UI library in order to benefit from the chance that it was already cached on a user's machine.

             

            And, of course, it's not your issue that PrimeFaces hasn't come up with a way to separate PF native resources from the jQuery libraries.

             

            I really appreciate all the work you guys are doing and the quality documentation and forums.

             

            Best Regards,

             

            Josh