我正在通過oracle中的Java EE 7的tutorial。第一次訪問bean如何?
下面是一個簡單的表格,在輸入框中獲取用戶名:
<h:body>
<h:form>
<h:graphicImage url="#{resource['images:duke.waving.gif']}"
alt="Duke waving his hand"/>
<h2>Hello, my name is Duke. What's yours?</h2>
<h:inputText id="username"
title="My name is: "
value="#{hello.name}"
required="true"
requiredMessage="Error: A name is required."
maxlength="25" />
<p></p>
<h:commandButton id="submit" value="Submit" action="response">
</h:commandButton>
<h:commandButton id="reset" value="Reset" type="reset">
</h:commandButton>
</h:form>
我看到value="#{hello.name}"
在代碼中使用。這條線做什麼?
這就是在tutorial link提到:
該網頁連接至你好通過表達式語言(EL)值表達式#{} hello.name,其中檢索名稱的值託管bean來自託管bean的屬性。
Q1)但第一次載入表單時,沒有名稱屬性附加到hello bean。所以應該返回null應該返回正確?
Q2)其次,輸入框中輸入的值如何綁定到hello bean的name屬性?
實際上,在表單提交後,頁面被重定向到「response.xhtml」,其中hello bean的名稱屬性的值以相同的方式獲取,例如。
從II到III,瀏覽器重定向是相同的請求o提出不同的要求。因爲當第一個請求中設置'#{hello.name}'並且在重定向之後,該bean可以爲空,因爲它是'@ requestscoped' – 2014-10-08 21:31:55
從II到III沒有重定向,但是轉發;我編輯了答案。 – n1k1ch 2014-10-08 22:18:30
這有幫助!謝謝 – 2014-10-08 22:21:22