JSF JSF Lifecycle

Manuba

Mitglied
Ich habe ein Verständnisproblem bei der Beschreibung des JSF Ablaufs bei einem Request. In der Oracle Dokumentation steht folgendes:
Apply Request Values Phase
After the component tree is restored, each component in the tree extracts its new value from the request parameters by using its decode method. The value is then stored locally on the component. If the conversion of the value fails, an error message associated with the component is generated and queued on FacesContext. This message will be displayed during the render response phase, along with any validation errors resulting from the process validations phase.

In the case of the userNo component on the greeting.jsp page, the value is whatever the user entered in the field. Because the object property bound to the component has an Integer type, the JavaServer Faces implementation converts the value from a String to an Integer.
Update Model Values Phase
After the JavaServer Faces implementation determines that the data is valid, it can walk the component tree and set the corresponding server-side object properties to the components’ local values. The JavaServer Faces implementation will update only the bean properties pointed at by an input component’s value attribute. If the local data cannot be converted to the types specified by the bean properties, the life cycle advances directly to the render response phase so that the page is re-rendered with errors displayed. This is similar to what happens with validation errors.
Sowohl im Schritt "Apply Request Values Phase" als auch im späteren Schritt "Update Model Values Phase" wird eine Fehlermeldung ausgegeben, falls ein Wert nicht korrekt Konvertiert werden kann (in dem verwendeten Beispiel von String nach int).
  1. Wenn schon ein Fehler im erstgenannten Schritt auftaucht, wie kann es dann in dem darauf folgenden Schritt wieder zu demselben Fehler kommen?
  2. Warum wird zweimal Konvertiert?
  3. Und woher weiß die Anwendung im Schritt "Apply Request Values Phase" von welchem Datentyp die Backing Bean Property ist, wenn doch erst im darauffolgenden Schritt eine Verbindung zur Backing Bean hergestellt wird?
 

stg

Top Contributor
In ApplyRequest wird der Input-Componente der im Request übergebene Wert zugewiesen. Aus dem Request bekommst du einen String, in der Komponente hast du irgendein Object. Hier wird irgendwann/wo setSubmittedValue() auf der Komponente aufgerufen.
In UpdateModel wird übers ValueBinding der BeanProperty der Wert der Komponente zugewiesen.Hier wird also getValue() der Komponente aufgerufen und damit die BeanProperty gefüttert.

Du hast also einmal die Konvertierung von String zur Property der Komponente, welche den Wert aufnimmt, und dann später vom Property der Komponente zum Property der Bean. Meist wird in ApplyRequest der Komponente einfach ein String zugewiesen und dann später entsprechend konvertiert. Bei einer Checkbox ist das aber bereits hier ein Boolean. Aber auch jeder andere Typ ist denbar ... da müsste man sich dann im Zweifelsfall die Implementierung der jeweiligen Komponente genauer anschauen.
In UpdateModel hat die eigentliche Konvertierung aber schon stattgefunden (die passiert ja zwischen ApplyRequest und UpdateModel). Hier könnte es nur ein Problem beim casten geben.

Ganz allgemein zum LifeCycle kannst du auch mal hier nachlesen:
http://balusc.omnifaces.org/2006/09/debug-jsf-lifecycle.html
 

Manuba

Mitglied
Ok, verstehe. Also zwei unabhängige Schritte: 1) Übermittlung des Wertes vom Request zur Komponente und 2) von der Komponente in die Bean.
Danke!
 

Neue Themen


Oben