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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:13:04+00:00 2026-05-27T17:13:04+00:00

I have foreign key inside my Customer table. @JoinColumn(name = DISCOUNT_CODE, referencedColumnName = DISCOUNT_CODE)

  • 0

I have foreign key inside my Customer table.

@JoinColumn(name = "DISCOUNT_CODE", referencedColumnName = "DISCOUNT_CODE")
@ManyToOne(optional = false)
private DiscountCode discountCode;

I have a form that contains all fields of this table (including the foreign key discountCode and its description from the other table).

I want to be able to show a message that this foreign key does not exist in case that the user entered an input that does not exist in the foreign key table.
When I onblur this field, then I’m retriving its description from the table. How can I show the error message of invalid field when the user onblurs it and it does not exist in the table?

  • 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-27T17:13:05+00:00Added an answer on May 27, 2026 at 5:13 pm

    What you need is a Validator. It should look like this:

    @ManagedBean
    @RequestScoped
    public class DiscountCodeValidator implements Validator {
        @EJB
        private MrBean mrBean;
    
        @Override
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            String discountCode = (String) value;
    
            if (!mrBean.checkDiscountCodeExistence(discountCode)) {
                throw new ValidatorException(new FacesMessage("This code is not valid!"));
            }
        }
    }
    

    In your .xhtml file, you can declare this validator as following:

    <h:inputText id="discountCode" value="#{someBean.discountCode}" 
                 validator="#{discountCodeValidator}" 
                 required="true" requiredMessage="Discount code is required.">
       <f:ajax event="blur" render="discountMsg" />
    </h:inputText>
    <h:message for="discountCode" id="discountMsg"/>
    

    One thing to note is I assume that you would inject an EJB to check the existence of the discount code with the checkDiscountCodeExistence() function. Hence, I annotated the above Validator as a @ManagedBean. If you don’t need to inject any EJBs, you can annotate the Validator with @FacesValidator.

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

Sidebar

Related Questions

I have created a foreign key (in SQL Server) by: alter table company add
I have a table containing primary key and foreign key that references same table.
I have a table it includes 3 foreign key field like that: My Table:
If I have a table with two foreign key fields to another table, I.E.
We have a non normalized table that contains foreign key infomration as free text
I have a table B that has a foreign key to table A, and
Why can you not have a foreign key in a polymorphic association, such as
I have a number of child tables that have a foreign key to a
I have a Person model that has a foreign key relationship to Book ,
I have a model that contains a foreign key value, then in the form

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.