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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:04:05+00:00 2026-05-26T19:04:05+00:00

For my project i want to implement a combobox with h:selectOneMenu . I read

  • 0

For my project i want to implement a combobox with h:selectOneMenu. I read many posts about how to handle the selectOneMenu properly and how to implement a custom converter. The combobox shall store the ID (Long) from a different DB Table (named fk_ID) for which a constrain is in place. So far everything seems to function as planned. Now to my problem:

The column fk_ID is optional, so the first option in the combobox is a f:selectItem with no value labeled “choose …”. When I save the form and change the value everything is OK, except if I set it back to “choose …”. The error I get is a constraint integrity violation.

I found the problem too: The converter returns null as intended but the bean receives the Long 0.

The XHTML:

<h:selectOneMenu value="#{userBean.selectedModel.fk_id}"
    id="combobox">
    <f:selectItem itemLabel="choose ..." />
    <f:selectItems
        value="#{userBean.items}"
        var="item"
        itemLabel="#{item.value}"
        itemValue="#{item.id}"
    />
    <f:converter converterId="userConverter" />
</h:selectOneMenu>

The custom converter:

@FacesConverter(value = "userConverter")
public class UserConverter implements Converter {
    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
        if (arg2 != null && !arg2.equals("null"))
            return Long.valueOf(arg2);

        return null;
    }
    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        return String.valueOf(arg2);
    }
}

The bean (very short version):

@Named(value = "userBean")
public class UserController implements Serializable {

    @Getter
    @Setter
    private UserModel selectedModel;

    @Getter
    @Setter
    private List<UserModel> items;

    public void saveModel() {
        selectedModel = userService.saveModel(selectedModel);
    }
}

The problem is that the fk_id is Long 0, but should be null. I can solve the problem by writing

if (selectedModel.getFk_id() == 0)
    selectedModel.setFk_id(null);

, but thats not a solution I am comfortable with.

My Question: Why is the value null, which the converter returns, the Long 0 inside the saveModel() method?

  • 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-26T19:04:06+00:00Added an answer on May 26, 2026 at 7:04 pm

    This converter is unnecessary and makes no sense (I’d expect an UserConverter to convert between User and String, not between Long and String). Remove it.

    Now, you need to tell JSF to interpret empty string submitted values as null. Add the following to your web.xml:

    <context-param>
        <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
        <param-value>true</param-value>
    </context-param>
    

    This should solve the problem on most containers. But if you’re using Tomcat or a fork/clone of it (JBoss AS, WebSphere AS, etc) and/or the container uses the Apache EL parser implementation, then you also need to add the following argument to its VM startup arguments:

    -Dorg.apache.el.parser.COERCE_TO_ZERO=false
    

    This will prevent the Apache EL parser from coercing the submitted value to the primitive’s default, even though you’re using a primitive wrapper type as property.

    See also:

    • Communication in JSF 2.0

    Unrelated to the concrete problem, you don’t have a combobox there. That’s just a simple dropdownlist. A combobox is an editable dropdownlist. Get your terms right 😉

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

Sidebar

Related Questions

I want to implement a html audio player in my project having playlist with
I am working on a web project. I want to implement same in ruby.
I started my project in Asp.net MVC(c#) & SQL Server 2005.I want to implement
Trying to implement 3-layer (not: tier, I just want to separate my project logically,
In my project i want to first view country in combobox then selecting country
I want to implement a schedule function in my project. So I Googled for
I want to implement an AsyncTaskLoader in my project using the Compatibility Package, so
I want to implement basic spell checking in a Notepad clone project I'm doing.
I want to implement Ajax on my JSF web project. I googled and found
I want to implement CI for my project, but I've never done this before.

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.