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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:40:54+00:00 2026-05-31T18:40:54+00:00

I’ve started learning JSF2.0, and have come across a problem. Any advice on how

  • 0

I’ve started learning JSF2.0, and have come across a problem. Any advice on how to proceed would be welcome.

I have renamed form elements and classes for simplicity sake.

I have a form, for example:

<h:form id="frmSearch">
    <h:inputText id="dataPoint1" value="#{bean.dataPoint1}"/>
    <div id="dataPoint1Error" class="msgError">Value not found in database.</div>

    <h:inputText id="dataPoint2" value="#{bean.dataPoint2}"/>
    <div id="dataPoint2Error" class="msgError">Value not found in database.</div>

    <h:commandButton action="#{bean.validate}" type="submit" value="Search"/>
</h:form>

The CSS class “msgError” keeps the element hidden by default.

I would like to basically have a method in the “bean” class that validates the input by checking against the database, then if the value isn’t found, unhide the error message, or if it is found, then execute another method which performs the actual functionality.

In my head, it would work sort of like this in the Java (forgive any syntax errors, just typing as I think):

@ManagedBean
public class Bean {
    private String dataPoint1 = "";
    private String dataPoint2 = "";

    public boolean validate() {
        if(dao.fieldExists(this.dataPoint1) && dao.fieldExists(this.dataPoint2)) { //check the database
            performFunctionality();
            return true;
        }
        else {
            return false; //and show error div on screen
        }
    }        

    public void performFunctionality() {
        //do whatever
    }

    //getters and setters
}

Any advice would be very welcome!
Thanks!

  • 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-31T18:40:55+00:00Added an answer on May 31, 2026 at 6:40 pm

    You’re not utilizing JSF builtin validation facilities. Make use of it.

    Here’s how it can look like:

    <h:form id="frmSearch">
        <h:inputText id="dataPoint1" value="#{bean.dataPoint1}" validator="#{bean.validateDataPoint}" />
        <h:message for="dataPoint1" />
    
        <h:inputText id="dataPoint2" value="#{bean.dataPoint2}" validator="#{bean.validateDataPoint}" />
        <h:message for="dataPoint2" />
    
        <h:commandButton action="#{bean.performFunctionality}" value="Search">
            <f:ajax execute="@form" render="@form" />
        </h:commandButton>
    </h:form>
    

    with

    public void validateDataPoint(FacesContext context, UIComponent component, Object convertedValue) {
        if (!dao.fieldExists((String) convertedValue)) {
            throw new ValidatorException(new FacesMessage("Value not found in database."));
        }
    }        
    

    That performFunctionality() must be executed by the command button’s action method.

    When validation fails (i.e. ValidatorException is been thrown), then the message will be displayed in the <h:message> associated with the input component and the action method won’t be invoked. The validator attribute can alternatively also point to a fullworthy class which implements javax.faces.validator.Validator. The <f:ajax> is been added to make it an ajax submit.

    See also:

    • How to perform validation in JSF, how to create a custom validator in JSF

    Wherever you’ve learnt JSF, make sure that you’ve also read the chapters about conversion and validation. Don’t think too much the PHP/ASP/JSP/jQuery way. JSF is a full fledged component based MVC framework.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I would like to run a str_replace or preg_replace which looks for certain words

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.