selectOneMenu - a4j onchange 不起作用
我正在尝试使用 a4j 更新使以下代码正常工作。
这是我的源代码:
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) {
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
非常欢迎任何想法。 我们将不胜感激您的帮助
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) {
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试在 form e 重新渲染后插入 rich:panel:
You try to insert a rich:panel after form e reRender it: