ここ数日、解決できない問題に悩まされています。で使用Mojarra 2.2.12
していWildfly 10
ます。
私の問題は、f:ajax
タグ内でタグh:inputFile
を使用し、コンポーネントの ID、、、、またはその他を使用してコンポーネントを再レンダリングしようとすると@form
、@all
何も再レンダリングされないことです。これまで。ただし、h:commandButton
または他のコンポーネント内ではまったく問題なく動作します。
簡単な例を次に示します。
というxhtml
ファイルがありますindex.xhtml
。このファイルには、、、および が含まれてh:message
いh:inputFile
ますh:commandButton
。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
<h:form id="test" enctype="multipart/form-data">
<h:message for="test" />
<br />
<h:inputFile value="#{uploadController.uploadedFile}">
<f:ajax render=":test" />
</h:inputFile>
<h:commandButton value="Push me!"
action="#{uploadController.buttonPushed}">
<f:ajax render=":test" />
</h:commandButton>
</h:form>
</h:body>
</html>
ManagedBean
と呼ばれるクラスもあります。これは、アクションが発生するとメッセージをログに記録し、フォームが再レンダリングされるとタグUploadController
内にメッセージを表示することになっています。h:message
@ManagedBean
@ViewScoped
public class UploadController {
private Part uploadedFile;
public Part getUploadedFile() {
return uploadedFile;
}
public void setUploadedFile(Part uploadedFile) {
this.uploadedFile = uploadedFile;
System.out.println("File Uploaded!");
FacesContext.getCurrentInstance().addMessage("test", new FacesMessage("File Uploaded!"));
}
public void buttonPushed()
{
System.out.println("Button pushed!");
FacesContext.getCurrentInstance().addMessage("test", new FacesMessage("Button Pushed!"));
}
}
期待される結果は、ファイルを選択すると、ファイルが「アップロード」され、「ファイルがアップロードされました!」と表示されることです。一度ajaxがh:message
ページを再レンダリングします。ボタンを押すと「Button Pushed!」と表示されます。同じでh:message
。
実際の結果は、はい、「ファイルがアップロードされました」です。コンソールに出力されますが、ページは再レンダリングされず、メッセージは表示されません。一方、ボタンは完全に機能し、メッセージは本来のように表示されます。
ここからどうすればいいのか全くわかりません。私はJSFの初心者です。ajax が 内で再レンダリングされないのに、h:inputFile
では完全に正常に動作するのはh:commandButton
なぜですか? これはバグですか?ページを更新せずに目的の結果を得るにはどうすればよいですか?