我正在尝试使用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 AdminCommunauteThematiques操作:
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
任何想法都非常欢迎。
您的帮助将不胜感激
最佳答案
您尝试在表单e reRender之后插入rich:panel:
<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>
关于java - selectOneMenu-a4j onchange不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5795486/