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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:40:58+00:00 2026-05-26T22:40:58+00:00

I am making an application where I am going to register questions. Each question

  • 0

I am making an application where I am going to register questions. Each question has a relationship with one or more categories so I need a way in the register question form to select which categories it belongs to.

I am thinking of using one of the selectMany… components from JSF for the task. I could retrieve the list of all categories in the database (only 9) and then bind that list to a f:selectItems component. Then the itemValue of each selectItem must be the id of the category. I will also need a second list containing all the selected id’s of the categories and at last do some sort of query against the database again with each id and add it to the list ….which again is set on the question.

I do not need a explanation on how to retrieve the list etc. but I could need some help if this approach is any good? Alternatives is well accepted:=)

  • 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-26T22:40:58+00:00Added an answer on May 26, 2026 at 10:40 pm

    Make List<Category> a property of the Question entity.

    @Entity
    public class Question {
    
        @OneToMany
        private List<Category> categories;
    
        // ...
    }
    

    with

    <h:selectManyMenu value="#{question.categories}" converter="#{categoryConverter}">
        <f:selectItems value="#{data.categories}" />
    </h:selectManyMenu>
    

    You only need to supply a converter for Category class.

    @ManagedBean
    @RequestScoped
    public class CategoryConverter implements Converter {
    
        @EJB
        private CategoryService categoryService;
    
        @Override
        public String getAsString(FacesContext context, UIComponent component, Object value) {
            if (!(value instanceof Category) || ((Category) value).getId() == null) {
                return null;
            }
    
            return String.valueOf(((Category) value).getId());
        }
    
        @Override
        public Object getAsObject(FacesContext context, UIComponent component, String value) {
            if (value == null || !value.matches("\\d+")) {
                return null;
            }
    
            return categoryService.find(Long.valueOf(value));
        }
    
    }
    

    (note: it’s until JSF 2.2 not possible to inject an @EJB in a @FacesConverter, that’s why it’s a @ManagedBean instead, see also Communication in JSF 2.0 – Converting and validating GET request parameters)

    You don’t need to duplicate the selected items in the managed bean or something else.

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

Sidebar

Related Questions

So, I'm going to be making an application, but for one of the features
I'm going through some old C#.NET code in an ASP.NET application making sure that
I'm going through some old C#.NET code in an ASP.NET application making sure that
I am making an application which has j2me in client side and dotnet on
I am making one application where i am reading mails from Lotus Notes. I
I'm making a thread for my application that's going to do an exit operation
I'm using C++ and GDI+ I'm going to be making a vector drawing application
I'm making a message board application. Users can make a post, each post requires
I'm making a java application that is going to be storing a bunch of
I am making a screen capturing application and everything is going fine. All I

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.