문제

통조림 데이터를 표시하는 매우 간단한 페이지가 있습니다. DB의 데이터 로이 문제를 경험 했으므로이 간단한 예를 들었고 여전히 문제가 있습니다. 이 페이지가 세션을 처음으로 탐색 할 때 첫 번째 행의 첫 번째 열에는 데이터가 표시되지 않습니다.

요청 또는 세션으로 범위를 변경해도 문제가되지 않으며 Firefox 또는 IE를 사용하는 경우 차이가 없습니다. 내가 아는 것은 페이지를 다시로드하거나 탐색하고 다시 돌아 오면 갑자기 내 데이터를 보여줄 것입니다. 해당 브라우저의 모든 인스턴스를 닫고 새 브라우저를로드 할 때까지 데이터가 표시됩니다. 그런 다음 다시 페이지를 다시로드 할 때까지 내 데이터가 표시되지 않습니다.

문제는 왜 내 첫 번째 책의 첫 번째 제목이 페이지를 다시로드 할 때까지 나타나지 않는 이유입니다 ( "운영 체제 개념"은 표시되지 않지만 "Silberschatz")?

아래는 관련 코드입니다.

Homepage.java :

public class HomePage {

    private Book[] books;

    public HomePage() {
        books = new Book[3];
        books[0] = new Book("Operating System Concepts", "Silberschatz");
        books[1] = new Book("Learning Sql", "Beaulieu");
        books[2] = new Book("Effective Java", "Bloch");
    }

    public Book[] getBooks() {
        return books;
    }
    public void setBooks(Book[] books) {
        this.books = books;
    }
}

BOOK.java

public class Book {

    private String title;
    private String author;

    public Book() {}

    public Book(String title, String author) {
        this.title = title;
        this.author = author;
    }


    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
}

home.jsp :

<html>
  <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
  <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

  <link href="../css/styles.css" rel="stylesheet" type="text/css" />
  <f:loadBundle basename="omitted.for.anonymity.bundle.home" var="msgs"/>

  <f:view>
    <body>
      <h:form>
        <h:panelGrid columns="2" columnClasses="sideControlColumn,contentColumn">
          <f:facet name="header">
            <f:subview id="header">
              <jsp:include page="header.jsp" />
            </f:subview>
          </f:facet>

          <f:subview id="sideControl" >
            <jsp:include page="sideControl.jsp" />
          </f:subview>

          <h:dataTable value="#{homePage.books}"
                var="book"
                styleClass="homeTable"
                rowClasses="evenColumn,oddColumn"
                >

            <h:column>
              <f:facet name="header">
                <h:outputText value="#{msgs.columnHeader1}"/>
              </f:facet>

              <h:outputText value="#{book.title}" />
            </h:column>

            <h:column>
              <f:facet name="header">
                <h:outputText value="#{msgs.columnHeader2}"/>
              </f:facet>

              <h:outputText value="#{book.author}" />
            </h:column>

          </h:dataTable>

        </h:panelGrid>
      </h:form>
    </body>
     </f:view>
</html>

faces-config.xml :

<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
    "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
    "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<faces-config>

    <navigation-rule>
    <from-view-id>/pages/login.jsp</from-view-id>
        <navigation-case>
            <from-outcome>login</from-outcome>
            <to-view-id>/pages/home.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>

    <navigation-rule>
    <from-view-id>/pages/home.jsp</from-view-id>
        <navigation-case>
            <from-outcome>searchForBooks</from-outcome>
            <to-view-id>/pages/searchCriteria.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>

    <navigation-rule>
    <from-view-id>/pages/searchCriteria.jsp</from-view-id>
        <navigation-case>
            <from-outcome>searchForBooks</from-outcome>
            <to-view-id>/pages/searchCriteria.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>

    <navigation-rule>
    <from-view-id>/pages/searchResults.jsp</from-view-id>
        <navigation-case>
            <from-outcome>searchForBooks</from-outcome>
            <to-view-id>/pages/searchCriteria.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>

    <navigation-rule>
    <from-view-id>/pages/searchCriteria.jsp</from-view-id>
        <navigation-case>
            <from-outcome>search</from-outcome>
            <to-view-id>/pages/searchResults.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>


    <managed-bean>
        <managed-bean-name>book</managed-bean-name>
        <managed-bean-class>omitted.for.anonymity.beans.Book</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    <managed-bean>
        <managed-bean-name>homePage</managed-bean-name>
        <managed-bean-class>omitted.for.anonymity.beans.page.HomePage</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    <managed-bean>
        <managed-bean-name>searchCriteriaPage</managed-bean-name>
        <managed-bean-class>omitted.for.anonymity.beans.page.SearchCriteriaPage</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    <managed-bean>
        <managed-bean-name>searchResultsPage</managed-bean-name>
        <managed-bean-class>omitted.for.anonymity.beans.page.SearchResultsPage</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>

</faces-config>
도움이 되었습니까?

해결책

설정하는 테이블 a book 요청 범위 변수 :

<h:dataTable value="#{homePage.books}"
    var="book"
    styleClass="homeTable"
    rowClasses="evenColumn,oddColumn">

a book 세션 범위 변수 :

<managed-bean>
    <managed-bean-name>book</managed-bean-name>
    <managed-bean-class>omitted.for.anonymity.beans.Book</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

그냥 추측하지만, 표현 언어가 어떤 이유로 세션 콩을 해결하고 있는지 궁금합니다. 그것은 아니어야합니다 - scopedattributeelresolver "주어진 이름이있는 속성에 대한 페이지, 요청, 세션 및 응용 프로그램 범위를 검색하고 반환하거나 현재 이름에 속성이없는 경우 NULL을 검색합니다." 그러나 표현 언어 구현에 버그가있을 가능성은 없습니다. 이름을 변경하십시오 var 충돌을 피하거나 사용하는 범위로 명시 적으로 해결하기위한 속성 #{requestScope.book.title}.

<!DOCTYPE faces-config PUBLIC
  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
  "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

DocType에서 JSF 1.1을 사용하고 있음을 알 수 있습니다. 가능하면 최소 1.2 (바람직하게는 2.0)로 업그레이드하는 것이 좋습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top