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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:15:30+00:00 2026-06-18T20:15:30+00:00

Is there a way to set a bean property from a Validator ? In

  • 0

Is there a way to set a bean property from a Validator?
In my case, I have a validator which connects to the database and performs some validation.
Upon successful validation, I want to save the object received from database, inside a bean property.
Currently i’m doing this by setting a static property of my bean from the validator.
Here is my validator method

public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
    //perform validation
    if(isValidated) {
        Referral ref = database.getReferral(value.toString());  //receive referral object from batabase
        RegistrationBean.staticReferral = ref; // Set ref to RegistrationBean's static property
    } else {
       FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_FATAL, "Invalid Referral!", "Referral does not exist!");
        throw new ValidatorException(msg);
    }
}  

and here is my RegistrationBean

@ManagedBean  
@ViewScoped  
public class RegistrationBean implements Serializable {

    //other bean properties
    private Referral referral;
    public static Referral staticReferral;

    public RegistrationBean() {
        //default constructor
    }

    public Referral getReferral() {
        this.staticReferral = referral;
        return referral;
    }
    // other getters, setters and methods
}

So the questions in my mind are:

  • Is there a way to set a bean property directly from a bean? (without
    using a static property)
  • Would there be any concurrency issues (one user may receive other user’s selected referral object etc) using the existing approach?

Thanks

  • 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-18T20:15:31+00:00Added an answer on June 18, 2026 at 8:15 pm

    Static members in managed beans are shared among all instances (and users of your application). So think at least twice before making a member variable static.

    If you make your validator a managed bean, you can inject your target managed bean into your validator. See this answer for details.

    In the given example an EJB is injected, but you can inject a JSF managed bean via the @ManagedProperty annotation

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

Sidebar

Related Questions

Is there a way to set a property of a bean in a Spring
Is there any way to set DPI (dots per inch) in case of PDFsharp?
Is there a way to set a property in spring to, not an instance
Is there any standard way to access Java Bean Property like class A {
I have a JSF ManagedBean which has a property that should be set by
Is there any way to know which tab from the list is clicked in
Is there way to set @include mixin(); to variable? I tried this @mixin bg-gradient($fallback,
Is there any way to set up a PendingIntent with the download manager? Or
Is there any way to set order by clause in HQL by run time.
Is there a way to set a constant width for geom_bar() in the event

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.