Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
677 views
in Technique[技术] by (71.8m points)

jsf - Difference between Apply Request Values and Update Model Values

I often get doubt on these two phases. The following is my understanding:

  1. Apply Request Values

    • In this phase, the submitted values are coming from the request parameter. Then the request values are set into the backing bean ie.setting to components UIInput
  2. Update Model Values

    • In this phase, processed values are transferred from backing bean (UIInput) to managed beans. (It is our custom defined JSF beans).

I am thinking that my understanding is correct. But, reading few articles made me confused. I want to make me more clear on these two phases. Please clarify me.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Apply Request Values

  • In this phase, the submitted values are coming from the request parameter. Then the request values are set into the backing bean ie.setting to components UIInput

That's not entirely correct. The values are not set into backing beans. They are set into components. Basically the following happens for each UIInput component in the component tree:

input.setSubmittedValue(request.getParameter(input.getClientId()));

Here input is UIInput and request is HttpServletRequest.


Update Model Values

  • In this phase, processed values are transferred from backing bean (UIInput) to managed beans. (It is our custom defined JSF beans).

Also not entirely correct. UIInput components are not backing beans. Basically the following happens for each UIInput component in the component tree:

bean.setProperty(input.getValue());

Here, the bean and property is based on the input's valuebinding, e.g. value="#{bean.property}".


All with all, your confusion is clearly in distinguishing between the JSF component tree, the JSF backing beans and the JSF managed beans. The JSF component tree is the one which you've definied in the JSP/Facelets page and as you can obtain by FacesContext#getViewRoot(). The JSF backing beans are Javabean classes whose properties are bound to the component tree using EL such as #{bean.property}. The JSF managed beans are concrete instances of those Javabean classes. They can be request, session or application scoped (and in JSF 2.0 also view scoped). It are the managed beans where the values are actually been set and retrieved.

See also


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...