0

I'm Migrating My project from seam 2 to JSF 2.x .

In seam 2 for enum's we have

<s:convertEnum /> 

which will call the converter when correct value is selected not the noSelectionOption value.

In JSF 2.x I have created My custom Converter like

@Named("enumConverter")
@ApplicationScoped
public class EnumConverter implements Converter {

public Object getAsObject(FacesContext context, UIComponent component, String key) 
        throws ConverterException {
if(!key.equalsIgnoreCase("-- Choose one --")){
    // DO LOGIC
}
return null;
}

public String getAsString(FacesContext context, UIComponent component, Object object) {
}

Now the problem is in my view I'm using the converter like

<h:selectOneMenu value="#{user.DocumentType}" required="true">
       <f:selectItem itemLabel="-- Choose one --" itemValue="#{null}" noSelectionOption="true"/>
        <f:selectItems value="${user.Constants(user.statuses)}"
            var="Val" itemLabel="#{user.Display(Val)}" 
        />
        <f:converter converterId="enumConverter"></f:converter> 
    </h:selectOneMenu>

Here if i select the NoSelectionOption then also my converter is getting called ,,, which should not happen and it should be called only if correct value is needed

in case of seam 2 converter only if correct value is selected then only converter will be called otherwise "value is required" is displayed.

Kindly please tell me ,what I'm missing here .... Appreciate and help ...

Thanks in advance

4

1 回答 1

0

上述问题是由于 a4j:commandlink 具有 reRender 属性,我将其替换为 render 属性,现在正在显示消息。

但现在的问题是

*如果required=true不存在并且我选择noSelectionOption那么它将在数据库中存储空白值。是否有必要jsf 2中为noSelectionOption提供验证器????

谢谢

于 2013-06-04T06:10:22.473 回答