我將一個參數傳遞給@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