[JSF - RichFaces] SelectOneMenu & NoSuchElementException
Bonjour à tous,
Dans mon formulaire, j'ai un système de filtre de liste déroulante.
Je vous explique :
* J'ai une liste déroulante (businessPartnerType), lorsque je sélectionne un élément, une autre liste déroulante (businessPartner) est filtré en fonction du choix de la première liste.
Mon problème est que :
* Lorsque je valide mon formulaire, et que je n'ai pas touché aux 2 listes déroulante, celui-ci ne génère aucune exception.
* Par contre lorsque je sélectionne dans ces liste déroulante et que je valide mon formulaire, une exception du type NoSuchElementException est lancé.
Voici mon code :
* form.xhtml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
| <ui:composition template="#{themeBean.template}/main.xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<ui:define name="title">#{bundle.HOME_TITLE}</ui:define>
<ui:define name="head">
<style type="text/css">
.label {
display: block;
float: left;
width: 11em;
margin-right: 0.5em;
text-align: right;
}
.left_margin {
margin-left: 11.5em;
}
</style>
</ui:define>
<ui:define name="content">
<ui:decorate template="#{themeBean.template}/frame.xhtml">
<ui:define name="content">
<h:form>
<h:outputLabel for="date" value="#{bundle.DATE} :" styleClass="label" />
<h:inputText id="date" size="10" maxlength="10" value="#{expenseBean.date}" />
<br />
<a4j:region>
<h:outputLabel for="businessPartnerType" value="#{bundle.BUSINESS_PARTNER_TYPE} :" styleClass="label" />
<h:selectOneMenu id="businessPartnerType" value="#{expenseBean.businessPartnerType}" immediate="true" valueChangeListener="#{expenseBean.businessPartnerTypeChanged}">
<f:selectItem itemValue=" " />
<f:selectItems value="#{expenseBean.businessPartnerTypeList}" />
<a4j:support event="onchange" reRender="businessPartner" />
</h:selectOneMenu>
<a4j:status styleClass="loading_thumb">
<f:facet name="start">
<h:graphicImage value="#{themeBean.images}/loading_thumb.gif" />
</f:facet>
</a4j:status>
</a4j:region>
<br />
<h:outputLabel for="businessPartner" value="#{bundle.BUSINESS_PARTNER} :" styleClass="label" />
<h:selectOneMenu id="businessPartner" value="#{expenseBean.businessPartner}">
<f:selectItem itemValue="" />
<f:selectItems value="#{expenseBean.businessPartnerList}" />
</h:selectOneMenu>
<br />
<h:outputLabel for="expenseType" value="#{bundle.EXPENSE_TYPE} :" styleClass="label" />
<h:selectOneMenu id="expenseType">
<f:selectItem itemValue="" />
</h:selectOneMenu>
<a href="javascript:Richfaces.showModalPanel('mp')">add</a>
<br />
<h:outputLabel for="amount" value="#{bundle.AMOUNT} :" styleClass="label" />
<h:inputText id="amount" value="#{expenseBean.amount}" />
<br />
<h:outputLabel for="currency" value="#{bundle.CURRENCY} :" styleClass="label" />
<h:selectOneMenu id="currency" value="#{expenseBean.currency}">
<f:selectItem itemValue="" />
<f:selectItems value="#{expenseBean.currencyList}" />
</h:selectOneMenu>
<div class="left_margin">
<h:selectBooleanCheckbox id="chargeable" value="#{expenseBean.chargeable}" />
<h:outputLabel for="chargeable" value="#{bundle.CHARGEABLE}" />
</div>
<h:outputLabel for="comment" value="#{bundle.COMMENT} :" styleClass="label" />
<h:inputTextarea id="comment" value="#{expenseBean.comment}" />
<div class="left_margin">
<a4j:commandButton value="#{bundle.OK}" action="#{expenseBean.merge}" styleClass="button" />
</div>
</h:form>
</ui:define>
</ui:decorate>
<rich:modalPanel id="mp">
<ui:decorate template="#{themeBean.template}/frame.xhtml">
<ui:define name="content">
<a4j:form ajaxSubmit="true">
Type : <h:inputText id="type" required="true" />
<rich:message for="type" />
<br />
<a4j:commandButton value="Ok" action="#{expenseBean.addType}" oncomplete="Richfaces.hideModalPanel('mp')" />
</a4j:form>
</ui:define>
</ui:decorate>
</rich:modalPanel>
</ui:define>
</ui:composition> |
* ExpenseBean.java
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
| package bss.gesnet.beans;
import java.util.ArrayList;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
import bss.gesnet.core.BusinessPartnerType;
import bss.gesnet.core.Gesnet;
import bss.gesnet.core.IBusinessPartner;
import bss.gesnet.core.ICurrency;
import bss.gesnet.core.B1DataManager.B1DataManagerException;
public class ExpenseBean extends AbstractBean
{
private String date;
private String businessPartnerType;
private String businessPartner;
private String expenseType;
private String amount;
private String currency;
private boolean chargeable;
private String comment;
private static ArrayList<SelectItem> businessPartnerTypeList;
private static ArrayList<SelectItem> businessPartnerList;
private static ArrayList<SelectItem> currencyList;
public String getDate()
{
return date;
}
public void setDate(String date)
{
this.date = date;
}
public String getBusinessPartnerType()
{
return businessPartnerType;
}
public void setBusinessPartnerType(String businessPartnerType)
{
this.businessPartnerType = businessPartnerType;
}
public String getBusinessPartner()
{
return businessPartner;
}
public void setBusinessPartner(String businessPartner)
{
this.businessPartner = businessPartner;
}
public String getExpenseType()
{
return expenseType;
}
public void setExpenseType(String expenseType)
{
this.expenseType = expenseType;
}
public String getAmount()
{
return amount;
}
public void setAmount(String amount)
{
this.amount = amount;
}
public String getCurrency()
{
return currency;
}
public void setCurrency(String currency)
{
this.currency = currency;
}
public boolean isChargeable()
{
return chargeable;
}
public void setChargeable(boolean chargeable)
{
this.chargeable = chargeable;
}
public String getComment()
{
return comment;
}
public void setComment(String comment)
{
this.comment = comment;
}
public ArrayList<SelectItem> getBusinessPartnerTypeList()
{
if (businessPartnerTypeList == null)
{
businessPartnerTypeList = new ArrayList<SelectItem>();
for (BusinessPartnerType item : BusinessPartnerType.values())
businessPartnerTypeList.add(new SelectItem(item.getValue(),
getResourceBundle("bundle").getString(item.name())));
}
return businessPartnerTypeList;
}
public void businessPartnerTypeChanged(ValueChangeEvent event)
{
businessPartner = null;
businessPartnerList = null;
}
public ArrayList<SelectItem> getBusinessPartnerList()
throws B1DataManagerException
{
if (businessPartnerList == null)
{
businessPartnerList = new ArrayList<SelectItem>();
if (businessPartnerType != null
&& !businessPartnerType.trim().isEmpty())
{
for (IBusinessPartner item : Gesnet.b1DataManager
.getBusinessPartners(getDbName(), BusinessPartnerType
.get(businessPartnerType)))
businessPartnerList.add(new SelectItem(item.getCode(), item
.getName()));
}
}
return businessPartnerList;
}
public ArrayList<SelectItem> getCurrencyList()
throws B1DataManagerException
{
if (currencyList == null)
{
currencyList = new ArrayList<SelectItem>();
for (ICurrency item : Gesnet.b1DataManager
.getCurrencyList(getDbName()))
currencyList
.add(new SelectItem(item.getCode(), item.getName()));
}
return currencyList;
}
public String addType()
{
System.out.println("ExpenseBean::addType");
return null;
}
public String merge()
{
System.out.println("MERGE !");
return null;
}
} |
Merci pour vos réponses.