What to do if FacesMessage is set but not displayed

Event: The message is not displayed even though FacesMessage is set as the content.

Execute the method with ajax


  <h:form id="formId">
    <div id="uploadArea">
<!--...abridgement...-->
          <f:ajax event="change" execute="uploadArea" render="uploadArea" listener="#{uploadBean.uploadFile}" />
<!--...abridgement...-->
      <div>
        <h:message for="uploadArea" errorClass="error" warnClass="warn" infoClass="info" />
      </div>
    </div>
  </h:form>

I set a message as content in a method, but it doesn't appear


    public void uploadFile(AjaxBehaviorEvent event) throws IOException {
        if (!isUpload()) {
            FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "", "The file was not selected.");
            event.getFacesContext().addMessage("uploadArea", message);
//...abridgement...

Output HTML


<form id="formId" name="formId" method="post" action="/tryJsf/base.jsf" enctype="application/x-www-form-urlencoded">
  <input type="hidden" name="formId" value="formId">
  <div id="uploadArea">
<!--...abridgement...-->
    <input id="formId:file" type="text" name="formId:file" style="display:none;" onchange="mojarra.ab(this,event,'change','uploadArea','uploadArea')">
    <div>
    </div>
  </div>
  <input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="-7689768516583343150:2206148480801750608" autocomplete="off">
</form>

Cause: Unknown (Please tell me.)

Apparently it didn't reappear after the f: ajax method was executed. render =" uploadArea " ... was ignored? Is HTML tag useless? Shouldn't it be a JSF tag? Isn't a component not written with JSF tags?

The clientIds of components that will participate in the "render" portion of the Request Processing Lifecycle. ajax(JSF 2.2 View Declaration Language: Facelets Variant)

Workaround: Change the div tag to h: panelGroup

Execute the method with ajax


  <h:form id="formId">
    <h:panelGroup id="uploadArea">
<!--...abridgement...Since I made it a JSF tag, make it an id attribute to specify..-->
          <f:ajax event="change" execute="formId:uploadArea" render="formId:uploadArea" listener="#{uploadBean.uploadFile}" />
<!--...abridgement...-->
      <div>
        <h:message for="formId:uploadArea" errorClass="error" warnClass="warn" infoClass="info" />
      </div>
    </div>
  </h:form>

It was displayed when I set the message as content in the method


    public void uploadFile(AjaxBehaviorEvent event) throws IOException {
//...abridgement...Same as before correspondence...Change only the specified id attribute...
            event.getFacesContext().addMessage("formId:uploadArea", message);
//...abridgement...Same as before correspondence...

Recommended Posts

What to do if FacesMessage is set but not displayed
[Swift] What to do if the app icon is set but not reflected
What to do if audio is not available on discordrb
[Ubuntu 20.04] What to do if the external monitor is not recognized
[Rails] What to do if data is not registered in DB
What to do if the background image is not applied after deployment
What to do if the prefix c is not bound in JSP
What to do if Operation not permitted is displayed when you execute a command in the terminal
What to do if the breakpoint is shaded and does not stop during debugging
What to do if you installed Ruby with rbenv but the version does not change
What to do if Cloud9 is full in the Rails tutorial
What to do if the Eclipse Maven dependency Jar is wrong
[Logback] What to do if unnecessary files do not disappear during rotation
What to do if you install Ubuntu
[Spring Boot] What to do if an HttpMediaTypeNotAcceptableException occurs on an endpoint for which produces is set
[Note] What to do if bundle install in Chapter 3 of the rails tutorial is not possible
[Java] What to do if a lot of "File is opened too much" is displayed due to FileNotFoundException
What to do if the app is not created with the latest Rails version installed when rails new
What to do when javax.el.ELException: Not a Valid Method Expression: appears when the JSF screen is displayed
What to do when "npm ERR! Code ENOSELF" is displayed after npm install
What to do if deployment fails on Heroku (Ruby app not detected)
Notes on what to do when EC2 is set up with t2.micro
What to do if tomcat process remains when tomcat is stopped in eclipse
What to do if the server tomcat dies
What to do if you push incorrect information
What to do if mvn archetype: generate fails
What to do when debugging "Source not found"
What to do if you get a SQLite3 :: BusyException: database is locked error
What to do if the changes are not reflected in the jar manifest file
What to do when is invalid because it does not start with a'-'
[Rails] What to do when the Refile image is not displayed when writing the processing at the time of Routing Error
What to do if the debug gem installation fails
What to do if the Rails server can't start
What to do when JSF tags do not become HTML
What to do if ClassNotFoundException occurs when starting Tomcat
What to do if rails server can't be stopped
What to do if TextToSpeech doesn't work on Android 11
What to do if you accidentally create a model
What to do if an ActionController :: UnknownFormat error occurs
What to do if password authentication fails in Docker/Postgres
ParseException: What to do when Unparseable date is reached
What to do if the update does not take effect after deploying Rails AWS
What to do when "Fail to load the JNI shared library" is displayed in Eclipse
What to do when Address already in use is displayed after executing rails s
What to do if the JSONHint annotation does not work with lombok and JSONIC
What to do if you get a java.io.IOException in GlassFish
What to do when Method not found in f: ajax
# What to do if you accidentally do rails db: migrate: drop
[Maven] What to do if you are asked to incorporate a jar that is not in the remote repository into the war
I want to Flash Attribute in Spring even if I set a reverse proxy! (do not do)
[Swift5] What to do if you want to commit files to github but there are too many
Introduction to Ratpack (1) --What is Ratpack?
What to do if the adb command cannot be executed
What to do if mysql2 gets a bundle install error
[Rails] fields_for is not displayed
[Rails] What to do when the view collapses when a message is displayed with the errors method
What to do if you can't use the rails command
What to do about the "cannot be read or is not a valid ZIP file" error
What to do if you get "Changes not staged for commit:" when you git status after git add.
What to do if you get a gcc error in Docker
What to do if validation doesn't work with the update action