jsf.ajax.request: Method must be called within a form

--Environment - CentOS Linux release 7.8.2003 (Core) - Eclipse IDE for Enterprise Java Developers.Version: 2020-03 (4.15.0) - openjdk version "11.0.7" 2020-04-14 LTS - JSF 2.3.9

Event: I got angry when I executed the process using f: ajax

When I thought something didn't work, there was an error in the Chrome development tool Console.

Error in Console of Chrome development tool


jsf.js.jsf?ln=javax.faces:1 Uncaught Error: jsf.ajax.request: Method must be called within a form
    at Object.request (jsf.js.jsf?ln=javax.faces:1)
    at Object.ab (jsf.js.jsf?ln=javax.faces:1)
    at HTMLInputElement.onclick (upload.jsf:12)

Cause: Because there is no form tag

I inadvertently forgot the form tag.

xhtml


<body>
<!--abridgement-->
    <h:commandButton value="close" action="#{uploadBean.close}">
      <f:ajax onevent="windowClose" />
    </h:commandButton>
  </div>
</body>

Output html


<input id="j_idt11:j_idt14" type="submit" name="j_idt11:j_idt14" value="close" onclick="mojarra.ab(this,event,'action',0,0,{'onevent':windowClose});return false">

Correspondence: Place f: ajax inside the form tag

xhtml


<body>
  <h:form>
<!--abridgement-->
      <h:commandButton value="close" action="#{uploadBean.close}">
        <f:ajax onevent="windowClose" />
      </h:commandButton>
    </div>
  </h:form>
</body>

Recommended Posts

jsf.ajax.request: Method must be called within a form
jsf.ajax.request: Method must be called within a form
[Java] Protected methods cannot always be called from within a subclass