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>
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)
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