I'm trying to make the following code working using a4j update.
Here my souce code:
File 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) {
开发者_C百科 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;
}
}
When trying to debug my code, I see that communauteSelected is never initialized. Any idea?
Here are the values in drop down combo:
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
Any idea is very welcome. Your help will be appreciated
You try to insert a rich:panel after form e reRender it:
<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>
精彩评论