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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:52:13+00:00 2026-06-18T07:52:13+00:00

I get NPE in JSF validator and I cannot find what cause this problem:

  • 0

I get NPE in JSF validator and I cannot find what cause this problem:

// Validate Datacenter Name
    public void validateDatacenterName(FacesContext context, UIComponent component, Object value) throws ValidatorException, SQLException
    {
        // Original value
        Object modelValue = ((UIInput) component).getValue();

        String oriDCName = modelValue.toString();

        String s; // New inserted value

        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;
            String resDCName = null;
            try
            {
                conn = ds.getConnection();
                // if componentsstatsid <> edited componentstatsid in jsf -> throw validator exception
                ps = conn.prepareStatement("SELECT NAME from COMPONENTSTATS where NAME = ?");
                ps.setString(1, s);
                rs = ps.executeQuery();

                while (rs.next())
                {
                    resDCName = rs.getString(1);
                }

                if (resDCName != null && (!resDCName.equals(oriDCName) ))
                {
                    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));
        }

    }

When I enter new value which is unique I get NPE. When I enter value which is already found into the DB table I get ...is already in use!.

The problem is somewhere here if (resDCName != null && (!resDCName.equals(oriDCName) )) but I cannot solve it. Any idea how to fix this?

  • 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-18T07:52:15+00:00Added an answer on June 18, 2026 at 7:52 am

    change your logic like below code. I am assuming you want resDCname should not be equals to origDCName.

    while (rs.next())
    {
    
        resDCName = rs.getString(1);
     if (resDCName != null && resDCName.equals(oriDCName))
        {
           throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
                               "  '" + s + "' is already in use!", null));
         }
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I cannot get a trivial Robotium test running: public class TapsTest extends ActivityUnitTestCase<Ad> {
I hope I get this one straight: I try to create an JSF 2.0
I'll make this quicky and easy. I get an NPE error... Row: 0 You
I get this error while accessing a php script: W/System.err: Error reading from ./org/apache/harmony/awt/www/content/text/html.class
import javax.swing.JOptionPane; public class RotateArrayCircularLL { private Node head=null; public void init() { int
In code reviews I stumbled over this java-pattern to avoid NPE's: value = (null
If I have the following code in a Fragment: public void doSomething() { if
Why do I get an NPE at Drawable pic = (Drawable) i.getDrawable();?????? I am
I create guice servlet like this: public class GuiceApplicationServlet extends AbstractApplicationServlet { protected Provider<Application>
Why do I get an NPE on the assignment of: mPyramid[row][column] = temp; Here

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.