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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:20:59+00:00 2026-05-26T23:20:59+00:00

I have an input field and a button. I want to check if the

  • 0

I have an input field and a button. I want to check if the textinput is valid before executing the button action. If it is valid I will render a response message. I have a code like this:

public void submitReportRequest() {
    if(nameField!=null){
        System.out.println("aaaaaaaaaaaaa");
        submitted=true;
    }
    if(nameField == null){
        System.out.println("report name is null!!!!!!");
    }
}

but from the console I just get:

[#|2011-11-18T15:22:49.931+0200|INFO|glassfishv3.0|null|_ThreadID=21;_ThreadName=Thread-1;|aaaaaaaaaaaaa|#]

when the nameField is empty, I receive nothing in the console just page is re-rendered with the validation message of nameField. I know from the JSF life cycle if the validation phase fails then it jumps directly to the render response phase and button action is never reached. But how can I achieve my objective in this case?

  • 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-05-26T23:21:00+00:00Added an answer on May 26, 2026 at 11:21 pm

    Empty submitted values default to empty strings, not null. Instead, you need to check if the string is empty by String#isEmpty():

    if (nameField.isEmpty()) {
        // Name field is empty.
    } else {
        // Name field is not empty.
    }
    

    You perhaps want to cover blank spaces as well. In that case, add trim():

    if (nameField.trim().isEmpty()) {
        // Name field is empty or contained spaces only.
    } else {
        // Name field is not empty and did not contain spaces only.
    }
    

    Note that the String#isEmpty() is introduced in Java 1.6. If you’re still on Java 1.5 or older for some reason, then you need to check String#length() instead.

    if (nameField.length() == 0) {
        // Name field is empty.
    } else {
        // Name field is not empty.
    }
    

    However, that’s not the normal way of required field validation. You should put the required="true" attribute on the input field instead.

    <h:inputText id="name" value="#{bean.name}" required="true" />
    <h:message for="name" />
    

    This way JSF will validate it by itself and display the appropriate message and will skip the action method invocation.

    See also:

    • Debug JSF lifecycle
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an input field and a login button. I want to allow users
I have an input field with an id that is used as a button.
I have a page with File html input field and a Submit button as
I have an input field which has a placeholder text. I want one word
I have one input field and 2 buttons, each button performs a different function.
I have an input field and I want that variable to be passed as
i have a selection field and when the button #btnaddtocart is selected i want
I have an input field on my page where the user will type in
I have 2 radio buttons and 2 input fields. I want to associate a
I have a form with input fields and a button which fades in when

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.