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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:13:34+00:00 2026-06-13T20:13:34+00:00

My problem is similar to this issue . I have a BaseBean which currently

  • 0

My problem is similar to this issue. I have a BaseBean which currently has just a single property which is annotated as a @ManagedProperty.

However, when I access the getter of this inherited managed property in the action method a commandbutton, it returns null. I debugged and confirmed that the base bean constructr was called twice – once on page load and next on click of the button as already described in the mentioned link.

I followed the suggestions as mentioned the article’s chosen answer as well as this post, but to no avail.

Following is my code:

public abstract class BaseBean
{
   @ManagedProperty(value = "#{serviceLocator}")
   private IServiceLocator serviceLocator;

   public IServiceLocator getServiceLocator() {
      return serviceLocator;
   }

   public void setServiceLocator(IServiceLocator serviceLocator) {
      this.serviceLocator = serviceLocator;
   }
}

@ManagedBean
@ViewScoped
public class RegistrationBean extends BaseBean implements Serializable
{
   private static final long serialVersionUID = -6449858513581500971L;

   private String userID;
   private String password;
   private String firstName;
   private String lastName;
   private String email;
   private String addressLine1;
   private String addressLine2;
   private String city;
   private String state;
   private String pincode;

   private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationBean.class);

   /* getter / setters */

   public String register() 
   {
      String nextPage = null;
      try {
         RegistrationDetails userDetails = ModelBuilder.populateRegistrationData(this);
         int registrationID = getServiceLocator().getUserService().registerUser(userDetails);
         LOGGER.info("Registered user successfully. Registration ID - {}", registrationID);
         nextPage = "success";
      }
      catch (RegistrationException e) {
         LOGGER.error(e.getMessage());
      }
      return nextPage;
   }

   public void checkUserExists() 
   {
      int regID = getServiceLocator().getUserService().findUser(getUserID());

      if(regID > 0) {
         FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_WARN, "User already exists !!", null);
         FacesContext.getCurrentInstance().addMessage(null, message);
      }
   }
}

Why would the constructor be called again on form submit ??? :/

The getter returns null even in the checkUserExists() method which is called via ajax on the blur event of the userID field.

EDIT : Added code for ServiceLocator..

@ManagedBean
@ApplicationScoped
public class ServiceLocator implements IServiceLocator
{
   private static final String USER_SERVICE = "userService";
   private static final String MOVIE_SERVICE = "movieService";

   @PostConstruct
   public void init() {
      final ServletContext sc = FacesUtils.getServletContext();
      this.webAppContext = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
      this.userService = (IUserService) webAppContext.getBean(USER_SERVICE);
      this.movieService = (IMovieService) webAppContext.getBean(MOVIE_SERVICE);
   }

   private ApplicationContext webAppContext;

   private IUserService userService;

   private IMovieService movieService;

   @Override
   public IUserService getUserService() {
      return userService;
   }

   @Override
   public IMovieService getMovieService() {
      return movieService;
   }
}
  • 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-13T20:13:36+00:00Added an answer on June 13, 2026 at 8:13 pm

    AFAIK you’re trying to mix two answers: one for @RequestScoped mbeans and other for @ViewScoped mbeans. If you see the first link you’ve posted, BalusC is saying that you don’t have to have @ManagedProperty in @ViewScoped mbeans as shown in ViewParam vs @ManagedProperty(value = “#{param.id})”.

    If you can’t pass the serviceLocator through a view param, you have to find another way to get that value (saving/retrieving it from session).

    Also, check this info from BalusC explaining why the @ViewScoped mbean could be recreated on every request:

    In a nutshell: the @ViewScoped breaks when any UIComponent is bound to the bean using binding attribute or when using JSTL or tags in the view. In both cases the bean will behave like a request scoped one. The first one is in my opinion a pretty major bug, the second one is only an extra excuse to get rid of the whole JSTL stuff in Facelets.

    This is related to JSF 2.0 issue 1492. Here’s an extract of relevance:
    This is a chicken/egg issue with partial state saving. The view is executed to populate the view before delta state is applied, so we see the behavior you’ve described.
    At this point, I don’t see a clear way to resolve this use case.
    The workaround, if you must use view-scoped bindings would be setting javax.faces.PARTIAL_STATE_SAVING to false.

    From

    • The benefits and pitfalls of @ViewScoped

    Based on your comment and edit, you can access to the @ApplicationScoped mbean by using the code provided here:

    • How to get application scope variable in jsf?

    This would be the line:

    FacesContext.getCurrentInstance().getExternalContext()
        .getApplicationMap().get("serviceLocator");
    

    You have to use that code since, apparently, the @ViewScoped bean can’t accept injection by @ManagedProperty.

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

Sidebar

Related Questions

Similar to this question: link However I have already mastered that. My problem is
I have a cross-tab report which similar to this Problem is when there are
I have a similar problem to this issue: Merging 2 pdf with Zend Framework
An issue I discover today is similar to this unanswered problem ; though not
I have checked this similar question, but the suggestions did not solve my problem:
I notice this thread: Fastish Python/Jython IPC , and I have a similar problem,
This is similar to an earlier problem I was having which you guys solved
I have a problem similar to this , although hopefully I've narrowed it down
Not sure if anyone has experience this issue. I have a TextBox that I
I have a problem somehow similar to this post : glTexGen in OpenGL ES

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.