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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:18:17+00:00 2026-06-17T00:18:17+00:00

I want to use both InCell editing in DataTable and the validation. I know

  • 0

I want to use both InCell editing in DataTable and the validation. I know that the trivial validations can be solved with f:validator, but what with non-trivial names?

I must, let’s say, assure that the ‘name’ property is unique in the table. So, before accepting the edit, I should check if the name is changed and if it is used by another element. If so, the edit must be refused.

How to achieve it? The eventListener would be only notified that the edit was accepted, as I have understood, so theoretically I could react and revert it, but I would prefer to refuse the edit when user clicks the ‘accept’ icon.

  • 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-17T00:18:18+00:00Added an answer on June 17, 2026 at 12:18 am

    Like Daniel said, you can use a JSF validator for this. A short example:

    Assume we have a person:

    public class Person
    {
        // Just imagine getters and setters ;-)
        private String firstName, lastName;
    }
    

    And a very simple backing bean:

    @ManagedBean
    @ViewScoped
    public class PersonBean
    {
        private List<Person> persons = new ArrayList<Person>();
    
        @PostConstruct
        private void init()
        {
            persons.add(new Person("John", "Doe"));
        }   
    }
    

    For example we want to ensure the first name starts with an uppercase letter. We don’t care if the last name doesn’t start with an uppercase letter (because of compatibility with IE or a legacy database, you know, the usual weirdness).

    @FacesValidator("firstNameValidator")
    public class FirstNameValidator implements javax.faces.validator.Validator
    {
        @Override
        public void validate(FacesContext context, UIComponent component,
            Object value) throws ValidatorException
        {
            if (!Character.isUpperCase(String.valueOf(value).charAt(0)))
            {
                FacesMessage msg = new FacesMessage("First name should start with a capital.");
                throw new ValidatorException(msg);
            }
        }
    
    }
    

    Now to display everything nicely:

    <p:growl id="growl" />
    <h:form>
        <p:dataTable value="#{bean.persons}" var="person" editable="true">
            <p:ajax event="rowEdit" update=":growl"/>
            <p:column headerText="first name">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{person.firstName}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText validator="firstNameValidator"
                            value="#{person.firstName}" />
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column headerText="last name">
                <p:cellEditor>
                    <f:facet name="output">
                        <h:outputText value="#{person.lastName}" />
                    </f:facet>
                    <f:facet name="input">
                        <p:inputText value="#{person.lastName}" />
                    </f:facet>
                </p:cellEditor>
            </p:column>
            <p:column>
                <p:rowEditor />
            </p:column>
        </p:dataTable>
    </h:form>
    

    If you’re interested, validation can be configured on domain-level by using bean validation (JSR-303). I strongly recommend it since it doesn’t depend on JSF and it integrates with JPA.


    Update as promised using bean validation:

    First, the validator:

    public class FirstNameValidator implements ConstraintValidator<FirstUpper, String>
    {
        @Override
        public void initialize(FirstUpper constraintAnnotation) { }
    
        @Override
        public boolean isValid(String value, ConstraintValidatorContext context)
        {
            return Character.isUpperCase(value.charAt(0));
        }
    
    }
    

    The annotation we’re going to use:

    @Constraint(validatedBy = FirstNameValidator.class)
    @Target({ ElementType.METHOD, ElementType.FIELD })
    @Retention(RetentionPolicy.RUNTIME)
    public @interface FirstUpper
    {
        String message() default "{FirstUpper.message}";
    
        Class<?>[] groups() default {};
    
        Class<? extends Payload>[] payload() default {};
    }
    

    Note that the message we declared "{FirstUpper.message}" will be resolved to a resource bundle. The bundle must be in the root of your classpath, named ValidationMessages.properties. To localize you can add a locale code: ValidationMessages_en.properties.

    In that file declare the message:

    FirstUpper.message=First name should start with a capital.
    

    The person class:

    public class Person
    {
        @FirstUpper
        private String firstName;
        private String lastName;
        // Imagine the getters/setters again ;-)
    }
    

    And now, in your UI you don’t have to refer to the validator, JSF is smart enough to validate using JSR-303. So instead of this:

    <p:inputText validator="firstNameValidator" value="#{person.firstName}" />
    

    Just use this:

    <p:inputText value="#{person.firstName}" />
    

    Easy right? 😉

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

Sidebar

Related Questions

I want to use both ContextLoaderListener (so that I can pass Spring Beans to
For the ASP.NET validator controls, I want to use both client-side validation for the
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I'm using gwt-maps-3.8.0, in that i want to use both clickhandler and dblclickhandler for
Basically, I want to use both $city_name and $ref_name with str_replace(), so that if
I have a Silverlight Class Library that I want to use in both my
I want to use both bash alias and bash function with several arguments. I
I want to use AngularJS with Django however they both use {{ }} as
I have a code base I want to use for both an ASP.NET MVC
I want to use the filter CSS property for both a gradient and an

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.