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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:06:08+00:00 2026-05-31T03:06:08+00:00

We have: public class TicketDbo { @Required @ManyToOne public ProjectDbo project; } We then

  • 0

We have:

public class TicketDbo {
   @Required
   @ManyToOne
   public ProjectDbo project;
}

We then have many projects to choose from, so we add a pulldown menu when you edit the Ticket where you can choose one of the projects.

We want to render something like this(this is the easy part and we know how to do this part with #{select}:

<select ... >
  <option value="" selected="selected">Please select...</option>
  <option value="1">Project1</option> 
  <option value="56">Project2</option>
</select>

NOTE: The value above is the entity id in the database.

What we want is some piece of code outside the controller where this code would run before the controller is invoked (AND we could hopefully re-use this code for any of these ManyToOne situations that happen all the time):

 ProjectDbo project = JPA.em().getReference(selectedOptionValueFromAbove); 
 //note, getReference doesn't hit DB!!!!
 ticketDbo.setProject(project);

Then our controller would be the same as always:

public static void postTicket(TicketDbo ticket) {
    //at this point the ticket already has the ProjectDbo and validation of it being required has already been run from the @Required annotation
}

Anyone knows how to do something like this? Or is there a plugin to help with this?

@2ND QUESTION: How do this with an enumeration as well? (Hopefully that is just a tweak to the above).

  • 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-31T03:06:09+00:00Added an answer on May 31, 2026 at 3:06 am

    This seems to work well(formed from one of the comments @maartencls made on another answer)

    @Global
    public class ProjectRefBinder implements TypeBinder<ProjectDBO>{
        @Override
        public Object bind(String name, Annotation[] annotations, String value,
                Class actualClass, Type genericType) throws Exception {
            if(value == null)
                return null;
            EntityManager em = JPA.em();
            Long id = Long.valueOf(value);
            ProjectDBO ref = em.getReference(ProjectDBO.class, id);
            return ref;
        }
    }
    

    Then in the page, I can do a #{ticket.project} and in my controller method, my TicketDbo ends up with a ProjectDbo proxy wrapping the id selected!!! works great so far I think. This class also works not just for my TicketDbo for other entities as well that have a ProjectDbo in them.

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

Sidebar

Related Questions

I have in my WPF project file RssInfo.cs in which I have public class
For example i have public class Person { public int Id {get;set;} [Required()] public
In the main class of my project, I have public class MyClass extends Activity{
Suppose I have: public class foobar { public int lorem; public int ipsum; }
Suppose I have public class Product: Entity { public IList<Item> Items { get; set;
In c# you can have public class Foo { public Foo(string name) { //do
Let's say I have: public class Components<T> extends TupleList<Class<T>, String> { private static final
Say I have: public class A extends B { /* autocompletion doesn't suggests protected
For example is it better to have: public class Case : EntityIdentifiable { public
Here is the domain that I wish to have: public class Person { public

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.