Hi.
Ich habe eine Frage bezüglich der View Parameter. Ich habe folgendes Problem:
Ich will über einen Link einen bestimmten Datensatz aus der Datenbank auslesen. Wenn ich auf einen Link klicke, erscheint in der Adresszeile meines Browsers die korrekte URL, allerdings wird der Datensatz nicht auf der Seite angezeigt. Ich benutze hierfür folgende Klassen bzw. Views:
Klasse CompanySiteController:
View1: Index.xhtml
View2: companyHome.xhtml
Könnt ihr mir bei dem Problem helfen und einen Denkanstoß geben?
Ich habe eine Frage bezüglich der View Parameter. Ich habe folgendes Problem:
Ich will über einen Link einen bestimmten Datensatz aus der Datenbank auslesen. Wenn ich auf einen Link klicke, erscheint in der Adresszeile meines Browsers die korrekte URL, allerdings wird der Datensatz nicht auf der Seite angezeigt. Ich benutze hierfür folgende Klassen bzw. Views:
Klasse CompanySiteController:
Java:
package de.zerrenda.zerrendaee6.controller;
import de.zerrenda.zerrendaee6.entities.Company;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Named
@SessionScoped
public class CompanySiteController implements Serializable{
@PersistenceContext(unitName="ZerrendaPU")
EntityManager em;
private int companyId;
private Company company;
public int getCompanyId() {
return companyId;
}
public void setCompanyId(int id) {
this.companyId = id;
}
public Company getCompany() {
return company;
}
public void setCompany(Company company) {
this.company = company;
}
public String goToCompanySite(int id){
setCompanyId(id);
company = em.find(Company.class, getCompanyId());
return "/Sites/companyHome.xhtml";
}
}
View1: Index.xhtml
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:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<body>
<ui:composition template="./META-INF/templates/template.xhtml">
<ui:define name="left">
left
</ui:define>
<ui:define name="right">
right
</ui:define>
<ui:define name="content">
<p align="center">Zerrenda Logo</p>
<div align="center">
<h:form>
<h:panelGrid columns="2">
<p:inputText id="suchfeld" size="80" />
<p:commandButton value="Suche"/>
</h:panelGrid>
</h:form>
</div>
<div align="center">
<h:form>
<h:panelGrid columns="3">
<p:dataTable value="#{companyListProducer.latest5Companys}" var="latest">
<p:column>
<f:facet name="header">
<h:outputText value="Neueste Einträge" />
</f:facet>
<h:link outcome="companyHome" value="#{latest.companyId}">
<f:param name="companyId" value="#{latest.companyId}"/>
</h:link>
</p:column>
</p:dataTable>
<p:dataTable>
<p:column>
<f:facet name="header">
<h:outputText value="Häufigste Produktgruppen" />
</f:facet>
</p:column>
</p:dataTable>
<p:dataTable>
<p:column>
<f:facet name="header">
<h:outputText value="Häufigste Suchbegriffe" />
</f:facet>
</p:column>
</p:dataTable>
</h:panelGrid>
</h:form>
</div>
</ui:define>
</ui:composition>
</body>
</html>
View2: companyHome.xhtml
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:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:metadata>
<f:viewParam name="companyId" value="#{companySiteController.companyId}"></f:viewParam>
</f:metadata>
<h:head>
<title>Zerrenda #{companySiteController.company.companyName}</title>
</h:head>
<body>
<ui:composition template="./../META-INF/templates/template.xhtml">
<ui:define name="content">
CompanyId = <h:outputText value="#{companySiteController.companyId}" />
</ui:define>
</ui:composition>
</body>
</html>
Könnt ihr mir bei dem Problem helfen und einen Denkanstoß geben?