5 Replies Latest reply on Feb 15, 2007 4:53 PM by saeediqbal1

    Tip worthy of inclusion in the documentation...

    tony.herstell1

      Can this be added to the doco.. it's a great tip.

      perhaps close to pg 67


      The <factory> declaration lets you specify a value or method binding expression that will be evaluated to initialize
      the value of a context variable when it is first referenced.
      <components>
      <factory name="contact" method="#{contactManager.loadContact}" scope="CONVERSATION"/>
      </components>





      I also use the following in components.xml
      
      <factory name="basePath"
       value="#{facesContext.externalContext.request.scheme}://#{facesContext.externalContext.request.serverName}:
      #{facesContext.externalContext.request.serverPort}#{facesContext.externalContext.request.contextPath
      }/"/>
      




      Note this is all one line the forum wrapped

      and

      
      <base href="#{basePath}" />
      
      


      So i can have the view files in different directories, but still resolve the images and css to the root of the webapp with out having to do ../../images/myimage.jpg

      I used to use something like this

      
       @Create
       public void setup() {
       request = (HttpServletRequest) facesContext.getExternalContext().getRequest();
       }
      
      
       @Factory("basePath")
       public void loadBasePath()
       {
       basePath = request.getScheme() + "://" +
       request.getServerName() + ":" +
       request.getServerPort() + request.getContextPath() + "/";
       }
      
      



      _________________
      Thank you for your time,

      Jason Long
      CEO and Chief Software Engineer
      BS Physics, MS Chemical Engineering
      http://www.supernovasoftware.com
      HJBUG Founder and President
      http://www.hjbug.com




      led to me re-organising my code a lot:
      <link rel="stylesheet" type="text/css" ref="#{basePath}/xmlhttp/css/xp/xp.css" />
      <link rel="stylesheet" type="text/css" href="#{basePath}/css/risingstars.css" />
      


      Allowing me to move a lot of pages that users should not access under WEB-INF

      template="/WEB-INF/pages/template.xhtml">
      



      Perhaps it obvious to you lot, but saved me a whole heap of headache.