You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Dennis Byrne <de...@dbyrne.net> on 2005/07/28 18:42:19 UTC

composite controls

I can't seem to find a lot of resources on creating composite 
controls ( an .ascx in .NET speak ).  Does anyone have a web 
site or a war story for this?
Dennis Byrne

Re: composite controls

Posted by De...@ak.blm.gov.
Thanks for the reply.  Right now I'm doing a little of what McClanahan 
suggested to comeone else: 
http://www.mail-archive.com/users%40myfaces.apache.org/msg06173.html . 

Let me elaborate:  I have JSP after JSP that go inputText, label, message 
<br/>, inputText, label, message, ...  I want one control that will "wake 
up", instantiate the UIcomponents for all three, and manually add these to 
the tree.  Right this second, I am currently trying to figure out why my 
tag handler is getting a null parent (when it should be the view).

Down the road, I may want to add components based on complex run time 
conditions.

Dennis Byrne

Re: composite controls

Posted by Werner Punz <we...@gmx.at>.
Dennis Byrne wrote:
> I can't seem to find a lot of resources on creating composite 
> controls ( an .ascx in .NET speak ).  Does anyone have a web 
> site or a war story for this?
> Dennis Byrne
> 
depends on what you want to do, if you want to stay on a high level, 
check out struts clay, facelets or jsf tiles.
If you want to code them, then I can recommend the custom control 
tutorial on the exadel website, and also Kito D. Manns book JSF in 
action, which has an excellent coverage of that kind of stuff.


Re: composite controls

Posted by Mike Kienenberger <mk...@gmail.com>.
They are added via getChildren().add() in the constructor of the UIComponent.

On 7/28/05, Dennis_Byrne@ak.blm.gov <De...@ak.blm.gov> wrote:
>  
> Mike, for the first option.  I take it you created UI components on the fly
> added them to tree via a call to getChildren().add() ?  If so, where did you
> do this?  In the Tag handler itself (perhaps setProperties)? or in some
> method or constructor of the UIComponent ? 
>  
> Dennis Byrne
>

Re: composite controls

Posted by Mike Kienenberger <mk...@gmail.com>.
Right, this is option #2.

x:aliasBean simply allows you to redefine the backing beans used by
your included piece of code and uses f:subview instead of f:view.

On 7/28/05, Dennis_Byrne@ak.blm.gov <De...@ak.blm.gov> wrote:
>  
> Thank you for your time.  I am going to weight each of these options w/ the
> one I just thought of below. 
>  
> Familiar w/ tag files?  Try this, it'll take 2 minutes.  Create a tags dir
> under WEB-INF .  Put these lines in a file called Test.tag . 
>  
> <%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %> 
> <%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%> 
>  
>         <f:view> 
>                 <h:outputText value="a"/> 
>                 <h:outputText value="b"/>                 
>         </f:view> 
>  
> ... in your JSP put these two lines. 
>  
> <%@taglib prefix="project" tagdir="/WEB-INF/tags" %>f:view> 
> <project:Test /> 
>  
> Dennis Byrne
>

Re: composite controls

Posted by Mike Kienenberger <mk...@gmail.com>.
The composite component example provided above is a custom DataTable
with a footer containing a UICommand, a row header UIColumn (with a
UIOutput) and a UIColumns object with a UIOutput header and a
UISelectBoolean.

On 7/28/05, Dennis_Byrne@ak.blm.gov <De...@ak.blm.gov> wrote:
>  
> Did any of these tags have children that render themselves?  I can save and
> restore state fine, but I'm stuck as far as getting children to render.  I
> get as far as UIComponent.encodeChildren() and I can query each child for
> it's renderer type.  Thoughts? 
>  
> Dennis Byrne
>

Re: composite controls

Posted by De...@ak.blm.gov.
Did any of these tags have children that render themselves?  I can save 
and restore state fine, but I'm stuck as far as getting children to 
render.  I get as far as UIComponent.encodeChildren() and I can query each 
child for it's renderer type.  Thoughts?

Dennis Byrne

Re: composite controls

Posted by De...@ak.blm.gov.
Thank you for your time.  I am going to weight each of these options w/ 
the one I just thought of below.

Familiar w/ tag files?  Try this, it'll take 2 minutes.  Create a tags dir 
under WEB-INF .  Put these lines in a file called Test.tag .

<%@taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

        <f:view>
                <h:outputText value="a"/>
                <h:outputText value="b"/> 
        </f:view>

... in your JSP put these two lines.

<%@taglib prefix="project" tagdir="/WEB-INF/tags" %>f:view>
<project:Test />

Dennis Byrne

Re: composite controls

Posted by De...@ak.blm.gov.
Mike, for the first option.  I take it you created UI components on the 
fly added them to tree via a call to getChildren().add() ?  If so, where 
did you do this?  In the Tag handler itself (perhaps setProperties)? or in 
some method or constructor of the UIComponent ?

Dennis Byrne

Re: composite controls

Posted by Mike Kienenberger <mk...@gmail.com>.
There are three ways to do this that I have successfully used.

#1)  Programmically create a set of controls as a new component.

#2)  Use x:aliasBean and a jsp include to represent your composite control.

#3)  Use ui:composition with the facelets library.

#1 is the hardest, most involved, and most fragile way to do it.

#2 is easy and requires only a dependency on x:aliasBean.   There are
possibly some issues with nesting x:aliasBean controls, however.

#3 is also easy and requires a dependency on the facelets library.

The resulting code for #2 and #3 are very similar, and converting
between them is trivial in most cases.

Shale's Clay subproject probably also offers similar functionality,
but I haven't used it yet.

You can find an example of #1 in issue MYFACES-331:

http://issues.apache.org/jira/secure/attachment/12311217/RowAndColumnRelationshipComponent.zip

An example of using #2 (without the custom component code) would look like this:

            <x:aliasBean alias="#{backingBean}"
value="#{activityTypeCategoryActivityTypeListRelationshipDataBackingBean}">
                <f:subview
id="activityTypeCategoryActivityTypeListRelationshipDataDataTableView">
        				<jsp:include page="/pages/BooleanRelationshipDataTable.jsp"/>
                </f:subview>
            </x:aliasBean>

An example of use #3 (without the custom component code) would look like this:

            <ui:include src="/pages/BooleanRelationshipDataTable.xhtml">
                <ui:param name="backingBean"
value="#{activityTypeCategoryActivityTypeListRelationshipDataBackingBean}"/>
            </ui:include>

-Mike




On 7/28/05, Dennis Byrne <de...@dbyrne.net> wrote:
> I can't seem to find a lot of resources on creating composite
> controls ( an .ascx in .NET speak ).  Does anyone have a web
> site or a war story for this?
> Dennis Byrne
>