5 Replies Latest reply on Apr 27, 2009 2:18 AM by domdom

    howto access unknown resource data from a renderer?

      Ok, I have the following problem which I just cannot figure out:
      I wrote several own components along with own renderers. They use css styles, which are defined via some xcss files. These css properties can be dynamically changed via some other custom property files, so that layout and style may change after restarting the web application. Although the css properties correctly affect all instances of a component in the same way, there is one case, where I have to change some properties to fit with other data.
      To be more concrete: I have a button (a subclass of CommandButton), which accepts a value as attribute. Depending on the length of the value (which is actually the text that is displayed on the button), the size of a background image have to change to accommodate the length of the text. The background image is rendered with a BackgroundResource (subclass of Java2Dresource) and beside the size, this BackgroundResourceRenderer needs several other properties, which are coming from the xcss files.
      This may be a little confusing, but actually I just need a way to access a resource, which is connected to a css class and created from a xcss file, from an 'encode'-block of a component renderer to get all data, the resource is based on. If I had these, I could change the size values (since they are depending on the length of the text) and render another BackgroundResource, which suits my needs (the length of the text).
      So far, the actual connection between what I'm encoding and what richfaces has generated in a style file sitting in the head part of the generated html output is only happening in the browser.
      I hope anyone has any clues. So far this forum was very helpful ;)
      Thx for reading.

        • 1. Re: howto access unknown resource data from a renderer?
          nbelaevski

          Hello,

          I'm not sure, I'm getting the case right, but I'll try to help. If you need to get URI to customized resource you can:

          1. Get resource object instance by its name: org.ajax4jsf.resource.InternetResourceBuilder.getResource(String). Note: resource should be registered in resources-config.xml

          2. Pass in data and get back resource URI that you can output to the page: org.ajax4jsf.resource.InternetResource.getUri(FacesContext, Object)

          Working with XCSS resources directly is completely different flavor; moreover that's not an API intended for public usage. Is it possible to keep all references to value inside resource class so that it will be independent of XCSS?

          • 2. Re: howto access unknown resource data from a renderer?

            Hi.
            First of all, thx a lot for looking into this.
            I try to clarify my situation:
            Actually i have a client application using some highly configurable components, which now get counterparts for the same application running in a web environment. Since I already have editors and configuration files for these client components, I want to use the same stock of configuration files for the web components. I translate these properties with something like a cssfactory and put them in a managed bean (while initializing the bean) and access them with generated xcss files over a *.skin.properties file, which contains something like this:
            button_txt.font-family=#{skinBean['button_txt.font-family']}
            This is what you had suggested in another post (thx again! ;)).
            Basically this is fine, since it's not needed to change configuration during run-time, except the one case, where something like text length dictates a size (like mentioned before) and an already existing resource has to be changed slightly and created anew.
            I'm already creating other resources too, by using framework methods like 'getResource(..)' and 'getUri(..)' but they work only with attribute data of the tag, like 'value' (in the case of the commandbutton).
            So now I'm in the unlucky position that I need data from different 'positions'.
            Actually what you wrote in your last sentence might be the best way, but so far I had no other idea to get the needed configuration data in the css classes (or in the data store or resourcerenderers), then by using xcss 'template' files.
            If there would be a way to access the data, which resides in my skinBean without using the xcss files, I think I could render every needed resource directly in the encode parts of the components... Isn't it possible to evaluate some EL-expressions from anywhere to get any data?

            • 3. Re: howto access unknown resource data from a renderer?

              I thought, I give it a try, to get the needed data directly from my skinBean (which is actually a Map<String, String>), but I'm not sure how I can access it.
              I tried this:

              ValueExpression ve = ex.createValueExpression("#{skinBean['button_txt.font-family']}", String.class);
              String value = (String)ve.getValue(context.getELContext());
              


              Obviously, skinBean does not return the expected value for the key, because the result for value is 'button_txt.font-family'.
              So, what do I have to do manually, to retrieve the values from the skinBean, similar to what the framework is doing by evaluating the expression from the *.skin.properties file:

              button_txt.font-family=#{skinBean['button_txt.font-family']}
              


              to fill in values in the xcss files ?

              • 4. Re: howto access unknown resource data from a renderer?
                nbelaevski

                Use a4jSkin instead of skinBean:

                #{a4jSkin['headerBackgroundColor']}


                • 5. Re: howto access unknown resource data from a renderer?

                  Hello.

                  Ok, thx, I could do that I guess.
                  However, just for future references to this subject, there is also the option to retrieve the whole skinBean just like this:

                  ExpressionFactory ex = FacesContext.getCurrentInstance().getApplication().getExpressionFactory();
                  ValueExpression valueExpression = ex.createValueExpression(context, "#{skinBean}", SkinBean.class);
                  if(valueExpression != null) {
                   return (SkinBean) valueExpression.getValue(context);
                  }
                  return null;
                  


                  Currently, I'm doing that, since this way I can wrap utility methods which give me certain collections of skin attributes.
                  Thx anyway! ;)