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 8768987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:12:47+00:00 2026-06-13T17:12:47+00:00

I defined the following drop down box in my page: … <td> <h:selectOneMenu id=bootenvironment1

  • 0

I defined the following drop down box in my page:
…

<td>
  <h:selectOneMenu id="bootenvironment1" value="#{detailModel.selectedBootenvironment1}"
                   disabled="#{detailModel.mode == detailModel.viewMode}">
    <f:selectItems value="#{detailModel.availableBootenvironments}"/>
  </h:selectOneMenu>
</td>

In my model I have:

...
  private Map<String, Bootenvironment> availableBootenvironments;

  public DefinitionDetailModel()
  {
    super();
  }

  public String getSelectedBootenvironment1()
  {
    if (((Definition) getAfterObject()).getBootenvironment1() != null)
    {
      return ((Definition) getAfterObject()).getBootenvironment1().getEnvironmentName();
    }

    return "--Please select one--";
  }

  public void setSelectedBootenvironment1( String selectedBootenvironment )
  {
    ((Definition) getAfterObject()).setBootenvironment1(availableBootenvironments.get(selectedBootenvironment));
  }
  ...

And in the controller I set the availableBootenvironments map:

private void fetchBootenvironments()
  {
    ...
    @SuppressWarnings( "unchecked" )
    List<Bootenvironment> bootenvironments = (List<Bootenvironment>) ...

    Map<String, Bootenvironment> availableBootenvironments = new HashMap<String, Bootenvironment>();

    availableBootenvironments.put("--Please select one--", null);

    for(Bootenvironment bootenvironment : bootenvironments)
    {
      availableBootenvironments.put(bootenvironment.getEnvironmentName(), bootenvironment);
    }

    ((DefinitionDetailModel) detailModel).setAvailableBootenvironments(availableBootenvironments);
  }

The problem is that when I click a button in the page (which is bound to an action), I get the error:

detailForm:bootenvironment1: Validation error: value is not valid.

I don’t understand where the error is; the value for selectItems is a map with the object’s name-field(so a string) as key and the object itself as value. Then the value for the default selected (value="#{detailModel.selectedBootenvironment1}") is a string too as you can see in the getter/setter method of the model.

Another problem (maybe related to the previous one) is that when the page first loads, the default selected value should be –Please select one— as the getBootenvironment1() returns null, but this does not happen: another one from the list is selected.

Can you please help me understanding what/where am I doing wrong?

EDIT

I implemented the Converter as you said:

@FacesConverter( forClass = Bootenvironment.class )
public class BootenvironmentConverter implements Converter
{

  @Override
  public String getAsString( FacesContext context, UIComponent component, Object modelValue ) throws ConverterException
  {
    return String.valueOf(((Bootenvironment) modelValue).getDbId());
  }

  @Override
  public Object getAsObject( FacesContext context, UIComponent component, String submittedValue ) throws ConverterException
  {
    List<Bootenvironment> bootenvironments = ... (get from DB where dbid=submittedValue)

    return bootenvironments.get(0);
  }

}

But now I have the following error:

java.lang.ClassCastException: java.lang.String cannot be cast to
ch.ethz.id.wai.bootrobot.bo.Bootenvironment

  • 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-06-13T17:12:49+00:00Added an answer on June 13, 2026 at 5:12 pm

    You will get this error when the selected item value doesn’t pass the equals() test on any of the available item values.

    And indeed, you’ve there a list of Bootenvironment item values, but you’ve bound the property to a String which indicates that you’re relying on the Bootenvironment#toString() value being passed as submitted value and that you aren’t using a normal JSF Converter at all. A String can never return true on an equals() test with an Bootenvironment object.

    You’d need to provide a Converter which converts between Bootenvironment and its unique String representation. Usually, the technical ID (such as the autogenerated PK from the database) is been used as the unique String representation.

    @FacesConverter(forClass=Bootenvironment.class)
    public class BootenvironmentConverter implements Converter {
    
        @Override
        public void getAsString(FacesContext context, UIComponent component, Object modelValue) throws ConverterException {
            // Write code to convert Bootenvironment to its unique String representation. E.g.
            return String.valueOf(((Bootenvironment) modelValue).getId());
        }
    
        @Override 
        public void getAsObject(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException {
            // Write code to convert unique String representation of Bootenvironment to concrete Bootenvironment. E.g.
            return someBootenvironmentService.find(Long.valueOf(submittedValue));
        }
    
    }
    

    Finally, after implementing the converter accordingly, you should be able to fix the selectedBootenvironment1 property to be a normal property without any mess in getter/setter:

    private Bootenvironment selectedBootenvironment1;
    
    public Bootenvironment getSelectedBootenvironment1() {
        return selectedBootenvironment1;
    }
    
    public void setSelectedBootenvironment1(Bootenvironment selectedBootenvironment1) {
        this.selectedBootenvironment1 = selectedBootenvironment1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to change the following to a drop down box but am
I am trying to delete a drop down from a spreadsheet using the following
I have defined following control template for my custom control. <ControlTemplate TargetType={x:Type local:CustomControl}> <Grid
I have defined following in a ResourceDictionary: <DockPanel x:Key=errorDisplay LastChildFill=False> <Border Background=Red DockPanel.Dock=Top> <TextBlock
In my .htaccess file I have defined following rule, RewriteRule t/([^.]+)/$ /videos/tag.php?tag=$1 [QSA] The
ive defined the following and filled it with elements: vector <vector<double> > my_vector; but
I have defined the following class using COM to use the IGroupPolicyObject using C#.NET:
I have defined the following two functions test <- function(t) { return( (0.5*eta^2/theta)*(1-exp(-2*theta*t)) )
I have defined the following struct in C: typedef struct point{ float x; float
If I have defined the following types: type category = Noun | Verb |

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.