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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:06:47+00:00 2026-05-26T22:06:47+00:00

I want to validate, before submitting the form, if the h:selectOneMenu and t:inputFileUpload have

  • 0

I want to validate, before submitting the form, if the h:selectOneMenu and t:inputFileUpload have a valid value. I have this code but it does not show the h:message when I leave the selectOneMenu, the same thing happens with t:fileInputUpload.

            <h:form id="uploadForm" enctype="multipart/form-data">
                <h:panelGrid columns="3">
                    <h:outputLabel for="option" value="Operación:" />
                    <h:selectOneMenu id="option" value="#{menu.infoMenuItem}"
                                     required="true"
                                     converterMessage="Opción no valida !" >
                        <f:selectItem itemLabel="Seleccione una opcion..." itemValue="null"/>
                        <f:selectItems value="#{menu.infoMenuItems}" />
                        <f:ajax event="blur" render="optionMessage" />
                    </h:selectOneMenu>
                    <h:message id="optionMessage" for="option" style="color: #FF0000;" />

                    <h:outputLabel for="upfile" value="Archivo: " />
                    <t:inputFileUpload id="upfile" value="#{uploadFile.upFile}"
                                       required="true">
                        <f:ajax event="blur" render="uploadMessage" />
                    </t:inputFileUpload>
                    <h:message id="uploadMessage" for="upfile" style="color: #FF0000" />

                    <h:panelGroup />
                    <h:commandButton value="Continuar"
                                     action="#{uploadFile.upload}">
                    </h:commandButton>
                </h:panelGrid>
            </h:form>

and also, is there a way to prevent the form to be submitted if the previous components don’t have valid values?

Cheers !

I’m using Mojarra 2.1.4 and Tomahawk 1.1.11 (for upload)

  • 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-26T22:06:48+00:00Added an answer on May 26, 2026 at 10:06 pm

    it does not show the h:message when I leave the selectOneMenu

    The code which is posted so far looks fine. The problem is caused elsewhere. Perhaps you’re nesting HTML <form>s, which is invalid. Make sure that you don’t nest JSF <h:form> components. For other causes, see also commandButton/commandLink/ajax action/listener method not invoked or input value not updated.


    the same thing happens with t:fileInputUpload.

    Unfortunately, the HTML4 <input type="file"> element and XHR1 ajax don’t play very well together. Determining whether a file is selected requires a multipart/form-data ajax request, which is only supported in HTML5/XHR2 (as far now, PrimeFaces 3.0 is the only JSF component library which supports this -in theory! I haven’t tested it). So the ajax validation request is totally ignored by <t:inputFileUpload>. Since JSF/Tomahawk is just a HTML code generator, it can’t do any much for you here. Best what you can do is to validate it by plain vanilla JS/HTML.

    <t:inputFileUpload id="upfile" value="#{bean.file}" required="true" 
        onblur="document.getElementById('uploadMessage').style.display = (!value) ? 'block' : 'none'"
    />
    <h:panelGroup>
        <h:message for="uploadMessage" style="color: #FF0000" />
        <span id="uploadMessage" style="display: none; color: #FF0000">Seleccione una archivo...</span>
    </h:panelGroup>
    

    (the <h:message> is kept in place so that the server side validation message will be shown anyway whenever you press the command button -which fires a synchronous (non-ajax) request)


    Unrelated to the concrete problem, you should prefer putting JS and CSS code in its own .js and .css files which you include by <script> and <link> in <h:head>.

    • 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 want to validate before the user is able
I want to validate few inputs before submiting the form, i am doing this
i have a form which i want to be validated with javascript before submitting.
I want to validate a condition before doing the next step, but only raise
I have a form that I want to be validated before showing it initially.
I have a class Employee. I want to be able to Validate() it before
Hi I want to validate the field values before submit the form here is
I have a form like this below: <form id=gb> <div><input type=text name=a value= /></div>
I want to validate the data contained by Value Objects before inserting into the
I want to validate a System.DateTime value before I add it as a parameter

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.