Dans la page suivante, je ne suis pas en mesure de charger automobileLists
puisque la méthode pour le remplir est en dehors du composant dans un f:metadata
. J'ai une erreur nullPointerException. partiel Code:Impossible d'utiliser f: metadata f: viewAction de l'intérieur des composants
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>title</title>
</h:head>
<f:metadata>
<f:viewAction action="#{primeAutomobileController.populateAutomobileFieldList}"/>
</f:metadata>
<ui:composition template="layout/template.xhtml">
<ui:define name="content">.....................
La seule façon pour moi de le charger est de la portée de la primeAutomobileController
à la session au lieu de la demande initiale, et appelez la méthode à partir d'une page précédente par un bouton, je voudrais à charger au début de la page au lieu de l'appeler précédemment. La méthode en question:
public void populateAutomobileFieldList(){
List<String> automobileFieldSource = new ArrayList<>();
List<String> automobileFieldTarget = new ArrayList<>();
automobileFieldSource.add("Make");
automobileFieldSource.add("Model");
automobileFieldSource.add("Year");
automobileFieldSource.add("Description");
setAutomobileList(new DualListModel<>
(automobileFieldSource, automobileFieldTarget));
}
partielle index.xhtml la page où f:metadata
obtient chargé
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>title</title>
</h:head>
<f:metadata>
<f:viewAction action="#{primeAutomobileController.loadAutomobiles}"/>
<f:viewAction action="#{primeAutomobileController.populateAutomobileFieldList}"/>
</f:metadata>
<ui:composition template="layout/template.xhtml">
<ui:define name="content"> ......................
Ici se correctement chargé les deux méthodes dans f:metadata
, comme il est montré dans un exemple dans un tutoriel vidéo i suis le suivant, mais quand c'est le même code exact dans un xhtml différent ça ne marche pas.
Je J'ai essayé de suivre l'exemple mais il ne me charge toujours pas, j'ai ajouté dans la publication ma page 'index.xhtml', où le même code est chargé. – MrSir
@mrsir: avez-vous lu la réponse et comparez la réponse avec votre code? – Kukeltje