Reconstitute Component Tree

How component tree was reconstituted?
From jsp that have JSF tags or somehow else?
I was read specification but nothing in detail about that.
Is it define by specification or every JSF implementation can do it differently?
For example page like this.
Let assume that tree wasn't saved before.
<HTML>
<HEAD><title>Hello</title></HEAD>
<%@taglib uri="http://java.sun.com/jsf/html"prefix="h"%>
<%@taglib uri="http://java.sun.com/jsf/core"prefix="f"%>
<body bgcolor="white">
<h2>My name is Duke.What is yours?</h2>
<jsp:useBean id="UserNameBean"
class="helloDuke.UserNameBean"scope="session"/>
<f:use_faces>
<h:form id="helloForm"formName="helloForm">
<h:graphic_image id="wave_img"url="/wave.med.gif"/>
<h:input_text id="username"
valueRef="UserNameBean.userName"/>
<h:command_button id="submit"label="Submit"
commandName="submit"/>
</h:form>
</f:use_faces>
</HTML>

Hi niksa_os,
I think I might have misunderstood some of your question. I have put further comments below.
"from the http session" - how when nothing about page
isn't in session?On the first request (as you have probably noticed if you have built an app) none of the lifecycle is traversed except 'render response' in the RI.
So, myFaces use JSP with JSF Tags to figure out what
components
to put in Tree(?)!Yes, exactly. But so does the RI, just at different times. myfaces uses the JSP with JSF tags at the beginning of the request during the 'reconstitute response tree'. The RI does not involve the JSP until the render response phase.
How RI make Tree for the first time? Same or from the
HTML request?During the first render response the JSP is rendered in the usual way. The JSF tags are invoked just like any other JSP custom tag would be invoked. During the tags processing (doStartTag, doEndTag etc) the JSF API is invoked to manage the tree. If a new componet must be created it is, if one is found to exist in the tree then its not created.
After the tree is created and arranged as specified in the JSP then the renderers take over and make HTML from the components.
Or is there any other way?
I can't contrive third way, only from JSP/JSF and HTML
request!
What about XML output?
How does it works?If I understand your question you would/could get XML output by implementing your own renderers.
Hope this helps,
-bd-

Similar Messages

  • Component tree in request?!

    I know very little about HTTP requests, so when I read in some JSF tutorials that the component tree can either be stored in the session or in the request, I became confused as to what they were suggesting by the latter.
    I understand how the component tree can be stored in the session (the components remain in memory on the server and a session ID string is passed back and forth through cookies, request parameters, or hidden form fields - or the HttpSession takes care of this for you behind the scenes). (Is what I have said so far completely accurate?)
    However, what would be involved in storing the component tree in the request? Would serialized versions of the component tree be stored, or would an ID string similar to that used in the session be stored as a request parameter? If so, where would you specify the settings for storing the component tree in the request (so that I can get a better idea of how this process works).
    If I have completely misunderstood this concept or if you can provide clarification on my confusion, that would be wonderful.
    Thank you.

    Here's an excerpt from a JSF book that explains what I'm having trouble with:
    "...during the first request for this page, during the Render Response phase, the tags in this page will create four UIComponents... Each of these components is then stored (by the doEndTag method on the view tag) for use in subsequent requests for this page. During the Restore View phase, it is these components that will be reconstituted into the tree and will then be carried through the rest of the phases."
    What I'm not understanding is how is "each of these components stored ... for use in subsequent requests on this page" (presumably through the HttpRequest, but how)?
    Thanks.

  • How to construct the component tree in my custom component?Help!

    Hi, i am writing a custom component like this:
    public class HtmlCategory extends HtmlPanelGrid
         public void processRestoreState(javax.faces.context.FacesContext context,
                java.lang.Object state)
              setColumns(1);
              HtmlCommandLink link=new HtmlCommandLink();
              link.setValue("Let's Bingo");
              MyUtil.setActionListener(context,link,"#{temp.mytest}");
              UIParameter param=new UIParameter();
              param.setName("name");
              param.setValue("Robin!");
              link.getChildren().add(param);
              param.setParent(link);
              getChildren().add(link);
              link.setParent(this);
              super.processRestoreState(context,state);
    }         you see, i want to construct the compont tree at Restore View phase this way,because the structure of the component tree will always be the same, so i don't the user to write extra code.
    But the children of the component are not rendered,the renderer of the HtmlCategory component just extends the HtmlGridRenderer(myfaces) directly,and always calls the "super" methods in the encode methods of the renderer.
    I got a message from the console:
    Wrong columns attribute for PanelGrid id0:id4: -2147483648
    but i have set the columns attribute in the code above, so what's happening? or please give some advice about how to render the component tree by myself in Restore View with the tree constructing code in the custom component class code,just lke the code above.
    Best Regards:)
    Robin

    Well, i don't know if i have got my question clear.
    usually, according to the tags you use in the jsf page, a component tree will be created at the Restore View phase,for example:
    <f:form>
      <h:panelGrid ...........>                         
              <h:dataTable ................>
              </h:dataTable>
       </h:panelGrid>
    </f:form>but because i am writing a component for my web app, all the child components and their attributes are not likely to change. so i want to reduce the tags into one custom tag, and construct the component tree internally by myself.But it is not the case of backing bean.So i wrote the the code in the method:
    public void processRestoreState(javax.faces.context.FacesContext context,java.lang.Object state)as it is shown in my orginal message.But it seems that it is not right way to construct my component tree.So where should i put the code that construct the component tree?Overriding the method :
    public void processRestoreState(javax.faces.context.FacesContext context,java.lang.Object state)is not the right way?
    Best Regards:)
    Robin

  • Validation error corrupts component tree?

    I've got a strange problem trying to use validation on input fields.
    The basic setup is as follows:
    I've got a page divided into two parts with separate h:form tags, the one holding a dataTable with some elements and the other showing the element details in inputFields once an item is selected in the dataTable via a commandLink. A commandButton on the detail side allows you to update the values of the selected item which is being reflected in the dataTable on reload. So far so good.
    Here comes the strange part:
    All the inputFields are marked required. Now once you leave a field empty and try to submit the form, you get a validation error as expected. BUT if you now select a different element from the dataTable, ONLY the field whose validation formerly failed is being updated, the other fields still show the same value as before. The backing bean method that belongs to the commandLink is being executed, and the underlying data object of the input fields is being set properly, only the values in the component tree aren't updated. This behaviour persists until you enter a valid value in the formerly invalid input field and submit. Debugging shows that as long as at least one field has had validation errors, only the getter of these backing beans properties are being invoked during render response phase, as opposed to the "normal" case where the getters of all the backing beans properties are being called.
    For some reason, the render response phase seems to ignore the other components in the component tree when there was some validation error on one or more fields.
    Another interesting observation:
    This is the behaviour if I don't specify an action attribute in the commandLink selecting an element from the dataTable, as I want to return to the same page again. But if I define a navigation case that brings me to the same page and put that into the action attribute, the problem doesn't occur. Unfortunately this is no option for me, as I'm aiming to do all this with ajax.
    I've created a simple example so you can try out yourself:
    test.jsp:
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <html>
    <head>
    <title>validator test</title>
    </head>
    <body>
    <f:view>
         <h:form id="form1">
              <h:dataTable id="table" value="#{bean.datas}" var="data" binding="#{bean.table}" border="1">
                   <h:column>
                        <h:commandLink actionListener="#{bean.selectData}" value="#{data.string1}" />
                   </h:column>
                   <h:column>
                        <h:outputText value="#{data.string2}" />
                   </h:column>
              </h:dataTable>
              </h:form>
         <hr />
         <h:form id="form2">
              <h:inputText value="#{bean.data.string1}" id="field1" required="true" />
              <h:inputText value="#{bean.data.string2}" id="field2" required="true"/>
              <h:commandButton value="submit" />
         </h:form>
    </f:view>
    </body>
    </html>Bean.java:
    needs to be defined in faces-config.xml as bean "bean" with session scope
    import java.util.ArrayList;
    import java.util.List;
    import javax.faces.component.html.HtmlDataTable;
    import javax.faces.event.ActionEvent;
    public class Bean {
         private Data data;
         private List<Data> datas;
         private HtmlDataTable table;
         public Bean() {
              datas = new ArrayList<Data>();
              datas.add(new Data("data1value1","data1value2"));
              datas.add(new Data("data2value1",""));
         public void selectData(ActionEvent event) {
              data = (Data)table.getRowData();
         public List<Data> getDatas() {
              return datas;
         public Data getData() {
              return data;
         public void setData(Data data) {
              this.data = data;
         public HtmlDataTable getTable() {
              return table;
         public void setTable(HtmlDataTable table) {
              this.table = table;
         public class Data {
              private String string1;
              private String string2;
              public Data(String string1, String string2) {
                   this.string1 = string1;
                   this.string2 = string2;
              public String getString1() {
                   return string1;
              public void setString1(String value) {
                   string1 = value;
              public String getString2() {
                   return string2;
              public void setString2(String value) {
                   string2 = value;
    }My system setup:
    WinXP Professional
    JDK 1.6.0-b105
    Tomcat 5.5.20 (also tried 6.0.7)
    JSF RI 1.1.02_b08 (also tried 1.2_04-b10-p01, different but anyway not expected behaviour with MyFaces 1.1.5)
    Thanks for any input,
    Harry.

    Is there noone here who can tell me if this is behavior like specified or if I miss some point?
    A possible solution seems to be telling JSF programmatically to rebuild the view root. Does anyone if this is possible?

  • Component Tree Iteration???

    I have read several posts that some what deal with what I am trying to accomplish. I am trying to iterate through the component tree and set certain attributes on each component based on a user's security. For instance, a user logs in, and only has access to half of the components on a page, I would like to be able to iterate through each component and set the Rendered flag based on that user. However, I know the tree is not built the first time the page is viewed, so my question is.... how do I get around this? I would just add the "rendered=blah blah" to each component in the JSP, but I need to change other attributes on the components dynamically as well, not just the rendered state. Is there any way to tell faces to build the tree from the JSP before the render response phase?

    Bumping this post

  • Component tree destroyed when it should not be

    I have a custom component which derives from UICommand, clicking on which pops up a new window ... i have a listener associated with this component ... within this listener I call the setAction(outcome) method on the associated UICommand component with an outcome string (whose navigation rule is defined in faces-config.xml) ... This works properly in that the new window opens with the correct JSP.
    However, in doing this, JSF destroys the component tree of my original page ... Hence when I perform some operation on the original page (after opening the new window), it constitutes a new tree instead of using the tree which was already created for this page ...
    How do I solve my problem? - I'd like the original component tree to not get destroyed as well as work with the new window.
    Thanks.

    Currently, JSF only saves the current tree (it does
    not save more than one tree). A new State Saving
    proposal is being developed which will
    address the problem you are having.
    -rogerWow, that's a pretty significant change. Can you give us any hints about other major differences currently under consideration for the next revision?
    Thanks,
    Jonathan

  • Session scope for component tree subtree

    I'm very new to JSF. Here is what I'm trying to do: I created a custom component, renderer, and tag. This custom action will always have children that are no custom, but whose rendering I must control (via encodeChildren, etc).
    The problem I have is that the CSS style of these components will change after they are rendered (DHTML & AJAX). Some are hidden, color changes, size change, etc. When I go to another page with the same custom action included, of course it just renders a new version with all of the changes lost.
    Now if this was a simple custom action with no children, I'd just create a managed bean with a value binding and there would be no problem. But what I am trying to do is save the ENTIRE subtree, ie. save the state of the custom component and all of its children also.
    Now the messy way to do this would be to take my component, make it a managed bean, then include a value binding every time I use that custom action. The custom renderer would look to the bean for how to render the children, etc. The problem I have with this approach is that I basically have to include attributes in my component (used as a managed bean) that redundantly describe the children.
    For example, my component:
    class UISearch extends UIComponentBase {
    private boolean showChild1;
    private boolean child1Color;
    etc..
    OR a better option, to have:
    private UIComponent child1;
    public setShowChild1() {
    child1.render = true;
    ....etc....
    The problem I have with the above aproach is that every time a page is requested, the UIViewRoot tree will be build, a new Child1 will be instantiated, and then during the rendering of UISearch's encodeChildren I'll have to pretty much copy over attributes..
    I wish there was a way that I could have a "managed component subtree" where UISearch and all of its children are instantiated once, held through session scope, and every time they are rendered, regardless of page, the existing, managed version is used.
    This sounds so obvious, and I am almost positive there is a way to do this, I just don't know how.
    Thank you!!!!!
    PS:
    I think I am on the wrong track. Basically all I want to do is have the UISearch and its children load the same normal way each time that they do now. I don't even care if the component tree is re-created, re-rendered, etc. But after this custom action is rendered, I call an AJAX loadConfig() type method that will return all of the style, innerHTML, src, etc. changes that must be updated.
    So my question really is.. what is the best practice for storing and retriving this information? I'm using DWR, and I'd like the loadConfig() to return an object with all the config stuff nicely organized.. so if the returned object is "search" and I need to load the 'display' CSS style for some child, i can do:
    child.style.display = search.history.clearHistoryLink.style.display;
    Who knows. Any and all ideas are welcome!
    Message was edited by:
    rrc3243

    I found example (bookstore) where I got answer about using backing bean in session scope.
    <!-- Backing Bean for bookshowcart.jsp -->
    <managed-bean>
    <managed-bean-name>showcart</managed-bean-name>
    <managed-bean-class>backing.ShowCartBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <!-- Managed Bean -->
    <managed-bean>
    <description>
    Create a shopping cart in session scope the first
    time it is referenced.
    </description>
    <managed-bean-name>cart</managed-bean-name>
    <managed-bean-class>cart.ShoppingCart</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    ShoppingCart class don't have data properties like lastName or orderId
    Class have only somethings like this:
    protected BookDetails book() {
    BookDetails book =
    (BookDetails) context()
    .getExternalContext()
    .getRequestMap()
    .get("book");
    return (book);
    * <p>Return the <code>ShoppingCart</code> instance from the
    * user session.</p>
    protected ShoppingCart cart() {
    FacesContext context = context();
    ValueBinding vb =
    context.getApplication()
    .createValueBinding("#{cart}");
    return ((ShoppingCart) vb.getValue(context));
    * <p>Remove the item from the shopping cart.</p>
    public String remove() {
    BookDetails book = (BookDetails) item()
    .getItem();
    cart()
    .remove(book.getBookId());
    message(null, "ConfirmRemove", new Object[] { book.getTitle() });
    return (null);
    rule:
    Don't use backing bean with data properties in session scope!

  • Where/How do I programmatically build the component tree?

    Hi! I'm having a lot of problems trying to make my JSF application work...
    Here's the situation:
    - I have to display a form (questionnaire) consisting of a tree (form - subforms - sections - groups - questions - checkboxes/dropdowns...). Each of these parts are custom components, with custom renderers.
    - This display is only a small part of a wider application (so the custom ViewHandler solution seems impossible to me), and it is done in an imported jsp (using <jstl:import ...>). In this jsp, there is only one component, representing the "root" of the questionnaire, because the structure of the questionnaire is unknown at the beginning.
    - I need to build programmatically (in Java) the component tree of my questionnaire (according to the structure loaded from a database) and integrate it in the component tree of the whole application.
    - The problem is I can't get this to work properly in the JSF lifecycle (either the restoreState/saveState methods aren't called, or the "main" tree doesn't contain my "sub-tree" although everything is rendered properly...). I searched on a lot of forums, I tried a lot of solutions (new UIComponent() vs. application.createComponent(...) / create the tree in the component constructor vs. in the component renderer... ) but none of them seemed to meet my requirements, since it seems to be a tricky situation.
    So, does anyone knows how to achieve this? How and where to build my component tree?
    (ask me if a you need more information about my code!)
    Thanks in advance!!
    Adriano

    Bit_happens wrote:
    - I'm using the "createComponent" method to build my tree (instead of just calling the component constructor), is that right? For example:
    UISubform subformComponent = (UISubform) application.createComponent(UISubform.TYPE);
    //UISubform subformComponent = new UISubform();What is the difference with the plain constructor call?You are not implementation dependent then.
    - Apparently, I have to explicitly add the panelGroup to the component tree, or else it won't be part of the tree. Is that normal? Shouldn't JSF add it to the tree automatically when it finds it in the JSP? I have to do the following:
    UIComponent parent = facesContext.getViewRoot().findComponent("form_subview").findComponent("main_form");
    parent.getChildren().add(panel);
    panel.setParent(parent);- Is there a difference between creating the "sub-tree" in an ascending way, or in a descending way? I.e. first creating the leaves and then going up the branches until I plug the root component into the main tree, or first creating the root component and then going down the branches until all the leaves are created?No, there isn't.
    - I think my custom components themselves should be right, and they're declared in faces-config. It looks like the panelGroup doesn't renders its children, but it should by default, right? When I look at the rendered page source code, the panelGroup is empty:
    <span id="form_subview:main_form:formPanel"></span>- Do you think of anything else I should check? Any tricky setting I could have forgot?Try adding existing components to the panelGroup, e.g. HtmlOutputText. If that works, then I rather think there is a flaw in your component.

  • I'm just wondering : when a Component Tree is contitute for the first time

    When I'm looking at the JSF life cycle figure I can see the "Reconstitute Componente Tree" but I don't see something like "Constitute Componente Tree". When is it supposed to happen ?
    Thanks for your answer.

    If there is no existing tree (for example if it's the first time you reach a certain page), you start with an empty tree. It is up to you to create a new tree, either directly from Java, or (which is probably going to be the most typical scenario) through a template language like JSP using the Standard HTML RenderKit Tag Library.
    When using JSP, the JSF spec defines a sort of tree merging algorithm, which merges an existing tree with a tree defined in your JSP file. If the initial tree is empty, the resulting tree is going to depend 100% on the tree defined in your JSP. If there is an initial tree, slightly more complex rules may apply.

  • How to create a view(Component Tree)?

    After I look at the source codes of the RestoreViewPhase.java and ViewHandler,I find that "createView" only to get an instance of the UIViewRoot class,and not add any children at all.So I want to know how JSF can get the component Tree from the "createView" method?

    In fact if the first time a page is accessed, the component tree is only complete AFTER the render response. I must agree that this is lousy. In fact Smile supports a non-JSP model where the component tree is constructed at createView() time. Which allows you to do some initialisation for your new page/screen.
    In the JSP model you have to go through managed beans or setup context upfront, which you don't want because you want the init code for a screen be coded together with that screen.
    In fact I'm still looking for a way to stick with the spirit of the specs, but have a common way to have some 'event handler' that allows you to setup some context when a new screen is accessed.
    Dimitry D'hondt. (http://smile.sourceforge.net)

  • Reset the whole Component Tree?

    Hi,
    I've got 2 qeustions:
    1. How can I reset the whole Component Tree?
    2. And is it possible to destroy the User-Session for the current JSF application? If I use session.invalidate() the whole session will be destroyed, but I only want that all jsf things are resetted.
    Would be great if someone could give me a hint!

    A better way is to recreate the managed bean in the session scope.
    For example, to reset the current session instance of the backing bean MyBean which is definied as managed bean "myBean":public class MyBean {
        public void reset() {
            FacesContext
                .getCurrentInstance()
                    .getExternalContext()
                        .getSessionMap()
                            .put("myBean", new MyBean());
    }

  • Manipulating the component tree at runtime

    How is it possible to add components into a form at runtime. I need to create role specific menues after login. I have tried adding new children to the form object but they do not seem to render.

    in a short word, when is the rendered attribute value processed?is it part of the request map, and at Restore View Phase when restore the component tree, the inputText component will not be restored,and is this the reason the new name value is not applied?
    But if i change the editable attribute in the same class( User.java) with the name attribute,and change the jsf code like this:
    <h:selectBooleanCheckbox value="#{user.editable}" onclick="submit()"></h:selectBooleanCheckbox>
          <h:inputText  value="#{user.name}" rendered="#{user.editable}" required="true"></h:inputText>
          <h:outputText value="#{user.name}" rendered="#{not user.editable}"></h:outputText>The new value is applied!!
    Please give some suggestion, and many many thanks:)
    Best Regards:)
    Robin

  • Component tree persistence

    Want to know a couple of things
    FIRST
    Wanted to know how long JSF maintains component tree instances and state.
    For example,
    If I go to form A then to form B then back to form A, does form A have to rebuild the component tree and reset state?
    A lot of my dropdowns are populated by calling a database and therefore I would like to know how often the routines that populate the List with SelectItems would be called.
    Do I need to cache my lists first or can JSF kind of do that for me.
    SECOND
    A lot of my dropdowns are actually the same on many forms.
    Is there a way for JSF to keep these lists for me, then access from various form backing beans?

    OK, I think I get it. Create a managed bean with
    application scope and create set/get methods which
    call the database to build my reusable lists.
    Since this bean will not be a backing bean (where set
    methods are called on requests sent), when would this
    application scope managed bean set methods get called
    to populate these application scoped lists.The "backing bean" term is not well defined. To me, a backing bean is any bean with properties bound to JSF components, no matter when its methods are called. Also, the getter methods for a bean in application scope may be called on every request. So, I would call a bean in application scope used for this purpose a backing bean.
    Anyway, you declare the bean as a managed bean in faces-config.xml and populate the lists the first time the getter method is called.
    Do I have to somehow explicitly call them when the
    application starts (kind of like a startup servlet) or
    does JSF somehow take care of that for me.JSF doesn't specify anything that is activated on application startup, but since JSF runs in a servlet container, you can use a servlet context listener to create an populate the bean and place it in the application scope. This is an alternative to declaring it in faces-config.xml and populating it in the getter
    method. Either way works and which alternative to use is a matter of preference, but unless there are other things (unrelated to JSF) that needs to be done at application start, I would go with the declared managed bean approach; it requires the least amount of work and, as a side effect, documents the fact that this bean exists in application scope.
    Thanks for the info so far....I do appreciate your
    time....:-)I hope this helped.

  • Component tree manipulation

    hi,
    when would be the best time to manipulate the component tree for a page during the ADF Page Lifecycle?
    thanks
    David

    Hi,
    what is the usecase for modifying the component tree and why can't this be done in a PhaseListener?
    Frank

  • Component Tree

    How I do to modify the image of Component Tree, but no the
    paste, the imgame paper or subItens.
    Thanks

    Hi,
    what is the usecase for modifying the component tree and why can't this be done in a PhaseListener?
    Frank

Maybe you are looking for

  • Create fixed assets from within the transaction for creating the purchase order

    Hello All, I have gone through the notes on help.sap.com related to automatic creation of asset master record at the time of creating purchase order.  I am not sure how do we achieve this? Link to the notes on help.sap.com SAP Library - Asset Account

  • How do I deal with a Runtime Error on Adobe Acrobat 9.5?

    How do I deal with a Runtime Error on Adobe Acrobat 9.5? The instructions say to contact the support team but I have to pay in order to do so.

  • Error Occured in __XML_SEQUENTIAL_LOADER

    Hi, I'm re-populating a cube using a procedure that has been working fine for some years when all of a sudden I run into this error: ***Error Occured in __XML_SEQUENTIAL_LOADER: In __XML_UNIT_LOADER: In __XML_LOAD_MEAS_CC_PRT_ITEM: In ___XML_LOAD_TEM

  • IB Windows

    Hi, I have a document based AppleScript Application, and I have the Main Menu and Document Interfaces completed, but when I click on "New" when running the app, the new "document" window shows, but does not make itself active. Is there some way of ma

  • Document Area Error?

    This is from the Windows version CS6 version of Illustrator. Has anyone come across this error before? It reads "Can't Open the illustration. There is not enough room for the window; increase the document area and try again." How does this happen in