Validierungs-Fehler: Wert ist nicht gültig

Ich habe ein problem mit einem p:selectOneMenu, egal was ich mache ich Schaffe es nicht, JSF aufrufen der setter auf die JPA-Entität. JSF-Validierung schlägt fehl mit dieser Meldung:

form:Lage: Validierungs-Fehler: Wert ist nicht gültig

Habe ich diese arbeiten auf mehrere andere Klassen des gleichen Typs (ie, join-Tabelle Klassen), aber nicht für das Leben von mir bekommen diese arbeiten.

Wenn jemand werfen einige Fehlersuche/debugging-Tipps für diese Art von problem, es würde sehr geschätzt werden.

Mit log-Anweisungen, die ich überprüft haben, das folgende:

  1. Die Conveter ist wieder richtig, nicht null Werte.
  2. Ich habe keine Bean-Validation in meinem JPA-Entitäten.
  3. Setter setLocation(Location location) wird nie aufgerufen.

Dies ist das einfachste Beispiel, das ich tun kann, und es wird einfach nicht funktionieren:

<h:body>
    <h:form id="form">
        <p:messages id="messages" autoUpdate="true" />
        <p:selectOneMenu id="location" value="#{locationStockList.selected.location}" converter="locationConverter">
            <p:ajax event="change" update=":form:lblLocation"/>
            <f:selectItems value="#{locationStockList.locationSelection}"/>
        </p:selectOneMenu>
    </h:form>
</h:body>

Konverter:

@FacesConverter(forClass=Location.class, value="locationConverter")
public class LocationConverter implements Converter, Serializable {
    private static final Logger logger = Logger.getLogger(LocationConverter.class.getName());

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        if (value.isEmpty())
            return null;
        try {
            Long id = Long.parseLong(value);
            Location location = ((LocationManagedBean) context.getApplication().getELResolver().getValue(context.getELContext(), null, "location")).find(id);
            logger.log(Level.SEVERE, "Converted {0} to {1}" , new Object[] {value, location});
            return location;
        } catch (NumberFormatException e) {
            return new Location();
        }
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if (value == null || value.toString().isEmpty() || !(value instanceof Location))
            return "";
        return String.valueOf(((Location) value).getId());
    }    
}

Ausgabe der Konsole:

//Getter method
INFO: Current value=ejb.locations.Location[id=null, name=null, latitude=0.0, longitude=0.0] 
//Session Bean
INFO: Finding ejb.locations.Location with id=3 
//Session Bean
INFO: ### Returning : ejb.locations.Location[id=3, name=mdmd, latitude=4.5, longitude=2.3] 
//Converter
SEVERE: Converted 3 to ejb.locations.Location[id=3, name=mdmd, latitude=4.5, longitude=2.3] 
//Getter method -> Where did my selected Location go ??
INFO: Current value=ejb.locations.Location[id=null, name=null, latitude=0.0, longitude=0.0] 

InformationsquelleAutor klonq | 2012-01-30

Schreibe einen Kommentar