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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:08:28+00:00 2026-06-09T19:08:28+00:00

I want to use a SIMPLE drop down menu for a OneToOne/ManyToOne relation in

  • 0

I want to use a SIMPLE drop down menu for a OneToOne/ManyToOne relation in jsf

Person.java

package com.aminpy.create;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;

@Entity
public class Person {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    private String firstName;
    private String lastName;
    private Phone phone;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @OneToOne
    public Phone getPhone() {
        return phone;
    }

    public void setPhone(Phone phone) {
        this.phone = phone;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Override
    public String toString() {
        return firstName + " " + lastName;
    }
}

managed bean -> PersonPage.java

package com.aminpy.create;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

@ManagedBean
@SessionScoped
public class PersonPage {
    private Person person;
    private List<Phone> phoneList;
    private EntityManagerFactory emf;
    private EntityManager em;

    public Person getPerson() {
        if (person == null) {
            person = new Person();
        }
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public List<Phone> getPhoneList() {
        if (phoneList == null) {
            emf = Persistence.createEntityManagerFactory("manager1");
            em = emf.createEntityManager();
            Query query = em.createQuery("select p from Phone p");
            phoneList = query.getResultList();
            em.close();
        }
        return phoneList;
    }

    public void setPhoneList(List<Phone> phoneList) {
        this.phoneList = phoneList;
    }

    public String btnCreate() {
        emf = Persistence.createEntityManagerFactory("manager1");
        em = emf.createEntityManager();

        em.getTransaction().begin();
        em.persist(person);
        em.getTransaction().commit();
        System.out.println("Record Stored!");
        em.close();

        return null;
    }
}

this is my index.xhtml page

<h:form id="person_form">
    <h:inputText value="#{personPage.person.firstName}" />
    <h:inputText value="#{personPage.person.lastName}" />
    <h:selectOneMenu value="#{personPage.person.phone}">
        <f:selectItems value="#{personPage.phoneList}" var="ph"
            itemLabel="#{ph.number}" itemValue="#{ph.id}" />
    </h:selectOneMenu>
    <h:commandButton value="save" action="#{personPage.btnCreate}" />
</h:form>

my relation worked without any problem in main() function
but I have problem when I submit my form with this error

sourceId=person_form:j_idt8[severity=(ERROR 2), summary=(Conversion Error setting value 'class com.aminpy.create.Phone' for 'null Converter'.), detail=(Conversion Error setting value 'class com.aminpy.create.Phone' for 'null Converter'.)]
  • 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-09T19:08:29+00:00Added an answer on June 9, 2026 at 7:08 pm

    You need to create a custom JSF Converter which can convert between String and Phone.

    @FacesConverter(forClass=Phone.class)
    public class PhoneConverter implements Converter {
    
        @Override
        public Object getAsObject(FacesContext ctx, UIComponent component, java.lang.String value) {
            // Write code here which converts from String to Phone.
        }
    
        @Override
        public String getAsString(FacesContext ctx, UIComponent component, Object value) {
            // Write code here which converts from Phone to String.
        }
    
    }
    

    Further you should replace the itemValue to be #{ph} instead of #{ph.id}.

    See also:

    • Conversion Error setting value for 'null Converter'
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple html option/select (dropdown) menu. I want to use JQuery to
I want to use the Simple Query tool in SubSonic 3(.0.0.2) and the docs
I'm new with ASP.NET, and I want to use a simple technique that I
I want to use ARC in my simple class where I store some values
I want to use List.Find() on a simple collection that does not implement Find().
I want to use the Django admin interface for a very simple web application
i want to use facebook's fb:dialog tag to display a simple pop-up form for
i want to know which parsing method is best to use among Simple XML
I'm writing simple filter in Android and want to use ExpandableListAdapter with check boxes.
I'm writing a simple C# program and want to use an SQL server to

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.