簡體   English   中英

帶會話的基本JSF在Glassfish中不起作用

[英]Basic JSF with Session doesn't work in glassfish

我想在集群環境中測試JSF 2的會話和應用程序范圍的Bean的會話復制,目前正在嘗試使用glassfish。 為此,我創建了一個簡單的應用程序,然后將其首先部署到服務器以驗證其是否正常工作(不是)。

這是我到目前為止所做的:

  1. 在Oracle VirtualBox中設置Ubuntu虛擬機
  2. 將glassfish下載為zip文件並將其解壓縮到主目錄中
  3. 開始玻璃魚
  4. 將JSF-app部署為war文件
  5. 轉到應用程序頁面:localhost:8080 / jsftest / index.jsf
  6. 嘗試設置保存在會話/應用程序范圍內的變量

取決於web.xml中的javax.faces.STATE_SAVING_METHOD,結果為:

  • 服務器:拋出viewExpiredException
  • 客戶端:未存儲值,並顯示默認值

要創建該應用程序,我執行了以下操作:

  1. 在Eclipse中創建新的動態Web項目
  2. 從WEB-INF / lib中的myfaces核心解壓縮所有文件
  3. 將classes-folder設置為WEB-INF / classes
  4. 如下所示編寫bean和一個.xhtml

會話作用域bean(應用程序作用域類似):

@ManagedBean(name = "sessbean")
@SessionScoped
public class MySessionScopeBean implements Serializable{
private static final long serialVersionUID = -4733271400646173098L;
private String value = "default session data";

public String getValue() {
    return value;
}

public void setValue(String value) {
    this.value = value;
}

}

index.xhtml:

<?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:f="http://java.sun.com/jsf/core"      
  xmlns:h="http://java.sun.com/jsf/html">

<h:head>
    <title>JSF 2.0 Hello World</title>
</h:head>
<h:body>
    <h3>JSF 2.0 Hello World Example - hello.xhtml</h3>
    <h:outputText value="Session id: #{sessionScope['id']}" />
    <h:form>
        <h:panelGroup>
            <h:outputText value="Session Variable:"/>
            <br/>
            <h:inputText value="#{sessbean.value}"/>
        </h:panelGroup>
        <h:commandButton value="submit"/>
    </h:form>
    <h:form>
        <h:panelGroup>
            <h:outputText value="Application Variable:"/>
            <br/>
            <h:inputText value="#{appbean.value}"/>
        </h:panelGroup>
        <h:commandButton value="submit"/>
    </h:form>
</h:body>
</html>

因此,這個非常基本的示例不起作用。 有什么建議么?

另外,會話ID不會顯示在#{sessionScope ['id']}中,不知道這是否是這樣做的方法。

通過刪除(生成的)web.xml文件的一部分使它正常工作。 工作文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>jsftest</display-name>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>
</web-app>

我剝離的內容(不知道是哪個部分導致了故障):

  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <description>
    This parameter tells MyFaces if javascript code should be allowed in
    the rendered HTML output.
    If javascript is allowed, command_link anchors will have javascript code
    that submits the corresponding form.
    If javascript is not allowed, the state saving info and nested parameters
    will be added as url parameters.
    Default is 'true'</description>
    <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <description>
    If true, rendered HTML code will be formatted, so that it is 'human-readable'
    i.e. additional line separators and whitespace will be written, that do not
    influence the HTML code.
    Default is 'true'</description>
    <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <description>
    If true, a javascript function will be rendered that is able to restore the
    former vertical scroll on every request. Convenient feature if you have pages
    with long lists and you do not want the browser page to always jump to the top
    if you trigger a link or button action that stays on the same page.
    Default is 'false'
</description>
    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
    <param-value>true</param-value>
  </context-param>
  <listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
  </listener>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM