2016-06-22 1 views
0

J'essaie de créer un ModalPanel à partir d'un DataTable (RichFaces 4.5.1, MyFaces 2.2.6, Spring 3.1.1, Tomcat 7.0.27) mais je ne peux pas.ModalPanel utilisant RichFaces

Le modalPanel a des valeurs à afficher en fonction de la ligne sélectionnée dans le tableau. Lorsque je clique dans un commandLink, déclencher un actionListener doit nourrir ces valeurs (localidadeMB.carregarColecoes()), mais cela ne fonctionne pas, car la référence aux attributs de bean est null (n'a pas été définie par le f:setPropertyActionListener situé dans commandLink).

Qu'est-ce qui manquait?

* page.xhtml

(...) 
<f:view> 
<h:form id="formConsulta"> 
    <rich:dataTable id="tabela" 
     value="#{localidadeMB.getLocalidadesPorPalavra()}" var="loc" 
     rowKeyVar="row" rows="20" width="800px" render="scroller"> 
     <rich:column> 
      (...) 
     </rich:column> 
     <rich:column> 
      <f:facet name="header"> 
       <h:outputText value=""/> 
      </f:facet> 
      <a4j:commandLink id="editlink" ajaxSingle="true" 
       oncomplete="#rich:component('modalEditarLocalidade')}.show()" 
       actionListener="#{localidadeMB.carregarColecoes}" 
       render="modalEditarLocalidade"> 
      <h:graphicImage value="/img/edit.png"/> 
      <f:setPropertyActionListener value="#{loc}" target="#{localidadeMB.localidade}" /> 
      </a4j:commandLink> 
     </rich:column> 
    </rich:dataTable> 
</h:form> 

<ui:include src="modalPanel.xhtml" /> 

* modalPanel.xhtml

<ui:composition> 
<rich:popupPanel id="modalEditarLocalidade" autosized="true" 
    modal="false" resizable="false"> 
    <f:facet name="header"> 
     <h:outputText value="Alterar localidade" /> 
    </f:facet> 
    <f:facet name="controls"> 
     <h:graphicImage id="modalClosePNG2" value="/img/close1.png" 
      style="cursor:default;" 
      onclick="Richfaces.hideModalPanel('modalEditarLocalidade')" /> 
    </f:facet> 
    <h:form> 
     <h:outputLabel value="Nome da localidade:" for="nomeLocalidade" /> 
     <h:inputText id="nomeLocalidade" 
      value="#{localidadeMB.localidade.nome}" required="true" 
      immediate="true"/> 
     </h:inputText> 
    </h:form> 
</rich:popupPanel> 
</ui:composition> 

* ManagedBean

private Localidade localidade; 

public void setLocalidade(Localidade l){ 
    this.localidade = l; 
} 

public void carregarColecoes(ActionEvent action){ 
    System.out.println(localidade.getNome()); 

     ***** print NULL ***** 
} 

Répondre

0

Avec la suggestion de Makhiel et this link j'ai décidé.

Le xhtml ressemblait à ceci:

<a4j:commandLink id="editlink" ajaxSingle="true" 
     oncomplete="#{rich:component('modalEditarLocalidade')}.show()" 
     action="#{localidadeMB.carregarColecoes}" 
     render="modalEditarLocalidade"> 
     <h:graphicImage value="/img/edit.png"/> 
     <f:setPropertyActionListener value="#{loc}" 
      target="#{localidadeMB.localidade}" /> 
    </a4j:commandLink> 

et ManagedBean comme ceci:

public String carregarColecoes(){ 
     (....) 
    } 
1

Si vous souhaitez configurer une variable d'abord, puis exécuter une méthode devez utiliser @action pour cette méthode, les actionsListeners sont exécutées en premier, mais puisque vos deux méthodes sont des actionListeners localidadeMB.carregarColecoes est exécuté avant la définition de la variable. (Et btw h: commandLink n'a pas d'attributs "ajaxSingle" ou "oncomplete".)

+0

Merci pour vos commentaires, Makhiel. Désolé, l'ajaxSingle est parce que je testais a4j: commandLink, et que je copiais juste le mauvais code. J'ai mis à jour. –

+0

Vous pouvez mieux expliquer l'utilisation de @Action? Quelle méthode dois-je utiliser: setLocalidade() ou carregarColecoes()? Lors de la tentative d'insertion, Eclipse a tenté d'importer javax.xml.ws.Action. Ça n'est pas correct? Quelle est l'importation devrais-je faire? –

+0

"@action" signifie "action nommée par attribut", pas une annotation Java. ;) – Makhiel