开发者

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

开发者 https://www.devze.com 2023-01-26 18:49 出处:网络
I need to set 2 different ManagedProperty on the same bean. So i tried : @ManagedBean(name=\"selector\")

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=pag开发者_运维百科e; }
}

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


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号