Page Actions with Annotations does not work with @URLMappingS

Splash Forums PrettyFaces Users Page Actions with Annotations does not work with @URLMappingS

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #19507

    albertoivo
    Participant

    Hello,

    This works perfect:

    @Named("bean")
    @URLMapping(id = "viewItem", pattern = "/store/item/#{ bean.itemId }", viewId = "/faces/shop/item.jsf")
    public class Bean implements Serializable {
    private String itemId;
    @URLAction
    public String load() { ... }
    // getters & setters
    }

    but this does NOT work:

    @Named("bean")
    @URLMappings(mappings={
    @URLMapping(id = "itemBean", pattern = "/store", viewId = "/faces/store.jsf"),
    @URLMapping(id = "itemBean2", pattern = "/shop/#{ bean.itemId }/", viewId = "/faces/shop/store.jsf")
    })
    public class Bean implements Serializable {
    private String itemId;
    @URLAction(mappingId = "itemBean2")
    public String load() { ... }
    // getters & setters
    }

    ERROR MESSAGE:

    Critical Exception!: com.ocpsoft.pretty.PrettyException: PrettyFaces: Exception occurred while building URL for MappingId < categoryBean2 >, Required value < #{bean.itemId} > was null

    anybody could help with this? Is this a bug or limitation from PrettyFaces that URLAction does not work properly with multiple @URLMapping ?

    #23414

    albertoivo
    Participant

    Well..

    It’s weird, but what I did to fix it:

    private String itemId = "";

    Only initialize it with an empty String.. but even without initialize it, it should be an empty String already and not null. should’nt it?

    #23415

    This exception is basically telling you that PrettyFaces was trying to build an URL for the mapping itemBean2 for rendering it to the page and the current value of #{bean.itemId} was null, which cannot work. Of cause initializing the value with an empty String will work and result in an URL like /shop// but I don’t think this is what you want.

    You can have a look at the stracktrace to get an idea of which component is trying to render the URL.

    BTW: You didn’t specify a scope on your bean. In this case the bean will be @Dependent scoped which will properly not be what you want any MAY cause this issue.

    BTW2: Although PrettyFaces offers the @URLMappings for defining multiple mappings for one page I doubt that it makes sense to do so. Every JSF application I developed in the last years is using PrettyFaces for rewriting but I found not a single usercase for @URLMappings. So you could think about if there is some other way to structure your beans.

    #23416

    albertoivo
    Participant

    Thanks Christian…

    The problem was solved…

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

You must be logged in to reply to this topic.

Comments are closed.