あるページから別のページに変更すると、奇妙な動作が見つかりました。
CDI、Jsf 2.2 API 2.2.8、Omnifaces 2.2、Primefaces 5.2、wildfly 8.2 を使用しています。
ほとんどのコントローラーとページは期待どおりに動作しますが、ページにアクセスすると @PostConstruct メソッドが呼び出され、ページを離れると @PostConstruct が再度呼び出されるものもあります。page.xhtml の何かに原因があることに気がついたので、探し始めました。しかし、とにかく奇妙な動作です。
私のコードといくつかの例に従ってください:
beginconversation() や list() などの抽象クラスメソッドを使用するコントローラー
import javax.inject.Named;
import javax.enterprise.context.ConversationScoped;
@Named
@ConversationScoped
public class PromptConfigurationController extends BaseController<PromptConfiguration> implements Serializable {
public PromptConfigurationController() {
super(PromptConfiguration.class);
}
@PostConstruct
public void init() {
list();
loadFilters();
}
}
抽象クラス
public abstract class BaseController<T extends BaseEntity> {
public void list() {
logger.info("list()");
items = getService().findAll(entityClass);
item = null;
beginConversation();
}
protected void beginConversation() {
logger.info("beginConversation()");
if (conversation != null && conversation.isTransient()) {
conversation.begin();
conversation.setTimeout(CONVERSATION_TIMEOUT);
logger.info("Conversation iniciada: " + conversation.getId());
}
}
}
問題を見つけたいくつかのxhtmlページと解決策(見つけたとき)は次のとおりです。
エラー:
<f:convertDateTime pattern="#{webChatSearchController.dateHelper.getLocalizedDatePattern()}" />
上記のメソッドはパターンを返すだけです。
働く
<f:convertDateTime dateStyle="dd/MM/yyyy" pattern="dd/MM/yyyy" />
エラー:
<p:commandButton id="commandButton-active" action="#{satisfactionSurveyController.changeQuestionStatus(true)}" update="form-content" binding="#{satisfactionSurveyController.activeButton}" value="#{bundle['common.active.3.message']}">
働く:
<p:commandButton id="commandButton-active" action="#{satisfactionSurveyController.changeQuestionStatus(true)}" update="form-content" value="#{bundle['common.active.3.message']}" disabled="#{satisfactionSurveyController.disableActiveButton}">
問題はまさに「バインディング」でした。
エラー:
<p:dataTable id="dataTable-group-email" var="emailMonitor" value="#{emailMonitorController.listEmailGroup}" selectionMode="single" rowKey="#{emailMonitor}" filteredValue="#{emailMonitorController.listEmailGroupFiltered}">
働く:
<p:dataTable id="dataTable-group-email" var="emailMonitor" value="#{emailMonitorController.listEmailGroup}" selectionMode="single" rowKey="#{emailMonitor}" >
「filteredValue」を削除するだけで機能し始めました。しかし、それがなければ、フィルター プロパティを使用できません。
ナビゲーションはプライムフェイスのメニューによって行われ、すべてのページは同じロジックです:
<p:menuitem id="satisfactionSurvey" action="#{satisfactionSurveyController.listPage}" value="#{bundle[satisfactionSurvey.message']}" ajax="false" immediate="true">
<f:param name="nocid" value="true" />
</p:menuitem>
そして方法:
public String listPage() {
return baseViewPath + "/list.xhtml?faces-redirect=true";
}