На странице отображены ссылки, нажав на которую должен отображаться определенный контент. Не могу понять почему не отображается контент. При вызове метода findId()
параметр с именем "id_action"
не передается в Managed Bean и полю name присваивается значение null
. Подскажите пожалуйста, как исправить данную ошибку?
Код основной страницы main.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Facelets Template</title>
<h:outputStylesheet library="css" name="main.css"/>
<h:outputStylesheet library="css" name="leftmen3"/>
</h:head>
<h:body>
<ui:composition template="/templates/lesson_template.xhtml">
<ui:define name="content">
<div class="content">
<h:outputText value="#{lessonController.content}" />
</div>
</ui:define>
</ui:composition>
</h:body>
</html>
Код страницы lesson_template.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Facelets Template</title>
<h:outputStylesheet library="css" name="main.css"/>
</h:head>
<h:body>
<div>
<ui:insert name="leftmenu">
<ui:include src="../templates/leftmenu.xhtml"></ui:include>
</ui:insert>
<ui:insert name="content">
<ui:include src="../templates/content.xhtml"></ui:include>
</ui:insert>
</div>
</h:body>
</html>
Код страницы leftmenu.xhtml
<ui:composition>
<h:dataTable value="#{lessonController.lessonList}" var="less" >
<h:column>
<h:form>
<h:commandLink action="#{lessonController.findId()}" value="#{less.name}">
<f:param name="id_action" value="#{less.name}"></f:param>
</h:commandLink>
</h:form>
</h:column>
</h:dataTable>
</ui:composition>
Код Managed Bean
@ManagedBean(eager=true)
@ApplicationScoped
public class LessonController implements Serializable {
private ArrayList <Lesson> lessons;
private String content ="";
private String name ="";
public LessonController() {
fillLessonAll();
}
private void fillLessonAll() {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
lessons = new ArrayList <Lesson> ();
try {
conn = DataBase.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from lessons");
while(rs.next()){
Lesson lesson = new Lesson();
lesson.setName(rs.getString("name"));
lesson.setLesson(rs.getString("lesson"));
lesson.setId(rs.getInt("idlessons"));
lessons.add(lesson);
}
}catch (SQLException ex){
Logger.getLogger(DataBase.class.getName()).log(Level.SEVERE,null,ex);
} finally {
try {
if(conn!=null) conn.close();
if(stmt!=null) stmt.close();
if(rs!=null) rs.close();
} catch (SQLException ex) {
Logger.getLogger(LessonController.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
public ArrayList<Lesson> getLessonList (){
return lessons;
}
public void findId() {
Map <String,String> params = FacesContext.getCurrentInstance().getExternalContext().getInitParameterMap();
name = params.get("id_action");
for(Lesson less : lessons) {
if(less.getName().equals(name)) content = less.getLesson();
}
}
public String getContent() {
return content;
}
}