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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:55:51+00:00 2026-05-22T01:55:51+00:00

I have an User object that has many attributes. In my edit profile screen

  • 0

I have an User object that has many attributes. In my edit profile screen I’m displaying a subset of those attributes. In the corresponding controller action how can I validate only those fields that are being edited and not all the fields in the User object?

I have annotated the fields in the User object with the MaxSize, Email, URL, etc. constraints and don’t want to repeat them again by validating each field manually.

Any pointers would be greatly appreciated. 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-22T01:55:51+00:00Added an answer on May 22, 2026 at 1:55 am

    the simplest way is to pass the full object to the receiving method and just validate all of it. As you are only editing a subset of fields, they will be the only ones changing and the ones that will trigger an error if the validation fails. This is, of course, assuming that you never store invalid objects in the database!

    If not, you can also create a support bean that doesn’t extend from Model, with validation tags, and pass that to the form and controller. Something like:

    public class SupportBean {
       @Email
       public String mail;
       @Max(3)
       public int size;
       //etc, add getters and setters as I'm not sure if it is required.
    }
    

    In both cases it would be something like this, replacing the full object User by a temporary object if needed (double check the code, I don’t have Play environment here and I may do some typos/small mistakes)

    *{ assuming parameter 'user' is passed in the render method that creates this view }*
    #{form @controller.save()}
      #{field 'user.name'}
        <p>
          <label>&{field.name}</label>
          <input type="text" id="${field.id}" name="${field.name}" value="${field.value}"  class="${field.errorClass}">
          <span class="error">${field.error}</span>
        </p>
      #{/field}
      *{ add more field the same way }*
    #{/form}
    

    And then in the controller:

    *{ we tag required for validation }*
    public static void save(@Valid User user) {
       checkAuthenticity();
       if(validation.hasErrors()){
         //there are errors, add to flash and redirect to edit page
       } else {
         user.save();
         //redirect
       }
    }
    

    Add a POST rule to ‘save’ int he routes file, and you are ready to go.

    The framework has a sample project (validation I think its the name) which contains 7 different ways of doing validation. The last one uses JQuery to reuse the validation tags of your class and run the same validation in the client before committing. Give them a look, they may help you a lot 🙂

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

Sidebar

Related Questions

I have a project that requires user-defined attributes for a particular object at runtime
I have a function that loads a user object from a web service asynchronously.
I have a NSTimer object that I need to invalidate if a user taps
When creating a web application, and lets say you have a User object denoting
I have user control named DateTimeUC which has two textboxes on its markup: <asp:TextBox
I have a user that want to be able to select a textbox and
I have a program in which the user adds multiple objects to a scene.
Suppose I have an array of a objects of user defined class. Wanted to
I have an array of objects which populate a UITableView . When a user
We would like to have user defined formulas in our c++ program. e.g. The

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.