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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:16:37+00:00 2026-06-11T12:16:37+00:00

I am experimenting with JSF and Primefaces ( JSF 2.0.2 ,PrimeFaces 3.0.5, Spring 3.0.0).

  • 0

I am experimenting with JSF and Primefaces ( JSF 2.0.2 ,PrimeFaces 3.0.5, Spring 3.0.0). It seems I am unable to access managed bean from a xhtml page such as

<h:inputText  id="lastName" value="#{personalBean.personal_Basic.firstName}"  label="Last Name"  required="true" />

The request starts from a command link’s invocation to bean method, service and returns the page. I could see in servers console Bean, service methods are executed. I am not seeing anything when I try to use beans attributes as above. However I am able to access session scoped bean used for session management of the user.

Sorry if this question is too naive. Any input to resolve the problem is greatly appreciated.

Below are my code snips. This is how I call the bean:

<h:form>
    <p:commandLink id="ajax" actionListener="#{personalBean.getPersonalInfo}" style="margin-left:5px;">  
        <h:outputText value="Personal Info" />  <br/>
    </p:commandLink>  
</h:form>

Below is the request scoped managed bean.

package com.test.model;
@ManagedBean
@Scope("request")
public class PersonalBean  implements Serializable {

private static final long serialVersionUID = 199L;
private Personal_Basic personal_Basic;
private IPersonalService personalService;

@Inject
public PersonalBean(final IPersonalService personalService) {
    this.personalService = personalService;
}
public String getPersonalInfo() {
    System.out.println("\n\nPersonalBean#getPersonalInfo called...**");
    User user = null;
    Personal_Basic personal_Basic = personalService.getPersonalBasic();
    this.setPersonal_Basic(personal_Basic);
    System.out.println("personal_Basic data:"+personal_Basic);
    System.out.println("PersonalBean#getPersonalInfo ended...");
    return "/page/personal.html";
}
// Getters/setters for class members followed
}

PersonalService implementation is annotated with @Service.

Below is the excerpt from spring configuration xml.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <context:annotation-config/> 
    <context:component-scan base-package="com.test"/>
...................
...................
</beans>

Below is the excerpt from faces-config.xml

<?xml version="1.0"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee     http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
              version="2.0">
  <application>
    <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
        <resource-bundle>
            <base-name>Messages</base-name>
            <var>msg</var>
        </resource-bundle>
        <locale-config>
            <default-locale>en</default-locale>
        </locale-config>
  </application>
...........................
</faces-config>
  • 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-11T12:16:41+00:00Added an answer on June 11, 2026 at 12:16 pm

    The <context:component-scan base-package="com.test"/> element scans and registers all beans annotated with @Component, @Repository, @Service, or @Controller by default.

    Spring also offers support for javax.annotation.ManagedBean (not javax.faces.bean.ManagedBean) and JSR-330 standard annotations and these are also scanned by Spring but you need to have the following dependency added to your project.

    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>
    

    You can see all the equivalent annotations for Spring annotations here, as you can see the equivalent of @Component is @Named and for the scope use Springs @Scope annotation instead of javax.inject.scope as mentioned.
    So if you want Spring to manage all the beans in your application you can use either @Component, @Named and javax.annotation.ManagedBean annotation and inject them using @Autowired or @Inject.

    And to your question why beans annotated with javax.faces.bean.ManagedBean seem to be initialized but do not work is because as mentioned by @BalusC, @Inject is not supported in JSF you have to use @ManagedProperty annotation.

    A little background on how it all works with Spring and JSF:

    Actually there are two IOC containers in your application now with JSF and Spring, when the application starts up.
    First the org.springframework.web.jsf.el.SpringBeanFacesELResolver configured in your faces-config.xml delegates to the Spring root WebApplicationContext first resolving name references to Spring-defined beans, then to the default resolver of the underlying JSF implementation.

    Now when the JSF bean is first looked up it is constructed and then the managed property is set via the setter method so you can inject a Spring bean using the @ManagedProperty annotation like this:

    package com.test.model;
    @ManagedBean
    @RequestScoped
    public class PersonalBean  implements Serializable {
    @ManagedProperty(value="#{personalService}")
    private IPersonalService personalService;
    public IPersonalService getPersonalService() {
        return personalService;
    }
    
    public void setPersonalService(IPersonalService personalService) {
        this.personalService= personalService;
    }
    

    or you can also manually get the Spring bean using

    org.springframework.web.context.support.WebApplicationContextUtils like this:

    private Object getSpringBean(String name){
            WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(
                    (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext());
            return ctx.getBean(name);
    }
    

    and use it like this:

    Personal_Basic personal_Basic = ((IPersonalService) getSpringBean("personalService")).getPersonalBasic();
    

    But instead of using two containers in your applications you can just use the Spring container to manage all your beans by annotating JSF beans with @Component and there are no implications as such that I am aware of and should be perfectly alright to use Spring annotations.

    See also:

    • Difference between <context:annotation-config> vs <context:component-scan>
    • JSR-330 support for component detection is inconsistent
    • Spring Documentation – JSF Integration
    • Using Spring to Manage JSF beans
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm experimenting with Spring Mobile but I can't seem to get the basic example
While experimenting a bit with C++ templates I managed to produce this simple code,
As I was experimenting with JSF 2.0 , i came across a scenario like
I've been experimenting with hibernate and spring and servlets. Now, I'm stuck. Why am
While experimenting with Git, I changed a file's content from 1 to 100 ,
Experimenting with existential types. Seems to be a great way to get some type
While experimenting with this question on collections in Spring.NET , I discovered that Spring
When experimenting with Spring MVC, I noticed the values passed to controller arguments annotated
was experimenting with reading from an excel workbook and noticed it takes a long
I'm migrating code from JSF 1.2 to JSF 2.0(deployed on JBoss 6.1). However, 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.