有效,我得到這個錯誤很多時候..我用兩個H:selectOneMenu用於在我的JSF頁面,medialist中和Unitlist。同時選擇任何媒體。我的單元列表會自動填充,但有一段時間會給出驗證錯誤:值無效;驗證錯誤::值不是Selectone菜單
我的JSF代碼
<h:selectOneMenu id="media" value="#{workOrderMbean.selectedMedia}" converter="MediaConverter" onchange="submit()" valueChangeListener="#{workOrderMbean.onChangeMediaCombo}" immediate="true">
<f:selectItems value="#{workOrderMbean.mediaCombo}"/>
</h:selectOneMenu>
<h:selectOneMenu id="hUnit" value="#{workOrderMbean.selectedHeightUnit}" converter="UnitConverter" >
<f:selectItems value="#{workOrderMbean.unitCombo}"/>
</h:selectOneMenu>
Mediacombo的onchane事件
public void onChangeMediaCombo(ValueChangeEvent e) throws SearchBLException {
if (e.getNewValue() != null) {
Media media = (Media) e.getNewValue();
if (unitCombo != null && !unitCombo.isEmpty()) {
unitCombo.clear();
seclectedWidthUnit=new Unit();
selectedHeightUnit=new Unit();
}
unitCombo = ComboLoader.getUnitsComboByMediaid(media.getMediaId());
}
else
{
if (unitCombo != null && !unitCombo.isEmpty()) {
unitCombo.clear();
seclectedWidthUnit=null;
selectedHeightUnit=null;
}
unitCombo = ComboLoader.getUnitsComboByMediaid(-1);
}
}
我也使用 '單位'
我的媒體轉換器是
@FacesConverter轉換器( value =「MediaConverter」) public class MediaConverter實現轉換器{
MediaDAO mediadao=new MediaDAOImpl();
public Object getAsObject(FacesContext context, UIComponent component, String value) {
Media media=null;
try {
media=mediadao.getMedia(Integer.parseInt(value));
} catch (SearchBLException ex) {
Logger.getLogger(MediaConverter.class.getName()).log(Level.SEVERE, null, ex);
}
return media;
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
String str = "";
if (value instanceof Media) {
str = "" + ((Media) value).getMediaId();
}
return str;
}
}
「plz幫助我。」我想你可以ommit這裏。你不是印度街頭的乞丐,是嗎?;) – 2012-02-20 09:47:01