Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1096493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:17:32+00:00 2026-05-17T00:17:32+00:00

Using NetBeans, I have generated Hibernate mapping files and set of POJOs. I have

  • 0

Using NetBeans, I have generated Hibernate mapping files and set of POJOs. I have also generated a set of JSF pages from entity classes (those generated POJOs).

Now, I am trying to add a dropdown menu that would enable me to select one of the enitites.

<h:selectOneMenu value="#{measurementController.sensor}">
    <f:selectItems value="#{sensorController.itemsAvailableSelectOne}" />
</h:selectOneMenu>

getItemsAvailableSelectOne() calls this method:

public static SelectItem[] getSelectItems(List<?> entities, boolean selectOne) {
    int size = selectOne ? entities.size() + 1 : entities.size();
    SelectItem[] items = new SelectItem[size];
    int i = 0;
    if (selectOne) {
        items[0] = new SelectItem("", "---");
        i++;
    }
    for (Object x : entities) {
        items[i++] = new SelectItem(x, x.toString());
    }
    return items;
}

In measurementController class I have this:

private Sensor sensor;

public Sensor getSensor() {
    return this.sensor;
}

public void setSensor(Sensor sensor) {
    this.sensor = sensor;
}

Whatever I do, I get Validation Error: Value is not valid error when I select any entry in the dropdown menu. Why?

I have a feeling that I am missing something very obvious, but I just can’t see it.

EDIT:

Digging trough generated code, I’ve found an existing converter class:

@FacesConverter(forClass=Sensor.class)
public static class SensorControllerConverter implements Converter {

    public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
        if (value == null || value.length() == 0) {
            return null;
        }
        SensorController controller = (SensorController)facesContext.getApplication().getELResolver().
                getValue(facesContext.getELContext(), null, "sensorController");
        return controller.ejbFacade.find(getKey(value));
    }

    java.lang.Integer getKey(String value) {
        java.lang.Integer key;
        key = Integer.valueOf(value);
        return key;
    }

    String getStringKey(java.lang.Integer value) {
        StringBuffer sb = new StringBuffer();
        sb.append(value);
        return sb.toString();
    }

    public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
        if (object == null) {
            return null;
        }
        if (object instanceof Sensor) {
            Sensor o = (Sensor) object;
            return getStringKey(o.getIdSensor());
        } else {
            throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: "+SensorController.class.getName());
        }
    }

}

When I step trough the code with the debugger it all seems to work fine. First the getAsObject method is called with the selected item as argument, and the return value is the Sensor object.

Then the getSensor() method is called that returns null (the current value stored in the measurementController class).

And last, the getAsString() method gets called for every item in the dropdown menu. I think this one is a part of Render response phase and has nothing to do with validation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:17:33+00:00Added an answer on May 17, 2026 at 12:17 am

    Validation Error: Value is not valid

    In case of a <h:selectOneMenu>, you can get this validation error whenever the selected item doesn’t match any of the items available in the list as per the Object#equals() contract. Basically, it boils down that sensor.equals(selectItem.getValue()) has never returned true for any of the SelectItem items available in the list. This can happen if the equals() method of the Sensor class is not or poorly implemented.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an issue using JaxB in Netbeans 7.1.2. I have auto-generated my classes
I have generated the client Binding using NetBeans NetBeans -> New -> Java Project
I have recently started using Netbeans with following stack Liferay, icefaces with jBoss. Is
I have developed a web application using Netbeans 6.7 and Ant. The webapp works,
I have created a java application on netbeans 7 .Now By using netbeans ihave
I have a jax-ws web service developped using netbeans 7 and glassfish 3.1.2 .
I am using NetBeans 7.1, which comes with Groovy 1.6 support. I have to
greetings, today i have started to learn java using netbeans ide. i would like
I am using the netbeans and mysql. I have a table named employee with
I am using a the NetBeans 7.x IDE. I have a Netbeans Application module.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.