我在将参数传递给我的@ManagedBean 的@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 页面)