Re: Given a resource URI, how to find out which group it belongs to in wro4j

50 views
Skip to first unread message

Alex Objelean

unread,
Jun 14, 2012, 3:01:49 AM6/14/12
to wr...@googlegroups.com
The WroModel can be accessed using WroModelFactory. 
You can inspect the model by iterating on available groups collections and find if a particular resource is part of the group. 
If you find it useful, the WroModel will be added a new method: List<Group> getGroupsOfResource(Resource resource);  

Alex

On Thursday, June 14, 2012 4:05:44 AM UTC+3, doncar...@gmail.com wrote:
I would like to know which group/groups has got a particular resource  n it. For eg: I want to know which Group consists the resource with the uri - http:/static.com/static/foo.css

.?

unread,
Jun 19, 2012, 9:03:58 PM6/19/12
to wr...@googlegroups.com
Thank you. It would be easier with an api instead. Will update you how it goes. Thanks again.

Alex Objelean

unread,
Jun 20, 2012, 9:59:05 AM6/20/12
to wr...@googlegroups.com
Ok, I'll add a new method which will expose this information in WroModel.

Cheers,
Alex

.?

unread,
Jun 21, 2012, 9:13:37 PM6/21/12
to wr...@googlegroups.com
Hi,

How can I access the WroModel from a spring bean ? I was using the following code and it is erroring out saying "No context associated with CURRENT request cycle!";

      ServletContextAttributeHelper helper =  new ServletContextAttributeHelper(m_context);
        WroManagerFactory wroManagerFactory = helper.getManagerFactory();
        WroManager wroManager = wroManagerFactory.create();    // This is the line where error is occuring !


        WroModelFactory wroModelFactory = wroManager.getModelFactory();
        WroModel wroModel = wroModelFactory.create();
        Collection<Group> groups = wroModel.getGroups();
        for (Group group : groups) {
            List<Resource> resources = group.getResources();
            for (Resource resource : resources) {
                m_map.put(resource.getUri(), group.getName());
            }
        }

Thank you.

Alex Objelean

unread,
Jun 22, 2012, 4:29:49 AM6/22/12
to wr...@googlegroups.com
Every operation performed by wro4j requires to access the Context object (the one which contains details about current request). The model can be inspected only during the request. You can find more details on this page: http://code.google.com/p/wro4j/wiki/WroServletContextListener  (@see AddWroContextFilter to web.xml section).

It is possible to access the model outside the request filter, but it won't be the same instance used by wro4j. You can build it using XmlModelFactory and loading from the location where the wro.xml is stored or GroovyModelFactory for loading wro.groovy file. Find more about model on wiki: http://code.google.com/p/wro4j/wiki/WroModel

Cheers,
Alex

Martin Grigorov

unread,
Jun 22, 2012, 4:33:36 AM6/22/12
to wr...@googlegroups.com
Hi,

Making your bean request or session scoped should help.
> --
> You received this message because you are subscribed to the Google Groups
> "wro4j" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/wro4j/-/2eHl9TJQc4UJ.
> To post to this group, send email to wr...@googlegroups.com.
> To unsubscribe from this group, send email to
> wro4j+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/wro4j?hl=en.

Alex Objelean

unread,
Jun 22, 2012, 4:40:55 AM6/22/12
to wr...@googlegroups.com
That's true, but you still have to map WroFilter to /* or similar in order to make the Context available.

Alex
Reply all
Reply to author
Forward
0 new messages