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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:41:21+00:00 2026-06-18T05:41:21+00:00

I have a CDI bean with Java object which I use to display profile

  • 0

I have a CDI bean with Java object which I use to display profile data from Database:

Parent Bean

@Named("DCProfileTabGeneralController")
@ViewScoped
public class DCProfileTabGeneral implements Serializable
{

    public DCObj dc;

    public class DCObj
    {

        private int componentStatsId;                 // COMPONENTSTATSID   NUMBER(38,0)
        ........
        // Default Constructor
        public DCObj(){};

        public DCObj(int componentStatsId....)
        {

            this.componentStatsId = componentStatsId;
            .......

        }

        public int getComponentStatsId()
        {
            return componentStatsId;
        }

        public void setComponentStatsId(int componentStatsId)
        {
            this.componentStatsId = componentStatsId;
        }
        ....
    }

    // Getters ------------------------------------------------------------------------------------
    public DCObj getdcData()
    {
        return dc;
    }

    @PostConstruct
    public void initData() throws SQLException
    {
        initDBData();
    }

    // Generate data Object from Oracle
    public void initDBData() throws SQLException
    {
                dc = new DCObj(result.getInt("COMPONENTSTATSID"),
                .........
    }
}

Validator

@Named("ValidatorDatacenterController")
@ViewScoped
public class ValidatorDatacenter implements Validator, Serializable
{

    public ValidatorDatacenter()
    {
    }

    @Inject
    private DCProfileTabGeneral profileTabGeneral;


    // Validate Datacenter Name
    public void validateDatacenterName(FacesContext context, UIComponent component, Object value) throws ValidatorException, SQLException
    {
        int componentStatsId = -1;

        if (profileTabGeneral != null)
        {
            DCObj dcData = profileTabGeneral.dc;
            if (dcData != null)
            {
                componentStatsId = dcData.getComponentStatsId();
            }
        }

        if (componentStatsId == -1)
        {
            return;
        }

        String l;
        String s;

        if (value != null && !(s = value.toString().trim()).isEmpty())
        {

            if (s.length() > 18)
            {
                throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                        "  Value is too long! (18 digits max)", null));
            }

            if (ds == null)
            {
                throw new SQLException("Can't get data source");
            }

            Connection conn = null;
            PreparedStatement ps = null;
            ResultSet rs;
            int resComponentStatsId = -1;
            try
            {
                conn = ds.getConnection();
                // if componentsstatsid <> edited componentstatsid in jsf -> throw validator exception
                ps = conn.prepareStatement("SELECT componentstatsid from COMPONENTSTATS where NAME = ?");
                ps.setString(1, s);
                rs = ps.executeQuery();

                while (rs.next())
                {
                    resComponentStatsId = rs.getInt(1);
                }

                if (resComponentStatsId != -1 && resComponentStatsId != componentStatsId)
                {
                    throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                            "  '" + s + "' is already in use!", null));
                }

            }
            catch (SQLException x)
            {
                throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                        "  SQL error!", null));
            }
            finally
            {
                if (ps != null)
                {
                    ps.close();
                }
                if (conn != null)
                {
                    conn.close();
                }
            }
        }
        else
        {
            throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                  "  This field cannot be empty!", null));
        }

    }

}

I have a custom validator which checks the input values from the profile page into the Database. I tested to get the Java object from the parent page using @Inject and to pass the Ojject to the validator. It turns out that I get empty Java object every time when I use @Inject.

I also tested to get Int using CDI. It works but when I again tested to get the Java Object again I get empty Object.

Can you tell me what is the proper way to call a Java Object from CDI bean? Why I cannot get Java object from CDI bean?

  • 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-18T05:41:23+00:00Added an answer on June 18, 2026 at 5:41 am

    If I recall correctly CDI injection will not work with a validator. Use advanced from Myfaces CODI as the JSF-module from deltaspike is not ready yet. https://cwiki.apache.org/EXTCDI/jsf-usage.html

    Or go for deltaspike and use the BeanProvider to get your instance.

    BeanProvider.getContextualReference(DCProfileTabGeneral .class, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Stateless Session Bean (java ee 6, cdi) which throw events @Stateless
I'm trying to use CDI for my JSF/Java EE application. I have the following
I have already one session scoped CDI bean, which keeps currently logged in user
In my application, I have an @ApplicationScoped CDI bean to store some information from
I have a CDI bean annotated with @Named and @RequestScoped. It is working perfectly
have written this little class, which generates a UUID every time an object of
I have a Java EE 6 CDI based application running on JBoss AS 7.1.1
I have a database with 2 tables CD and Song . Session bean access
I have a few Hibernate Envers listeners which I use for audit purposes. I
Suppose I have a dataset called data that was created from dataset(xls2struct('file.xls') : subj_CDI:

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.