我将一个参数传递给@ManagedBean的@PostConstruct方法时遇到了一些问题。我已经知道不能这样做,但我也不知道如何做。JSF - 将参数传递给@PostConstruct方法
让我们先从一些代码:
<h:form>
<h:dataTable value="#{accountsList.accountsList}" var="konto">
<h:column>
<f:facet name="header">#{messages.id}</f:facet>
#{konto.id}
</h:column>
<h:column>
<f:facet name="header">#{messages.login}</f:facet>
<h:commandLink value="#{konto.login}" action="#{profileViewer.showProfile()}" />
</h:column>
.........
</h:dataTable>
</h:form>
上面的XHTML是用来显示帐户列表。
看看commandLink。我想将它的值(用户的登录名)作为参数传递给作为ProfileViewer bean的PostConstruct方法的操作方法。
这里的ProfileViewer bean代码:
@ManagedBean
@RequestScoped
public class ProfileViewer {
@EJB
private MokEndpointLocal mokEndpoint;
private Konta konto;
private String login;
@PostConstruct
public String showProfile(){
konto = mokEndpoint.getAccountByLogin(login);
return "profile";
}
public Konta getKonto() {
return konto;
}
public void setKonto(Konta konto) {
this.konto = konto;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public ProfileViewer() {
}
}
我怎样才能做到这一点?请帮帮我!我将不胜感激一个简单而好的解决方案和一些代码的答案。
好的,我会这样说: 我有一个显示帐户列表的JSF页面。我想每个帐户名(登录)是一个链接资料信息(这是显示关于选择的帐户信息其他JSF页面)
你究竟想在这里获得什么?请删除不必要的变量,使问题更清楚。 – 757071
通过此链接http://balusc.blogspot.in/2011/09/communication-in-jsf-20.html。它对JSF-2.0中的通信给出了一个清晰的概念。 – 757071