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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:45:32+00:00 2026-06-13T13:45:32+00:00

i have a form with some inputs that have validation (required=true) and when i

  • 0

i have a form with some inputs that have validation (required=true)
and when i click on the cancel button in case of validation error, the cancel button doesn’t navigate to previous page, instead it removes the validation error (i think it goes back one step that was before the validation error ?)

here’s my code:

<h:form>

<h:inputText value="#{myBean.nickName}" id="nickname" required="true"
requiredMessage="nickname should be specified" />

<h:commandLink immediate="true" id="cancel_link" onclick="history.back(); return false" style="float: left;margin: 118px 189px 0 0;">
 <h:graphicImage width="90" height="28" value="#{resource['images:blu_btnCancel.png']}" />
</h:commandLink>

</h:form>

please advise how to fix that.

  • 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-13T13:45:33+00:00Added an answer on June 13, 2026 at 1:45 pm

    The JavaScript history.back() function takes you to the previous synchronous request, not to the previous view as you seemed to expect.

    Even though the history.back() is terrible this way (unreliable, hackable, etc), a quick fix would be to send an ajax request on form submit instead of a synchronous request.

    <h:form>
        ...
        <h:commandButton value="submit">
            <f:ajax execute="@form" render="@form" />
        </h:commandButton>
    </h:form>
    

    Ajax requests doesn’t account as browser history.

    A more robust way is to just pass the identifier of the previous view along during navigation and then use <h:link> to link back to it. E.g.

    <h:link value="Go to next view" outcome="nextview">
        <f:param name="from" value="#{view.viewId}" />
    <h:link>
    

    And then in the nextview.xhtml

    <f:metadata>
        <f:viewParam name="from" />
    </f:metadata>
    
    ...
    
    <h:link ... outcome="#{from}" rendered="#{not empty from}">
        <h:graphicImage ... />
    </h:link>
    

    If you’re navigating by POST, you might consider using the flash scope to remember the initial view.


    Unrelated to the concrete problem, the proper way to use <h:graphicImage> with JSF2 resources is to just use its name attribute instead of its value attribute with a #{resource} which is plain clumsy.

    Replace

    <h:graphicImage width="90" height="28" value="#{resource['images:blu_btnCancel.png']}" />
    

    by

    <h:graphicImage name="images/blu_btnCancel.png" width="90" height="28" />
    

    Note that the library name images is here just replaced by the path name. The usage of the name “images” as library name is highly questionable. See also What is the JSF resource library for and how should it be used?

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

Sidebar

Related Questions

I have a form that I'm trying to run some basic validation on using
So I have a form that accepts some input from a user that may
I have to escape some inputs on a form. I used mysql_real_escape_string to escape
I have an AngularJS page with several form inputs. When the some of the
I have a form inside a dialog that appears after clicking in another button.
I am doing some basic form validation. I have the following JavaScript function: function
So I have form with 1 fields that need to be required <h:form id=form>
I have a form with multiple fields that I'm validating (some with methods added
I have 4 buttons on my form, a Submit, Cancel, Add and Remove button.
I have a form that is using the jQuery validate functionality, with some custom

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.