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

  • Home
  • SEARCH
  • 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 8649473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:34:13+00:00 2026-06-12T13:34:13+00:00

Our team is writing its first JSF 2.0 application since using Stripes for many

  • 0

Our team is writing its first JSF 2.0 application since using Stripes for many years, and I have some questions on the best way to use the f:ajax tag and validate the input.

A lot of questions I’ve seen answered have a form with multiple inputs and then a submit button), but we would like to maintain individual input fields updated immediately upon change and persisted to the database (with no submit button. We had this working fine in Stripes using Prototype’s Ajax.Request, but it was an extra step I’d like to avoid if possible.

Essentially we have a page with a bunch of inputs on it directly backed by beans, for example:

<h:inputText id="name" value="#{personController.name}" >
    <f:ajax listener="#{personController.ajax}" />
</h:inputText>

As you may know, by the time the listener is invoked, the value of name has already been changed on the bean. This would be convenient, but I have a few problems with it:

  • the listener doesn’t obviously know which value of the bean was changed
  • the value has already been changed, I can’t perform any server side validation on it
  • I don’t know what the old value of name is even if I could perform some sort of validation on it, I wouldn’t know what to set the value back to

Right now it’s looking like we’ll have to implement some kind of javascript middleman to take in what property changed and the new value, send that to the Controller, and have it perform validation, updating the database, sending back something to render, etc. But like I said, this is what we used to do with Stripes and I’d really like to use something more native.

I did see that if we wanted some kind of Submit button on the page we could use something like the valueChangeListener attribute, but I’d also like to avoid massive submits.

I included the OpenFaces tag because we’re already using that for datatables, so if there’s something nice in there we’re open to using it. But as far as I can tell their o:ajax tag isn’t that much more powerful than JSF’s f:ajax.

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-06-12T13:34:15+00:00Added an answer on June 12, 2026 at 1:34 pm

    You’re looking in the wrong direction to achieve the concrete functional requirement of validating an input field. You should use a normal JSF validator for this, not some ajax listener method which runs at the wrong moment (the INVOKE_ACTION phase instead of PROCESS_VALIDATIONS phase) and where you don’t directly have a hand at the model value. The ajax listener method is merely to be used to execute some business logic based on the current model value(s).

    JSF has several builtin validators behind the required attribute and several <f:validateXxx> tags. You can even create custom validators by implementing the Validator interface.

    E.g. checking the requireness:

    <h:inputText ... required="true">
        <f:ajax />
    </h:inputText>
    

    Or checking if it matches a pattern using one of the various <f:validateXxx> tags:

    <h:inputText ...>
        <f:validateRegex pattern="[a-z]+" />
        <f:ajax />
    </h:inputText>
    

    Or using a custom validator:

    <h:inputText ...>
        <f:validator validatorId="myValidator" />
        <f:ajax />
    </h:inputText>
    

    with

    @FacesValidator("myValidator")
    public class MyValidator implements Validator {
    
        @Override
        public void validate(FacesContext context, UIComponent component, Object value) {
            if (value is not valid) {
                throw new ValidatorException(new FacesMessage(...));
            }
        }
    
    }
    

    The <f:ajax> is merely there to submit the current input field during the HTML DOM change event (or click event in case of checkboxes/radiobuttons). You don’t necessarily need a <f:ajax listener> method in order to submit the current input field by ajax. If you want to hook on a value change event, just use valueChangeListener.

    <h:inputText ... valueChangeListener="#{bean.valueChanged}">
        <f:ajax />
    </h:inputText>
    

    with

    public void valueChanged(ValueChangeEvent event) {
        Object oldValue = event.getOldValue();
        Object newValue = event.getValue();
        UIComponent component = event.getComponent();
        // ...
    }
    

    Note that this will only be invoked when validation has passed on the particular component.

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

Sidebar

Related Questions

My team is on our first attempt at using NServiceBus (v2.0), using MSMQ as
Our team is pretty new with testing. We are using scrum for the first
Our team is growing, but we're also growing specialized. We've already been using ticketing/bug
Our team is faced with slow but serious Javascript memory leak . We have
I'm writing some documentation for how we will use Git in our organization. For
I'm writing a work management application in C# for my team at work (because
Using: ASP.NET 4, SQL 2008, C# I'm writing a web app for our projects
Recently I participated in designing & writing of an application which my team was
I work with a small team (4 developers) writing firmware and software for our
My team is working on educating some of our developers about testing. They understand

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.