selectOneMenu - a4j onchange не работают - PullRequest
1 голос
/ 26 апреля 2011

Я пытаюсь заставить работать следующий код с помощью обновления a4j.

Вот мой код:

Файл communauteThematiques.xhtml :

<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a4j="http://richfaces.org/a4j"
    template="../layout/template.xhtml">

    <ui:define name="containerCentral" >
        <script language="javascript">
            bUpdate = false;
            function checkForm() {
                alert("ici verif si modifs a commiter");
                return true;
            }
        </script>

        <div class="entry errors" style="text-align: center;" >
            <h:messages globalOnly="true" />
        </div>

        <s:div style="padding-top: 20px;" >
            <h:form id="frmList" >
                <h1>Gestion des thématiques des communautés</h1>
                <br/>
                <h:outputText value="Sélectionner une communauté : "/>
                <h:selectOneMenu id="listeCommunaute" value="#{adminThesaurusThematiques.communauteSelected}" required="true" disabled="#{adminThesaurusThematiques.communauteSelected != null}" >
                    <s:selectItems value="#{adminThesaurusThematiques.listeCommunaute}" 
                                   var="communaute" 
                                   label="#{communaute.nom}" 
                                   noSelectionLabel="Veuillez sélectionner une communauté ... " />
                    <a4j:support event="onchange" reRender="arbre" status="majTypeWaiting" ajaxSingle="true" />
                </h:selectOneMenu>

                <!--h:selectOneMenu id="typeCommunaute" value="#{adminCommunaute.communauteSelected.type}" required="true" disabled="#{adminCommunaute.communauteSelected.type != null}" >
                    <s:selectItems noSelectionLabel="#{messages['application.label.choixSelect']}" />
                    <f:selectItem itemValue="geo" itemLabel="Géographique" />
                    <f:selectItem itemValue="metier" itemLabel="Métier" />
                    <a:support event="onchange" reRender="typeCommunaute,zoneChoixMembres" status="majTypeWaiting" ajaxSingle="true" />
                </h:selectOneMenu-->


                <a4j:status id="majTypeWaiting" forceId="true">
                    <f:facet name="start">
                        <img src="/communaute/images/admin/ajax-loader.gif" style="padding-left: 5px;" />
                    </f:facet>
                </a4j:status>

                <br/>
                <rich:tree id="arbre" value="#{adminThesaurusThematiques.arbre}" var="node" switchType="client" toggleOnClick="true" >
                    <rich:treeNode>
                        <h:outputText value="#{node}" />
                    </rich:treeNode>
                </rich:tree>

                <h:commandButton id="saveNewOrder" value="Enregistrer les modifications" action="#{adminThesaurusThematiques.saveNewOrder}" style="display: none;" />
            </h:form>
        </s:div>



    </ui:define>
</ui:composition>

File AdminCommunauteThematiquesAction :

public class AdminCommunauteThematiquesAction {

    @Logger
    private Log log;

    @In(create = true)
    private GeneralMgr generalMgr;
    @In(create = true)
    private CommunauteMgr communauteMgr;
    @In(create = true)
    private MetadataMgr metadataMgr;
    @In
    private FacesMessages facesMessages;
    private Communaute communauteSelected;
    private List<Communaute> listeCommunaute;
    private TreeNodeImpl<String> arbre;

    @Create
    public void init() {
        //if (listeCommunaute == null) {
            log.debug("Listing des communautés");
            listeCommunaute = communauteMgr.getListeCommunautesByName();
        //}
    }

    public List<Communaute> getListeCommunaute() {
        return listeCommunaute;
    }

    public void setListeCommunaute(List<Communaute> listeCommunaute) {
        this.listeCommunaute=listeCommunaute;
    }

    public Communaute getCommunauteSelected() {
        return communauteSelected;
    }

    public void setCommunauteSelected(Communaute communaute) {
        this.communauteSelected=communaute;
    }

    private void buildTree() {
        try {
            arbre = new TreeNodeImpl<String>();
            Metadata thesaurus = metadataMgr.getApplicationMetadata();
            if (thesaurus.getThesaurus() != null) {
                for (MetadataValue metVal : thesaurus.getThesaurus()) {
                    arbre = ajoutNodeRecursif(arbre, metVal);
                }
            }
        } catch (Exception e) {
            log.error("Erreur pendant la génération de l'arbre de thématiques", e);
            facesMessages.add("Une erreur est survenue pendant la génération de l'arbre de thématiques");
        }
    }

    private TreeNodeImpl<String> ajoutNodeRecursif(TreeNodeImpl<String> node, MetadataValue val) {
        if (val != null) {
            TreeNodeImpl<String> child = new TreeNodeImpl<String>();
            child.setData(val.getLibelle());

            if (val.getSousElements() != null) {
                for (MetadataValue metVal : val.getSousElements()) {
                    child = ajoutNodeRecursif(child, metVal);
                }
            }

            node.addChild(val.getId(), child);
        }

        return node;
    }

    /* Getters & Setters */

    public TreeNodeImpl<String> getArbre() {
        if(communauteSelected!=null) {
            communauteSelected.getId();
            buildTree();
        }
        return arbre;
    }

    public void setArbre(TreeNodeImpl<String> arbre) {
        this.arbre = arbre;
    }
}

При попытке отладить мой код я вижу, что communauteSelected никогда не инициализируется. Есть идеи?

Вот значения в выпадающем списке:

org.cyo.diapason.model.Communaute@411 - Aspects postes de travail
org.cyo.diapason.model.Communaute@41e - BLOC 3
org.cyo.diapason.model.Communaute@419 - CCF

Любая идея очень приветствуется. Ваша помощь будет оценена

1 Ответ

0 голосов
/ 05 ноября 2011

Вы пытаетесь вставить панель rich: после формы и повторно ее отобразить:

<h:form id="frmList" >
<rich:panel id="panel">

...

<h:selectOneMenu id="listeCommunaute" value="#{adminThesaurusThematiques.communauteSelected}" required="true" disabled="#{adminThesaurusThematiques.communauteSelected != null}" >
                    <s:selectItems value="#{adminThesaurusThematiques.listeCommunaute}" 
                                   var="communaute" 
                                   label="#{communaute.nom}" 
                                   noSelectionLabel="Veuillez sélectionner une communauté ... " />
                    <a4j:support event="onchange" reRender="panel" status="majTypeWaiting" ajaxSingle="true" />
                </h:selectOneMenu>
...

</rich:panel>

...