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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:55:45+00:00 2026-05-25T09:55:45+00:00

Update: Updated once more now. I think my previous analysis was wrong, because I

  • 0

Update: Updated once more now. I think my previous analysis was wrong, because I have now been able to create an example for this. It appears to be related to composite components and the insertChildren tag.

Here is my facelet:

<?xml version='1.0' encoding='UTF-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:form="http://java.sun.com/jsf/composite/composite/form"
    xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head></h:head>

<h:body>
        <h:form>
        <form:workspace>

            <h:inputText id="email" value="#{user.email}" size="45"
                required="true" requiredMessage="Required">
                <f:validateRegex pattern="([^.@]+)(\.[^.@]+)*@([^.@]+\.)+([^.@]+)" />
            </h:inputText>
            <h:message for="email" />
            <br />
            <h:commandButton action="#{user.update}" value="Update"/>

        </form:workspace>
        </h:form>
</h:body>
</html>

The form:workspace composite component is defined as follows:

<?xml version='1.0' encoding='UTF-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:cc="http://java.sun.com/jsf/composite">

<cc:interface>
</cc:interface>

<cc:implementation>
    <cc:insertChildren/>
</cc:implementation>
</html>

The #{user} variable refers to a trivial bean with just a field called email and a getter and a setter. The update method does nothing.

The behavior I get is as described below. When I enter an invalid value, it is reverted back to what it is stored in the bean. If I remove the wrapping by the form:workspace component, it works like I expect – the value is not reverted. JSF bug?


I have a JSF form with a number of input components. Some of these have validators attached to them. For example, a simple one is the e-mail address, which is mandatory:

<h:inputText id="email" value="#{profile.user.email}" size="45"
  required="true" requiredMessage="Required">

Now, we have received a requirement that fields that are invalid should keep the submitted value in them, so the user does not have retype a lot of text for simple spelling mistakes. This seems very reasonable to me, and I even expected this to be the default behavior of validation. But it doesn’t seem to be – the value is reverted back to what it was before (when it was still valid).

The problem is, I cannot even find a reference for what the behavior should be. I read somewhere that it’s the local value of the UIInput that is displayed after validation. Inspecting the code of UIInput tells me that local value is intentionally not set if validation fails. But this does not seem to be the whole truth, because ALL input fields are reverted – not just the ones for which validation failed! So it looks more like it gets the values from the model again.

In any event, is there a way I circumvent this behavior?

I am using JSF 2.0.4-b09. I feel like I am missing something obvious.

Edit: I changed the e-mail validator to the regexp one BalusC posted below, and I still get the same behavior. I posted an image illustrating the problem. The upper part of the image shows the initial state of the form. Then the middle part shows that I change the fields “First name”, “Last name” and “Email”. The bottom part shows the result after I click the save button. As you can see, the e-mail field is reverted. Not only that, the first name and last name fields are also reverted.

Problem illustrated in three steps.

  • 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-25T09:55:45+00:00Added an answer on May 25, 2026 at 9:55 am

    There’s some confusion going on. The value is only reverted back to the initial value when the submitted value is empty (i.e. the user removed the initial value or just entered nothing). I’m not sure how the problem of having to retype the whole text is related to this as actually nothing has been entered.

    When the submitted value is empty or null, JSF will just redisplay the model value, else it will redisplay the submitted value, exactly as you’d expect. This is specified in JSF specification. To see it yourself, add for example

    <f:validateRegex pattern="([^.@]+)(\\.[^.@]+)*@([^.@]+\\.)+([^.@]+)" />
    

    to the email input field. You’ll see that any non-empty(!) submitted value is retained in case of invalid email formats.


    Update: as per your update it turns out that your input components are actually been rendered by <cc:insertChildren>. This behaviour is indeed a bug in Mojarra. See issue 1991. As mentioned in the issue ticket, the workaround is to put the <cc:insertChildren /> inside a <h:panelGroup> or an <ui:fragment>.

    <cc:implementation>
        <ui:fragment>        
           <cc:insertChildren/>        
        </ui:fragment>
    </cc:implementation>
    

    MyFaces 2.1.1 doesn’t have this bug and it works fine over there.

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

Sidebar

Related Questions

Here's some code I saw once. Can you see what's wrong with it? [updated]
[Update]: my initial example doesn't reflect my problem. Updated the sample, hopfully it is
I have a table which is updated with ajax and after update it if
Ooops, fiddle updated now correct In this fiddle, http://jsfiddle.net/SySRb/118/ once you click .start an
Our application uses a large product database that is updated once a day. Updates
During a complicated update I might prefer to display all the changes at once.
I know of a lot of programs that once installed (or an update to
UPDATE - A comprehensive comparison, updated as of February 2015, can be found here:
Update: This turned into a blog post, with updated links and code, over at
UPDATED I have made the changes to the C# code so it uses a

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.