Nie mam zielonego pojęcie jak naprawić ten błąd...
Otóż nie działa mi słuchacz NodeSelected.
Według mnie to przez <h:form> ponieważ gdy wstawiłem go do książki.XHTML i uruchomiłem jako samodzielny plik to wszystkie działało jak należy ale gdy tylko podłączyłem go do index.xhtml to już nie działo. Wyskakiwał mi taki komunikat:
"The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form>"
Wydaje mi się, że on wyskakuje bo coś w menu.XHTML jest nie tak, próbowałem to naprawić wstawiając <h:form> od
Mam nadzieję, że ktoś będzie wiedział jak to naprawić :)</p>
Główny HTML:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
<h:outputStylesheet library="css" name="style.css" />
<title>Wypożyczalnia książek</title>
</h:head>
<h:body>
<div id="container">
<div id="head">
<ui:include src="Szablony/logo.xhtml" />
</div>
<div id="underHead">
<ui:include src="Szablony/underHead.xhtml" />
</div>
<div id="menuBar">
<ui:include src="Szablony/menu.xhtml" />
</div>
<div id="mainPanel">
<h:panelGroup id="includeContainer">
<h:panelGroup rendered="#{stronaGlowna.wiadomosc == 'klienci'}">
<ui:include src="Szablony/klienci.xhtml" />
</h:panelGroup>
<h:panelGroup rendered="#{stronaGlowna.wiadomosc == 'ksiazki'}">
<ui:include src="Szablony/ksiazki.xhtml" />
</h:panelGroup>
<h:panelGroup rendered="#{stronaGlowna.wiadomosc == 'glowna'}">
<ui:include src="Szablony/glowna.xhtml" />
</h:panelGroup>
</h:panelGroup>
</div>
<div id="sidePanel">
<ui:include src="Szablony/windowLogin.xhtml" />
</div>
</div>
</h:body>
</html>
menu HTML:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<div id="lista">
<ul>
<li>
<p:commandLink action="#{stronaGlowna.strglowna()}" value="Strona główna" update="includeContainer" />
</li>
<li>
<p:commandLink action="#{stronaGlowna.ksiazki()}" value="Książki" update="includeContainer" />
</li>
<li>
<p:commandLink action="#{stronaGlowna.klienci()}" value="Klienci" update="includeContainer" />
</li>
</ul>
</div>
</ui:composition>
książki HTML:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:form id="form">
<p:growl id="messages" showDetail="true" />
<p:tree value="#{treeEventsView.root}" var="doc" selectionMode="single" animate="true" selection="#{treeEventsView.selectedNode}">
<p:ajax event="select" update=":form:messages" listener="#{treeEventsView.onNodeSelect}" />
<p:treeNode expandedIcon="ui-icon-folder-open" collapsedIcon="ui-icon-folder-collapsed">
<h:outputText value="#{doc}"/>
</p:treeNode>
</p:tree>
</h:form>
</ui:composition>
DocumentService:
@ManagedBean(name = "documentService")
@ApplicationScoped
public class DocumentService {
private TreeNode root;
public TreeNode createDocuments() {
root = new DefaultTreeNode("Root", null);
TreeNode node = new DefaultTreeNode("Lista wszystkich książek", root);
Connection con = connection();
String sqlCommand = "select * from ksiazka ORDER BY tytul;";
try {
PreparedStatement ps = (com.mysql.jdbc.PreparedStatement) con.prepareStatement(sqlCommand);
ResultSet rs = ps.executeQuery();
while(rs.next()){
TreeNode treeNode = new DefaultTreeNode(rs.getString("tytul"), node);
}
} catch (SQLException ex) {
Logger.getLogger(DocumentService.class.getName()).log(Level.SEVERE, null, ex);
}
return root;
}
}
EventsView:
@ManagedBean(name="treeEventsView")
@ViewScoped
public class EventsView implements Serializable {
private TreeNode root;
private TreeNode selectedNode;
@ManagedProperty("#{documentService}")
private DocumentService service;
@PostConstruct
public void init() {
root = service.createDocuments();
}
public TreeNode getRoot() {
return root;
}
public TreeNode getSelectedNode() {
System.out.println("getSN");
return selectedNode;
}
public void setSelectedNode(TreeNode selectedNode) {
System.out.println("setSN");
this.selectedNode = selectedNode;
}
public void setService(DocumentService service) {
this.service = service;
}
public void onNodeSelect(NodeSelectEvent event) {
System.out.println("Wydarzenie się wydarzyło");
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Selected", event.getTreeNode().toString());
FacesContext.getCurrentInstance().addMessage(null, message);
}
}