add new mapping during runtime

Splash Forums PrettyFaces Users add new mapping during runtime

This topic contains 4 replies, has 2 voices, and was last updated by  dev123 5 years, 3 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #18469

    dev123
    Participant

    hi,

    i try to add a new url mapping at runtime, but it does not work.

    On server startup i load the pretty config and add the mapping from db (ConfigurationProvider).

    Now i would like to add a new mapping at runtime, but it occurs an exception, since the mapping list is already in use.

    is there any way to add new mappings add runtime?

    Thanks.

    #22691

    I think adding mappings at runtime should actually work fine. Could you post some more details. Which exception do you get?

    #22692

    dev123
    Participant

    Thanks for the quick response :).

    I`m using PrettyFaces in Version 3.3.3 for JSF2. I want to add a new link to the current mapping. In the method I want to create a new UrlMapping like this:

    UrlMapping urlMapping = new UrlMapping();
    urlMapping.setId("my_unique_id");
    urlMapping.setViewId("/MyPage");
    urlMapping.setPattern("/myPage.jsf");

    and add this mapping to the current configuration like this:

    PrettyContext.getCurrentInstance().getConfig().getMappings().add(urlMapping);

    now this exception occurs:

    Caused by: java.lang.UnsupportedOperationException
    at java.util.Collections$UnmodifiableCollection.add(Collections.java:1018)

    #22693

    Hmmm, yeah, that’s because getMappings() returns an unmodifiable view for the list of mappings. So adding a mapping to this list won’t work. But you could use setMappings() to work around this. Just retrieve the current list of mappings and construct a new list which also contains the new mapping. Than use setMappings() to set the new mapping list.

    I know that this isn’t a very nice solution, but it should work. Adding mappings dynamically is a very rare usecase nobody thought of while building the API back then. :)

    #22694

    dev123
    Participant

    Hi,

    thank you very much. it works fine :).

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

Comments are closed.