我需要在同一个 bean 上设置 2 个不同的 ManagedProperty。所以我试过:
@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; }
}
但不幸的是,我不能写 2 个不同的 @ManagedProperty :它说重复注释。我该如何解决?
另一个:当我返回这个值时,它是一个字符串,我需要对抗。此语法:
<h:panelGroup rendered="#{selector.profile_page.compareTo("main")}">
<ui:include src="/profile/profile_main.xhtml" />
</h:panelGroup>
将工作?
干杯
最佳答案
注释必须直接在感兴趣的类、方法或字段之前声明。
所以:
@ManagedProperty(value="#{param.page}")
private String page;
@ManagedProperty(value="#{param.profile_page}")
private String profile_page;
关于JSF - 在单个 bean 中在 @ManagedProperty 上设置多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4279571/