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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:02:42+00:00 2026-06-13T04:02:42+00:00

My following code is not working as per expectation. The validation does not work

  • 0

My following code is not working as per expectation. The validation does not work as expected.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:f="http://java.sun.com/jsf/core">

<h:head>
    <title>My Registration Page</title>
    <link href="stylesheet/reset.css" rel="stylesheet" type="text/css" />
    <link href="stylesheet/style.css" rel="stylesheet" type="text/css" />
    <link rel="icon" type="image/png" href="images/icons/favicon.png" />
    <script src="script/script.js" />
</h:head>
<h:body>
    <h:outputText id="progress_bar" styleClass="progress-bar" /> 
    <a4j:jsFunction name="login" action="#{loginBean.validateUser}" />


    <div id="login-container">
        <div class="login-logo">
            <img src="images/logo.png" />
        </div>
        <f:view>
            <div id="loin-form">
                <h1>
                    Log in to your account or <a href="#">sign up</a> to Get Started
                </h1>
                <h:form>
                    <h:inputText id="userName" value="#{loginBean.userName}"
                        label="User Name" required="true" class="txtFld">
                        <f:validator
                            validatorId="com.coinfling.validation.LoginBeanValidator" />
                    </h:inputText>
                    <h:message for="userName" style="color:red"></h:message>
                    <h:inputSecret id="passWord" value="#{loginBean.passWord}"
                        label="Password" required="true" class="pswrdFld">
                        <f:validator
                            validatorId="com.coinfling.validation.LoginBeanValidator" />
                    </h:inputSecret>
                    <h:message for="passWord" style="color:red"></h:message>
                    <p>
                        <a4j:commandLink id="forgotPasswordLink" lable="Password"
                            value="Forgot Your Password? " />
                        <a4j:commandButton id="loginButton" value="Sign In"
                            onclick="login();" styleClass="sign-btn" />
                    </p>
                </h:form>
            </div>


        </f:view>
    </div>

</h:body>
</html>

My simple validation class code is below
package com.coinfling.validation;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;
@FacesValidator("com.coinfling.validation.LoginBeanValidator")
public class LoginBeanValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent toValidate,
            Object value) throws ValidatorException {
        FacesMessage message = new FacesMessage("*UserName is not in Correct Format");
        throw new ValidatorException(message);

//      
//      if(toValidate.getId().equals("userName"))
//      {
//          FacesMessage message = new FacesMessage("*UserName is not in Correct Format");
//          throw new ValidatorException(message);
//      }
//      else if(toValidate.getId().equals("passWord"))
//      {
//          FacesMessage message = new FacesMessage("*Password is not in Correct Format");
//          throw new ValidatorException(message);
//      }
    }

}

As you can see my validation i am just thrown an exception for whatever gets input. The required field is also not working. No error message is printed. What am i doing wrong ?

Kind Regards

  • 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-13T04:02:43+00:00Added an answer on June 13, 2026 at 4:02 am

    You’re not actually submitting the form. You’re basically invoking a standalone bean method separately. That’s a huge difference. To execute validation on the form, you have to submit the form.

    Replace the wrong a4j:jsFunction approach:

    <a4j:jsFunction name="login" action="#{loginBean.validateUser}" />
    ...
    <a4j:commandButton id="loginButton" value="Sign In"
       onclick="login();" styleClass="sign-btn" />
    

    by the normal form submit approach:

    <a4j:commandButton id="loginButton" value="Sign In"
       action="#{loginBean.validateUser}" styleClass="sign-btn" />
    

    I’m not sure why you used a4j:jsFunction, but whatever you thought to benefit from the a4j:jsFunction, has definitely to be solved in a different way.

    Don’t forget to add a render="@form" to update the form on complete of the ajax request, so that all messages are been shown:

    <a4j:commandButton id="loginButton" value="Sign In"
       action="#{loginBean.validateUser}" render="@form" styleClass="sign-btn" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why is the following code not working? if(EventLog.Exists(Foo)) { EventLog.Delete(Foo); } if(EventLog.Exists(Foo) == false)
can anybody tell me why is the following code not working? <script type=text/javascript src=../../Scripts/jquery.js></script>
i am using python 2.5.2 . The following code not working. def findValue(self, text,
The following code is not working: private void fileNameLinkButton_Click(object sender, RoutedEventArgs e) { HyperlinkButton
Any idea why the following code is not working mysql credentials are correct, have
My following code for posting the UIImage to user's facebook wall is not working
I'm trying the following code to execute a search and it's not working. On
I'm working in Python. I have the following code: while not is_suffix(pattern[:k], pattern[:q]): k
I have the simple following code, which is working in a ruby (not rails)
The following code for prime sieve is not working with Release mode ,,but works

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.