what I have is jsf page that shows users in a table, one of the columns is commandbutton, that hides that table and shows another table with all articles that that user has.Here things are OK. The articles table again has column with commandbuttons that has to hide that table and show the article content, but it shows the user table. In my bean I have 3 properties
private Boolean usersViewActive;
private Boolean articlesViewActive;
private Boolean articleContentViweActive;
and methods that activate one of them and deactivate the others
public void activateUsersView() {
this.usersViewActive = true;
this.articlesViewActive = false;
this.articleContentViweActive=false;
}
public void activateArticleView() {
this.usersViewActive = false;
this.articlesViewActive = true;
this.articleContentViweActive = false;
}
public void activateArticleContentView() {
this.articleContentViweActive = true;
this.usersViewActive = false;
this.articlesViewActive = false;
}
My bean
@ManagedBean
@RequestScoped
public class DataBean {
private List<UserAcc> users;
private List<Article> articles;
private List<ArticleComment> articleComments;
private Article currentArticle;
private Boolean usersViewActive;
private Boolean articlesViewActive;
private Boolean articleContentViweActive;
public DataBean() {
DataBaseUtil dbu = new DataBaseUtil();
users = dbu.loadUsers();
this.usersViewActive = true;
}
public void activateUsersView() {
this.usersViewActive = true;
this.articlesViewActive = false;
this.articleContentViweActive=false;
}
public void activateArticleView() {
this.usersViewActive = false;
this.articlesViewActive = true;
this.articleContentViweActive = false;
}
public void activateArticleContentView() {
this.articleContentViweActive = true;
this.usersViewActive = false;
this.articlesViewActive = false;
}
public void loadArticles(ActionEvent e) {
DataBaseUtil dbu = new DataBaseUtil();
int userId = (Integer) e.getComponent().getAttributes().get("userId");
articles = dbu.loadUserArticles(userId);
}
public void loadComments(ActionEvent e) {
DataBaseUtil dbu = new DataBaseUtil();
int articleId = (Integer) e.getComponent().getAttributes()
.get("articleId");
articleComments = dbu.loadArticleComments(articleId);
}
public void loadCurrentArticle(ActionEvent e) {
DataBaseUtil dbu = new DataBaseUtil();
int articleId = (Integer) e.getComponent().getAttributes()
.get("articleId");
this.currentArticle = dbu.loadArticleById(articleId);
}
Getters and Setters...
}
My Page:
<h:body>
<h:panelGroup rendered="#{loginBean.authorised}">
User: <h:outputText value="#{loginBean.name}"></h:outputText>
<a href="new_article.jsf">Add article</a>
</h:panelGroup>
<h:panelGroup rendered="#{not loginBean.authorised}">
<h:outputText>You are not authorised to be here!</h:outputText>
<a href="index.jsf">Login or Registrate</a>
</h:panelGroup>
<h:form>
<h:panelGroup rendered="#{loginBean.authorised}">
<!-- All users -->
<h:panelGroup rendered="#{dataBean.usersViewActive}">
<rich:dataTable value="#{dataBean.users}" var="user" rows="10">
<f:facet name="header">Users</f:facet>
<rich:column>
<f:facet name="header">User Id</f:facet>
<h:outputText value="#{user.id}"></h:outputText>
</rich:column>
<rich:column>
<f:facet name="header">User Name</f:facet>
<h:outputText value="#{user.name}"></h:outputText>
</rich:column>
<rich:column>
<h:commandButton value="Show articles"
action="#{dataBean.activateArticleView}"
actionListener="#{dataBean.loadArticles}">
<f:attribute name="userId" value="#{user.id}"></f:attribute>
</h:commandButton>
</rich:column>
<f:facet name="footer">
<rich:dataScroller></rich:dataScroller>
</f:facet>
</rich:dataTable>
</h:panelGroup>
<!-- All articles -->
<h:panelGroup rendered="#{dataBean.articlesViewActive}">
<h:commandButton value="Back to users"
action="#{dataBean.activateUsersView}"></h:commandButton>
<rich:dataTable value="#{dataBean.articles}" var="article" rows="10">
<f:facet name="header">Articles</f:facet>
<rich:column>
<f:facet name="header">Article Id</f:facet>
<h:outputText value="#{article.id}"></h:outputText>
</rich:column>
<rich:column>
<f:facet name="header">Article Title</f:facet>
<h:outputText value="#{article.title}"></h:outputText>
</rich:column>
<rich:column>
<!-- Here is the problem -->
<!-- This button renders all users instead article content -->
<h:commandButton value="Show article content and comments"
action="#{dataBean.activateArticleContentView}"
actionListener="#{dataBean.loadCurrentArticle}">
<f:attribute name="articleId" value="#{article.id}"></f:attribute>
</h:commandButton>
</rich:column>
<f:facet name="footer">
<rich:dataScroller></rich:dataScroller>
</f:facet>
</rich:dataTable>
</h:panelGroup>
<!-- Article content -->
<h:panelGroup rendered="#{dataBean.articleContentViweActive}">
<h:outputText value="#{dataBean.currentArticle.title}"></h:outputText>
<h:outputText value="#{dataBean.currentArticle.text}"></h:outputText>
</h:panelGroup>
</h:panelGroup>
</h:form>
</h:body>