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

  • Home
  • SEARCH
  • 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 501473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:11:36+00:00 2026-05-13T06:11:36+00:00

I would like to know how to use Converters in Java Server Faces similar

  • 0

I would like to know how to use Converters in Java Server Faces similar to Spring collection property editor

Suppose the following model

public class Group {

    private String name;

    List<User> users = new ArrayList<User>();

    // getter's and setter's
}

And equivalent form

<form ...>
    <h1>Group form</h1>
    <label for="name">Enter name</label>
    <input type="text" name="name"/>

    <label for="users">Select users</label>
    <!--value attribute stores userId-->
    <input type="checkbox" value="1" name="users"/> User 1
    <input type="checkbox" value="2" name="users"/> User 2
    <input type="checkbox" value="3" name="users"/> User 3
</form>

If i use Spring to bind users property in Group class, i call

binder.registerCustomEditor(List.class, new CustomCollectionEditor() {
    protected Object convertElement(Object userId)  {
        return new User((Integer) userId);
    }
});

How do i get the same effect when using Java Server Faces ?

regards,

  • 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-13T06:11:36+00:00Added an answer on May 13, 2026 at 6:11 am

    For that you can implement javax.faces.convert.Converter. Its API is pretty self-explaining: write the getAsString() method accordingly that it returns the String representation of the Object, which can be under each the technical ID such as userId. Then, to get JSF set the right Object during apply request parameters phase, you need to implement getAsObject() that it returns the Object associated with the given String value.

    Basically:

    public class UserConverter implements Converter {
    
        private UserDAO userDAO = SomeDAOManager.getUserDAO();
    
        public String getAsString(FacesContext context, UIComponent component, Object value) {
            return String.valueOf(((User) value).getId());
        }
    
        public Object getAsObject(FacesContext context, UIComponent component, String value) {
            return userDAO.find(Long.valueOf(value));
        }
    
    }
    

    Register it in faces-config.xml as follows:

    <converter>
        <converter-for-class>com.example.model.User</converter-for-class>
        <converter-class>com.example.converter.UserConverter</converter-class>
    </converter>
    

    That should be it. For more insights you may this or this article useful.

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

Sidebar

Ask A Question

Stats

  • Questions 342k
  • Answers 342k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This seems to indicate it can occur if you don't… May 14, 2026 at 5:11 am
  • Editorial Team
    Editorial Team added an answer The DoubleAnimation is used to animate a dependency property of… May 14, 2026 at 5:11 am
  • Editorial Team
    Editorial Team added an answer If you're describing what I think you're describing, you're looking… May 14, 2026 at 5:11 am

Related Questions

I have a project in which we often use Integer.parseInt() to convert a String
I am trying to use the random forests package for classification in R. The
I need to create a text editing control in C# and I'm not sure
We have Product Backlog in an Excel Spreadsheet that we also commit to SVN,
I'm using sequential ids as primary keys and there are cases where I don't

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.