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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:47:09+00:00 2026-05-31T12:47:09+00:00

I have a Model: @Entity @Table(name = User) public class User implements Serializable {

  • 0

I have a Model:

@Entity
@Table(name = "User")
public class User implements Serializable  {

    private static final long serialVersionUID = 546951187473649176L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Size(min = 3, max = 25)
    @Pattern(regexp = "[A-Za-z ]*", message = " wroooooong")
    private String name;

    /** some setters and getters **/
}

I have a UserController.java

@ManagedBean(name = "userController")
@SessionScoped
public class UserController implements Serializable {

    private static final long serialVersionUID = -4210819542193607967L;

    @EJB
    private UserProvider userProvider;

    @Inject
    EntityManager entityManager;

    @PostConstruct
    public void initNewUser() {
        user = new User();
    }

    private User user;

    public void registerUser() throws ValidatorException  {
        try {
            userProvider.registerUser(new User(),user);
        } catch (Exception e) {
            throw new ValidatorException(new FacesMessage(e.getMessage()));

        }
    }

    private String name;
    /** some setters and getters **/

}

The UserProvider looks like this:

@RequestScoped
@Stateful
public class UserProvider {

    @Inject
    private EntityManager entityManager;

    public void registerUser (User newUser, String name) throws Exception {
        try {
            newUser.setName(name);
            entityManager.persist(newUser);
        } catch (Exception e){
            throw e;
        }
    }
}

and, finally my register.xhtml:

<h:form>
    <label for="name">name</label>
    <h:inputText id="name" value="#{userController.name}" required="true"  />
    <h:message id="register_name_error" for="name" errorClass="invalid"/>
    <h:commandButton action="#{userController.registerUser()}" id="submit" value="send" />
</h:form>

When i enter something to short in the name field, i got this in my stack:

 javax.validation.ConstraintViolationException: Validation failed for classes [de.liedl.bachelor.model.User] during persist time for groups [javax.validation.groups.Default, ]
List of constraint violations:[
    ConstraintViolationImpl{interpolatedMessage='muss zwischen 3 und 25 liegen', propertyPath=accountName, rootBeanClass=class de.demotest.model.User, messageTemplate='{javax.validation.constraints.Size.message}'}
]

but the error is never thrown back to my <h:message
What is wrong?
I downloaded a demo-application, where it worked totally easy, but this was little bit different, without provider and controller and model, it was just the the model and a mix-class…

I also tried this with just throw exception and with and without try catch

which Validator do i need in the UserProvider?

  • 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-31T12:47:11+00:00Added an answer on May 31, 2026 at 12:47 pm

    You need to bind the field to a property of the model, not to a property of the controller.

    <h:inputText id="name" value="#{userController.user.name}" required="true"  />
    

    Unrelated to the concrete problem, throwing a ValidatorException inside an action method makes no sense. You have 2 options:

    1. Let it go so that it end up in container’s default error page or a custom one definied in web.xml.

    2. Create and add a faces message yourself by FacesContext#addMessage().

    Further I also wonder how it’s useful to have a @Stateful service in this particular case. It could be as good just @Stateless. That @RequestScoped on an EJB is completely unnecessary and only confusing. That whole try-catch and throws Exception in the service method is also completely unnecessary. That @Inject won’t work at all in side a @ManagedBean. The one inside the EJB must be @PersistenceContext instead. You’re completely mixing JSF/CDI/EJB annotations. Please be very careful with this.

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

Sidebar

Related Questions

I have 2 models. User: @Entity public class User implements Serializable { Long id;
I have a parent-child relationship: @Entity @Table(name = user) public final class User {
I have Doctrine 2.1 entity: /** * @Entity(repositoryClass=Varlab\Model\Repository\UserRepository) * @Table(name=user) */ class User {
I have the following code: modelBuilder.Entity<User>().HasMany(x => x.Items).WithRequired(); The model looks like public class
I am using Hibernate with spring. I have a model-class like this. @Entity @Table(name
I have the following model entity: public class ScheduledTask { public virtual int ScheduledTaskId
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
I have an entity model where the base class in an inheritance structure has
In my business model I have Entity class (IPoint interface ) that has a
I have an entity model that has audit information on every table (50+ tables)

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.