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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:42:15+00:00 2026-05-27T09:42:15+00:00

I want to reset JSF inputs to their original managed bean values after validation

  • 0

I want to reset JSF inputs to their original managed bean values after validation failed.

I have two forms inside the same page – the first form has a commandLink to initialize the second form. The second form is rendered as a dialog whose visibility is toggled through jQuery – for the purpose of this exercise, though, I can illustrate just with two forms on the same page. Also, while I’m using PrimeFaces 2.2.x in my app, the same behaviors appear with regular h:commandLink as well.

The issue I’m having is:

  1. click link in first form to initialize second form
  2. submit invalid values in second form
  3. click link in first form again to initialize second form – invalid values still there and/or UIInput state is still invalid.

For example – take the following form

<h:form id="pageForm">
    <h:commandLink actionListener="#{testBean.initialize}">Initialize, no execute
        <f:ajax render=":dialogForm"/>
    </h:commandLink>
    <br/>
    <h:commandLink actionListener="#{testBean.initialize}">Initialize, execute=@this
        <f:ajax execute="@this" render=":dialogForm"/>
    </h:commandLink>

</h:form>

<h:form id="dialogForm">
    <h:messages/>
    String property - Valid: <h:outputText value="#{property.valid}"/>
    <br/>
    <h:inputText id="property" binding="#{property}" value="#{testBean.property}">
    <f:validateLength minimum="3"/>                         
    </h:inputText>
    <br />
    Int property - Valid: <h:outputText value="#{intValue.valid}"/>
    <h:inputText id="intValue" binding="#{intValue}" value="#{testBean.intValue}">
        <f:validateLongRange maximum="50" />                            
    </h:inputText>
    <br/>

    <h:commandLink actionListener="#{testBean.submit}">
        Submit
        <f:ajax render="@form" execute="@form"/>
    </h:commandLink>

    <h:commandLink actionListener="#{testBean.initialize}">Initialize, execute=@this
        <f:ajax execute="@this" render="@form"/>
    </h:commandLink>

</h:form>

Bean class:

@ManagedBean
@ViewScoped
public class TestBean {
  private String property = "init";
  private Integer intValue = 33;
  // plus getters/setters

  public void submit() { ... }
  public void initialize() {
   intValue = 33;
   property = "init";   
  }

}

Behavior #1

  1. click either “Initialize” link on the pageForm
  2. inputs get initialized to “init”, “33”
  3. now submit something invalid for both fields like “aa”, “99”
  4. now click any of the “initialize” links again (they all seem to behave the same – makes no difference whether it’s in the same form or different, or whether I have specified execute=”@this” or not.)

Result => UIInput.isValid() = false, both values reset though (“init”, “33”).

Expected => valid = true (or is this not reasonable to expect?)

Behavior #2

  1. click either “Initialize” link on the pageForm
  2. inputs get initialized to “init”, “33”
  3. now submit something invalid for the text field but valid for the int field (“aa”, “44”)
  4. now click any of the “initialize” links again

Result => “init”, valid=false; 44, valid=true

Expected => “init”, valid=true; 33, valid=true

I have also looked at:

JSF 2 – Bean Validation: validation failed -> empty values are replaced with last valid values from managed bean

and

How can I populate a text field using PrimeFaces AJAX after validation errors occur?

The suggestion to explicitly reset the state of UIInputs with resetValue does work, but I’m not happy with it.

Now, I sort of understand why the isValid is not resetting – my understanding of the JSF lifecycle is that once a value is submitted to a component, isValid is not reset until the component is successfully submitted and validated and the Update Model Values phase sets the bean value. So there may be no way around explicitly resetting the valid state in this case, since I want to use #{foo.valid} for conditional CSS styling.

What I don’t understand, though, is why the components that successfully validated are not re-initializing from the bean. Perhaps my understanding of the JSF lifecycle is slightly off?

I understand the rules layed out in the answer to How can I populate a text field using PrimeFaces AJAX after validation errors occur? as they pertain to an individual component but not to the form as a whole – i.e., what happens if a component succeeds validation but the validation overall fails?

  • 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-27T09:42:16+00:00Added an answer on May 27, 2026 at 9:42 am

    In fact, there may turn out to be no better way than explicitly calling resetValue on components. In my case, all of the dialogs are in the same big JSF view tree with the underlying page that opens them. So from JSF’s perspective, the same view component state including invalid input values should be preserved until we navigate away from the view, as it has no visibility into how we’re toggling display attributes client-side.

    The only other thing that might work is if the components that make up the dialog are actually not rendered in the JSF view tree unless they’re visible. In my case, they’re always rendered, using CSS to toggle visibility.

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

Sidebar

Related Questions

Here I want to reset all properties of Data to their original values, how
I want to reset by JSF backing bean when some method is invoked. Assume
I want to reset a textView height after I have added it to the
I want to reset stop word list in mysql for FULLTEXT search. I have
I have a three-dimensional array that I want to reset to zero. It seems
I have multiple input textboxes in my page. I want to reset particular text
How do I reset my numbers after they count? I want something like an
I want to reset the form after calling an ajax function. This is the
I have multiple comment ids I want to reset to a default value. Ex:
I am using jquery-ui tabs ...Actually i want to reset the form fields after

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.