-
1. Re: howto access unknown resource data from a renderer?
nbelaevski Apr 17, 2009 6:51 AM (in response to domdom)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?
domdom Apr 17, 2009 8:39 AM (in response to domdom)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?
domdom Apr 17, 2009 10:58 AM (in response to domdom)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 Apr 19, 2009 9:04 AM (in response to domdom)Use a4jSkin instead of skinBean:
#{a4jSkin['headerBackgroundColor']}
-
5. Re: howto access unknown resource data from a renderer?
domdom Apr 27, 2009 2:18 AM (in response to domdom)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! ;)