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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:54:04+00:00 2026-06-18T12:54:04+00:00

I have a JSF validator which is used to validate input from form. When

  • 0

I have a JSF validator which is used to validate input from form.

When I insert simple string or duplicated string it’s working properly. But when I don’t enter anything the proper message will be This field cannot be empty!" : " '" + s + "' is not a valid name! but I don’t get anything. Can you help me to find the problem into the code logic?

// Validate Datacenter Name
    public void validateDatacenterName(FacesContext context, UIComponent component, Object value) throws ValidatorException, SQLException
    {

        String l;
        String s = value.toString().trim();

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

        try
        {
//            l = Long.parseLong(s);
//            if (l > Integer.MAX_VALUE)
//            {
//                throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
//                        "  '" + l + "' is too large!", null));
//            }
        }
        catch (NumberFormatException nfe)
        {
            l = null;
        }


        if (s != null)
        {

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

            Connection conn = null;
            PreparedStatement ps = null;
            ResultSet rs;
            int cnt = 0;
            try
            {
                conn = ds.getConnection();
                ps = conn.prepareStatement("SELECT count(1) from COMPONENTSTATS where NAME = ?");
                ps.setString(1, s);
                rs = ps.executeQuery();

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

                if (cnt > 0)
                {
                    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,
                    s.isEmpty() ? "  This field cannot be empty!" : "  '" + s + "' is not a valid name!", null));
        }

    }
  • 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-18T12:54:05+00:00Added an answer on June 18, 2026 at 12:54 pm

    that is because you only check if you s is != null.

    change if (s != null) to if (s != null && s.lenght() > 0) and try again.

    btw your String s can’t be null, because you initialize it with

    String s = value.toString().trim();
    

    and this would cause a NullPointerException if your value would be null.

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

Sidebar

Related Questions

I have a simple JSF input form into edit page and Validator which checks
We have a JSF based web application which submits the input form data to
i have a jsf page which displays an image from an url http://ichart.finance.yahoo.com/z?s=^NSEI&t=1d&q=l&l=on&z=l&p=s&a=v&p=s i
I have a simple JSF+RichFaces form with some fields and obviously a backing bean
I have a dynamic data table in JSF which has multiple input elements which
I have a JSF page that includes a tree form tag which is rendered
I have a standard JSF h:form which contains an h:SelectOneMenu control. As long as
I have a problem with a JSF composite which validates internal input fields. Following
Richfaces 3.3.3, Jsf 1.2: I have a a4j:form that uses some simple validation, mainly
For example: I have a JSF Validator to validate e-mail thusly: @FacesValidator(value=validateEmail) public class

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.