aspose file tools*
The moose likes JSF and the fly likes need for encodeBegin() method and an encodeEnd( ) method ??    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "need for encodeBegin() method and an encodeEnd( ) method ??    " Watch "need for encodeBegin() method and an encodeEnd( ) method ??    " New topic
Author

need for encodeBegin() method and an encodeEnd( ) method ??

lavnish lalchandani
Ranch Hand

Joined: Feb 28, 2007
Posts: 79
Hi All
i read the following text in a book
but was unable to inter prate it properly
would be glad if someone can explain the part in bold

<h:form>
Propety_Label: <h:inputText value="#{myBean.myProperty}" />
</h:form>

When the JSP container processes this page,
(i) it invokes the doStartTag() method on the tag handler for the <h:form> action,
(ii) writes the "Propety_Label:" template text to the response,
(iii) invokes the doStartTag() and the doEndTag() methods on the tag handler for the <h:inputText> action,
(iv) and invokes the doEndTag() method on the tag handler for the <h:form> action.

Unless we're careful here, the template text ends up before the <form> and <input> elements generated by the JSF components.
To avoid this, the JSF rendering API defines both an encodeBegin() method and an encodeEnd( ) method.

For a component that doesn't render its children, like the UIForm component, the tag handler's doStartTag() method calls encodeBegin(), which writes the <form> start tag to the response. The start tag therefore comes before the template text added to the response by the JSP container. The doStartTag() method for the <h:inputText> action then writes the single tag for the <input> element, and the doEndTag() method for the <h:form> action adds the end tag for the <form> element

my question is ....
1) even if there is no encodeBegin() and encodeEnd() methods
how can .... the template text ends up before the <form> and <input> elements ???
2) For a component that doesn't render its children, like the UIForm component, .... what difference will it make if the doStartTag() method writes the <form> instead of the encodeBegin()


lavnish.blogspot.com
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

Well, to make total sense of what you've posted, I'd probably have to print it out, think about it, and maybe consult a book or two. And I'm too lazy to do that.

But I'd venture a guess that the problem lies in the "Propety_Label: " part of the source. When a JSP tag is defined, it is defined as either having a body or being a standalone tag. Unless I say otherwise, everything that follows is also true of JSF, since it's built on the JSP tag architecture.

A JSP tag makes a decision on when - if ever - to output the generated java code that will then be compiled to form the servlet that renders and transmits the final output data stream (usually HTML text). It can do so when the start tag has been seen and/or when the end tag has been seen. All the body text between the tags gets scooped up and saved until the end tag is detected. The end tag then can use this text in whatever way it wishes. The start tag knows nothing of the body text - it hasn't been scanned yet - but it does know its attribute names and values.

JSF prefers to avoid mixing free text and tagged text. So the "Propety_Label: " string should properly be bracketed with its own tags. Which, if I remember correctly, would be <hutputLabel>Propety_Label: </hutputLabel>. In practical terms, this might mean that the "Propety_Label: " might not render in the right location - if at all.

Because of the nature of the JSF architecture, the tag structure of a JSF page is manipulated as a tree which gets several passes made over it. Straight JSP tags are stream-oriented with a single pass. That also makes a certain difference in how critical it is to use your tags properly.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: need for encodeBegin() method and an encodeEnd( ) method ??