我正在努力学习JSF,当然自学,我有几本书,我一直在努力学习。不知道怎么做... :-)
我的问题是当我尝试通过我的网络应用创建(添加)记录时。我收到错误“Target Unreachable,'null'返回null”。
堆栈跟踪(我在这里找不到任何有用的东西)
mai 18, 2014 3:50:21 PM org.apache.catalina.core.StandardWrapperValve invoke
Grave: Servlet.service() for servlet [Faces Servlet] in context with path [/HCP] threw exception [/jsf/phase/createPhase.xhtml @19,133 value="#{PhaseComponent.phase.description}": Target Unreachable, 'null' returned null] with root cause
javax.el.PropertyNotFoundException: /jsf/phase/createPhase.xhtml @19,133 value="#{PhaseComponent.phase.description}": Target Unreachable, 'null' returned null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:97)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:91)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1023)
at javax.faces.component.UIInput.validate(UIInput.java:953)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
at javax.faces.component.UIInput.processValidators(UIInput.java:693)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
at org.primefaces.component.panel.Panel.processValidators(Panel.java:281)
at javax.faces.component.UIForm.processValidators(UIForm.java:240)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
at org.primefaces.component.layout.Layout.processValidators(Layout.java:233)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
这是我使用该类的xhtml:
<p:panel header="#{phasemsgs['phase.title']} Details" style="margin-top:10px">
<p:messages />
<h:panelGrid id="detail" columns="2" styleClass="grid" columnClasses="label,value">
<h:outputText value="#{phasemsgs['phase.datedebut.title']}:" />
<p:calendar value="#{PhaseComponent.phase.datedebut}" id="datedebut" converter="dateConverterForCalendar"/>
<h:outputText value="#{phasemsgs['projet.datefineffective.title']}:" />
<p:calendar value="#{PhaseComponent.phase.datefin}" id="datefin" converter="dateConverterForCalendar"/>
<h:outputText value="#{phasemsgs['phase.description.title']}:" />
<h:inputText id="phase_description" value="#{PhaseComponent.phase.description}" required="false" label="phase_description" />
<h:outputLabel value="Projet: *" />
<h:selectOneMenu id="selectProjet" value="#{PhaseComponent.projet}" required="true" converter="#{entityConverter}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{PhaseComponent.findNomProjets()}" />
</h:selectOneMenu>
<h:panelGroup>
<p:commandButton image="save" ajax="false" style="margin-right:20px;" value="#{phasemsgs['navigation.save']}" action="#{PhaseComponent.savePhase(PhaseComponent.phase)}"/>
</h:panelGroup>
</h:panelGrid>
这是phaseComponent类:
@Scope("session")
@Component("PhaseComponent")
public class PhaseComponentImpl implements PhaseComponent ,Converter {
private Phase phase;
private Projet projet;
private Tache taches;
private Livrable livrables;
@Autowired
private LivrableDAO livrableDAO;
@Autowired
private PhaseDAO phaseDAO;
@Autowired
private ProjetDAO projetDAO;
@Autowired
private TacheDAO tacheDAO;
@Autowired
private PhaseService phaseService;
private Set<SelectItem> selected;
/**
*/
/**
*/
public Set<SelectItem> getSelectOneItemsProj(){
this.selected= new LinkedHashSet<SelectItem>();
Set<Projet> projets=projetDAO.findAllProjets();
for(Projet proj:projets)
{
SelectItem selectItem=new SelectItem(proj.getIdprojet(),proj.getNomprojet());
this.selected.add(selectItem); }
return selected;
}
public PhaseComponentImpl() {
}
@Transactional
public String selectPhaseTaches(Integer phase_idphase, Integer related_taches_idtache) {
taches = tacheDAO.findTacheByPrimaryKey(related_taches_idtache, -1, -1);
return "/jsf/phase/taches/viewTaches.xhtml";
}
@Transactional
public String editPhaseLivrables(Integer phase_idphase, Integer related_livrables_idlivrable) {
livrables = livrableDAO.findLivrableByPrimaryKey(related_livrables_idlivrable, -1, -1);
return "/jsf/phase/livrables/editLivrables.xhtml";
}
@Transactional
public String newPhaseTaches(Integer phase_idphase) {
taches = new Tache();
return "/jsf/phase/taches/createTaches.xhtml";
}
@Transactional
public Tache getTaches() {
return taches;
}
@Transactional
public String savePhaseProjet(Integer phase_idphase, Projet projet) {
phase = phaseService.savePhaseProjet(phase_idphase, projet);
return "/jsf/phase/viewPhase.xhtml";
}
@Transactional
public Projet getPhaseProjet(Integer idphaseKey) {
return phaseDAO.findPhaseByPrimaryKey(idphaseKey).getProjet();
}
@Transactional
public Projet getProjet() {
return projet;
}
@Transactional
public String confirmDeletePhaseProjet(Integer phase_idphase, Integer related_projet_idprojet) {
projet = projetDAO.findProjetByPrimaryKey(related_projet_idprojet);
return "/jsf/phase/projet/deleteProjet.xhtml";
}
@Transactional
public String newPhaseLivrables(Integer phase_idphase) {
livrables = new Livrable();
return "/jsf/phase/livrables/createLivrables.xhtml";
}
@Transactional
public String confirmDeletePhaseTaches(Integer phase_idphase, Integer related_taches_idtache) {
taches = tacheDAO.findTacheByPrimaryKey(related_taches_idtache);
return "/jsf/phase/taches/deleteTaches.xhtml";
}
@Transactional
public List<Livrable> listPhaseLivrables(Integer idphaseKey) {
return new java.util.ArrayList<Livrable>(phaseDAO.findPhaseByPrimaryKey(idphaseKey).getLivrables());
}
@Transactional
public String deletePhaseProjet(Integer phase_idphase, Integer related_projet_idprojet) {
phase = phaseService.deletePhaseProjet(phase_idphase, related_projet_idprojet);
return "/jsf/phase/viewPhase.xhtml";
}
@Transactional
public String confirmDeletePhaseLivrables(Integer phase_idphase, Integer related_livrables_idlivrable) {
livrables = livrableDAO.findLivrableByPrimaryKey(related_livrables_idlivrable);
return "/jsf/phase/livrables/deleteLivrables.xhtml";
}
@Transactional
public List<Phase> listPhases() {
return new java.util.ArrayList<Phase>(phaseService.loadPhases());
}
@Transactional
public String savePhaseTaches(Integer phase_idphase, Tache tache) {
phase = phaseService.savePhaseTaches(phase_idphase, tache);
return "/jsf/phase/viewPhase.xhtml";
}
@Transactional
public Livrable getLivrables() {
return livrables;
}
@Transactional
public String savePhaseLivrables(Integer phase_idphase, Livrable livrable) {
phase = phaseService.savePhaseLivrables(phase_idphase, livrable);
return "/jsf/phase/viewPhase.xhtml";
}
@Transactional
public String editPhase(Integer idphaseKey) {
phase = phaseDAO.findPhaseByPrimaryKey(idphaseKey);
return "/jsf/phase/editPhase.xhtml";
}
@Transactional
public String editPhaseProjet(Integer phase_idphase, Integer related_projet_idprojet) {
projet = projetDAO.findProjetByPrimaryKey(related_projet_idprojet, -1, -1);
return "/jsf/phase/projet/editProjet.xhtml";
}
@Transactional
public String selectPhaseLivrables(Integer phase_idphase, Integer related_livrables_idlivrable) {
livrables = livrableDAO.findLivrableByPrimaryKey(related_livrables_idlivrable, -1, -1);
return "/jsf/phase/livrables/viewLivrables.xhtml";
}
@Transactional
public String savePhase(Phase phase) {
phaseService.savePhase(phase);
return "/jsf/phase/listPhases.xhtml";
}
@Transactional
public String confirmDeletePhase(Integer idphaseKey) {
phase = phaseDAO.findPhaseByPrimaryKey(idphaseKey);
return "/jsf/phase/deletePhase.xhtml";
}
@Transactional
public String editPhaseTaches(Integer phase_idphase, Integer related_taches_idtache) {
taches = tacheDAO.findTacheByPrimaryKey(related_taches_idtache, -1, -1);
return "/jsf/phase/taches/editTaches.xhtml";
}
@Transactional
public String selectPhase(Integer idphaseKey) {
phase = phaseDAO.findPhaseByPrimaryKey(idphaseKey);
return "/jsf/phase/viewPhase.xhtml";
}
@Transactional
public String selectPhaseProjet(Integer phase_idphase, Integer related_projet_idprojet) {
projet = projetDAO.findProjetByPrimaryKey(related_projet_idprojet, -1, -1);
return "/jsf/phase/projet/viewProjet.xhtml";
}
@Transactional
public Phase getPhase() {
return phase;
}
@Transactional
public String newPhaseProjet(Integer phase_idphase) {
projet = new Projet();
return "/jsf/phase/projet/createProjet.xhtml";
}
@Transactional
public String deletePhaseLivrables(Integer phase_idphase, Integer related_livrables_idlivrable) {
phase = phaseService.deletePhaseLivrables(phase_idphase, related_livrables_idlivrable);
return "/jsf/phase/viewPhase.xhtml";
}
@Transactional
public List<Tache> listPhaseTaches(Integer idphaseKey) {
return new java.util.ArrayList<Tache>(phaseDAO.findPhaseByPrimaryKey(idphaseKey).getTaches());
}
@Transactional
public String deletePhase(Integer idphaseKey) {
Phase phase = phaseDAO.findPhaseByPrimaryKey(idphaseKey);
phaseService.deletePhase(phase);
return "/jsf/phase/listPhases.xhtml";
}
@Transactional
public String newPhase() {
phase = new Phase();
return "/jsf/phase/createPhase.xhtml";
}
@Transactional
public String deletePhaseTaches(Integer phase_idphase, Integer related_taches_idtache) {
phase = phaseService.deletePhaseTaches(phase_idphase, related_taches_idtache);
return "/jsf/phase/viewPhase.xhtml";
}
@Transactional
public void affectPhaseProjet(Integer phase_idphase_3,
Integer phase_idprojet) {
projet = projetDAO.findProjetByPrimaryKey(phase_idprojet, -1, -1);
phase.setProjet(projet);
}
@Transactional
public Projet findNomProjet()
{
return (Projet) projetDAO.findNomProjets();
}
public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
projet=(Projet) projetDAO.findProjetByNomprojet(arg2);
return projet ;
}
public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
// TODO Auto-generated method stub
return null;
}
public List<Projet> findNomProjets() {
// TODO Auto-generated method stub
return projetDAO.findNomProjets();
}
}
答案 0 :(得分:0)
从堆栈跟踪中,这是主要问题(强调我的):
Grave:servlet [Faces Servlet]的Servlet.service()在路径[/ HCP]的上下文中引发了异常[/jsf/phase/createPhase.xhtml @ 19,133 value =“#{PhaseComponent.phase.description } :目标无法访问,'null'返回null ]具有根本原因 javax.el.PropertyNotFoundException:/jsf/phase/createPhase.xhtml @ 19,133 value =“#{PhaseComponent.phase.description}”:目标无法访问,'null'返回null
PhaseComponentImpl#phase
为null
,因此对任何phase
字段的访问都将失败。要解决此问题,您必须初始化数据。您可以使用@PostConstruct
带注释的方法执行此操作:
@Scope("session")
@Component("PhaseComponent")
public class PhaseComponentImpl implements PhaseComponent ,Converter {
//your fields...
//your current methods...
@PostConstruct
public void init() {
//initialize the data here
this.phase = new Phase();
//similar for other fields
}
}