Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF - Set multiple values on @ManagedProperty in a single bean

I need to set 2 different ManagedProperty on the same bean. So i tried :

@ManagedBean(name="selector")
@RequestScoped
public class Selector {
    @ManagedProperty(value="#{param.page}")
    @ManagedProperty(value="#{param.profile_page}")
    private String page;
    private String profile_page;

    public String getProfile_page() { 
        if(profile_page==null || profile_page.trim().isEmpty()) {
            this.profile_page="main";
        }
        return profile_page;
    }
    public void setProfile_page(String profile_page) { this.profile_page = profile_page; }

    public String getPage() {
        if(page==null || page.trim().isEmpty()) {
            this.page="homepage";
        }
        return page;
    }
    public void setPage(String page) { this.page=page; }
}

but unfortunatly i can't write 2 different @ManagedProperty : it says duplicate annotations. How can I fix it?

Another : when i return this value, its a String, and i need to confrontate. This syntax :

<h:panelGroup rendered="#{selector.profile_page.compareTo("main")}">
    <ui:include src="/profile/profile_main.xhtml" />
</h:panelGroup>

will work?

Cheers

like image 845
markzzz Avatar asked Dec 29 '22 04:12

markzzz


1 Answers

The annotations have to be declared directly before the class, method or field of interest.

So:

@ManagedProperty(value="#{param.page}")
private String page;

@ManagedProperty(value="#{param.profile_page}")
private String profile_page;
like image 174
BalusC Avatar answered Jan 31 '23 07:01

BalusC