jsf-Managed Beans-Backing Beans

JSF使用 JavaBean 來達到程式邏輯與視圖分離的目的,在JSF中的Bean其角色是屬於Backing Bean,又稱之為Glue Bean,其作用是在真正的業務邏輯Bean及UI元件之間搭起橋樑,在Backing Bean中會呼叫業務邏輯Bean處理使用者的請求,或者是將業務處理結果放置其中,等待UI元件取出當中的值並顯示結果給使用者。




這個例子我們在 第一個JSF程式 看過,<managed-bean-class>設定所要使用的Bean類別,<managed-bean-name>設定之名稱,可供我們在JSF頁面上使用Expression Language來取得或設定Bean的屬性,例如:
<h:inputText value="#{user.name}"/>


<managed-bean-scope>設定Bean的存活範圍,您可以設定為request、session 與application,設定為request時,Bean的存活時間為請求階最,設定為session則在使用者應用程式交互開始,直到關閉瀏覽器或顯式的結束會話為止(例如登出程式),設定為application的話,則Bean會一直存活,直到應用程式關閉為止。




在JSF頁面上要取得Bean的屬性,是使用 JSF表示語言(Expression Language),要注意到的是,JSF表示語言是寫成 #{expression},而 JSP 表示語言 是寫成 ${expression},因為表示層可能是使用JSP,所以必須特別區分,另外要注意的是,JSF的標籤上之屬性設定時,只接受JSF表示語言。





Problem Descriptionn Mr. Pote's shop sells beans now. He has N bags of beans in his warehouse, and he has numbered them with 1, 2, …, N according to their expired dates. The i-th bag contains Wi units of beans. For selling at retail makes only a little profit, Mr. Pote want to pack beans in small packets with certain size and sell them in packets. Here comes his packing way:n Suppose the size of the packet is P units. Firstly, Mr. Pote selects some bags (at least one) of beans with consecutive number in his warehouse. Then he takes out the beans from all selected bags, and puts them together on the desktop. To pack the beans, he take P units of beans from desktop and fill in a new packet each time, until the beans left are less than P units. Finally the beans left on the desktop are eaten by a lucky dog.n Mr. Pote doesn't want the dog eat too many beans, so he prefers to solutions that resulting no more than K units of beans eaten by the dog. Moreover, he also wants to pack as many packets as possible. Could you tell him how many packets he can pack at most without breaking his preference?n nnInputn On the first line of input, there is a single positive integer T <= 20 specifying the number of test cases to follow. n Each test case contains two lines. n There are three integers in the first line, N, P, K as described above. (0 < N, P < 1000001, 0 <= K < P)n Next follow a line with N integers W1, W2, ..., WN. The i-th integers describes the amount of beans in the bags numbered i. (0 <= Wi < 32768)n Numbers are separated by spaces.n nnOutputn For each test case you should output a single line containing "Case X: Y" (quotes for clarity) where X is the number of the test case (starting at 1) and Y is the maximum number of packets that Mr. Pote can pack following his way. n In case there's no solution avoiding the dog eats more than K units of beans, Y should be equal to -1.n nnSample Inputn3n10 20 10n0 3 1 8 19 39 2 9 1 8n3 100 10n32 34 23n1 5 3n1n nnSample OutputnCase 1: 4nCase 2: -1nCase 3: 0