gpt4 book ai didi

jsf-2 - 在页面加载时开始对话

转载 作者:行者123 更新时间:2023-12-01 01:27:39 25 4
gpt4 key购买 nike

我是 Java EE 6 的初学者,最近在玩对话。在加载 JSF 页面(如在 Seam 中)时,我无法找到如何立即开始对话。这是可行的吗?

最佳答案

这是可行的。

页:

<?xml version='1.0' encoding='UTF-8' ?>
<!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://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<f:view contentType="text/html">
<f:metadata>
<f:event type="preRenderView" listener="#{myBean.preRenderView}"/>
</f:metadata>
<h:head>
<title>My Page</title>
</h:head>
<h:body>
<!-- Body here -->
</h:body>
</f:view>
</html>

bean 角,扁 bean :
import java.io.Serializable;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
import javax.inject.Named;

@Named
@ConversationScoped
public class MyBean implements Serializable {
public void preRenderView(ComponentSystemEvent e) {
String currentViewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
if (CONVERSATION_START_PAGE.equals(currentViewId)) {
conversation.begin();
}

@Inject
private Conversation conversation;

private static final String CONVERSATION_START_PAGE = "/foo/bar/start-page.xhtml";
}

关于jsf-2 - 在页面加载时开始对话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6699849/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com