gpt4 book ai didi

java - selectOneMenu - a4j onchange 不起作用

转载 作者:行者123 更新时间:2023-12-01 05:46:30 24 4
gpt4 key购买 nike

我正在尝试使用 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>

文件管理CommunauteThematiquesAction:

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 重新渲染后插入一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com