我有这个网址:
https://localhost:8181/Platform2/faces/admin/applicationDetails.xhtml?applicantid=16&applicationid=5
当我在浏览器上介绍这个时,我必须登录才能看到这个页面的内容。它应该显示申请人和申请的详细信息(申请人和申请是我的Web maven项目的实体)。问题是,当我这样做时,页面不会检索任何内容。当我再次输入URL时,会显示所需的内容。我的JSF网页是:
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<body>
<ui:composition template="./mainadmin.xhtml">
<ui:define name="content">
<h:form>
<h2 >Application details of #{applicationDetailsRequestBB.applicant.username}</h2>
<h:panelGrid columns="2" >
<h:outputText value="First Name" />
<h:outputText value="#{applicationDetailsRequestBB.applicant.firstName}" />
<h:outputText value="Last Name:" />
<h:outputText value="#{applicationDetailsRequestBB.applicant.lastName}" />
<h:outputText value="CV" />
<h:link outcome="#{applicationDetailsRequestBB.cvPath}" target="_blank" value="cv">
</h:link>
<h:outputText value="Cover Letter" />
<h:link outcome="#{applicationDetailsRequestBB.coverLetterPath}" target="_blank" value="cl">
</h:link>
<h:outputText value="Email:" />
<h:outputText value="#{applicationDetailsRequestBB.applicant.email}" />
<h:outputText value="Address:" />
<h:outputText value="#{applicationDetailsRequestBB.applicant.address}" />
<h:outputText value="City:" />
<h:outputText value="#{applicationDetailsRequestBB.applicant.city}" />
<h:outputText value="Phone:" />
<h:outputText value="#{applicationDetailsRequestBB.applicant.phone}" />
<h:outputText value="Mobile Phone:" />
<h:outputText value="#{applicationDetailsRequestBB.applicant.mobile}" />
<h:outputText value="Country:" />
<h:outputText value="#{applicationDetailsRequestBB.applicant.country}" />
<h:outputText value="Degree:" />
<h:outputText value="#{applicationDetailsRequestBB.applicant.degree}" />
<h:outputText value="School" />
<h:outputText value="#{applicationDetailsRequestBB.applicant.school}" />
</h:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</body>
</html>
我的支持豆是:
package pt.uc.dei.aor.finalproject.amj.platform.backingbeans;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.Serializable;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.component.html.HtmlForm;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import pt.uc.dei.aor.finalproject.amj.databasefinalproject.entities.Applicant;
import pt.uc.dei.aor.finalproject.amj.databasefinalproject.entities.Application;
import pt.uc.dei.aor.finalproject.amj.databasefinalproject.facades.ApplicantFacade;
import pt.uc.dei.aor.finalproject.amj.databasefinalproject.facades.ApplicationFacade;
import pt.uc.dei.aor.finalproject.amj.platform.application.StatefulApplication;
/**
*
* @author Alvaro
*/
@Named
@RequestScoped
public class ApplicationDetailsRequestBB implements Serializable {
private String cvPath;
private String coverLetterPath;
private String imgPath;
private Applicant applicant;
private Application application;
@EJB
private ApplicantFacade applicantFacade;
@EJB
private ApplicationFacade applicationFacade;
public ApplicationDetailsRequestBB() {
}
@PostConstruct
public void init() {
Map<String, String> mapList = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
if (mapList.containsKey("applicantid") && mapList.containsKey("applicationid")) {
Applicant a = applicantFacade.find(Long.parseLong(mapList.get("applicantid")));
Application app = applicationFacade.find(Long.parseLong(mapList.get("applicationid")));
if (a != null && app != null && app.getApplicant().equals(a)) {
applicant = a;
application = app;
this.cvPath = "/CV/" + application.getCv();
this.coverLetterPath = "/CL/" + application.getCoverLetter();
}
}
}
public String getCvPath() {
return cvPath;
}
public void setCvPath(String cvPath) {
this.cvPath = cvPath;
}
public String getCoverLetterPath() {
return coverLetterPath;
}
public void setCoverLetterPath(String coverLetterPath) {
this.coverLetterPath = coverLetterPath;
}
public String getImgPath() {
return imgPath;
}
public void setImgPath(String imgPath) {
this.imgPath = imgPath;
}
public Applicant getApplicant() {
return applicant;
}
public void setApplicant(Applicant applicant) {
this.applicant = applicant;
}
public ApplicantFacade getApplicantFacade() {
return applicantFacade;
}
public void setApplicantFacade(ApplicantFacade applicantFacade) {
this.applicantFacade = applicantFacade;
}
public Application getApplication() {
return application;
}
public void setApplication(Application application) {
this.application = application;
}
public ApplicationFacade getApplicationFacade() {
return applicationFacade;
}
public void setApplicationFacade(ApplicationFacade applicationFacade) {
this.applicationFacade = applicationFacade;
}
}
我在init方法中设置了一个突破点,进行调试,并且第一次没有被调用。当我刷新时,bean被调用并且evertything正常工作。为什么第一次没有结果?