Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF 2.0 Composite components - ajax render parameter OUTSIDE component definition

Tags:

java

jsf-2

Consider a simple composite component which takes an action parameter of some sort - a simple link 'prettifier', for example. I want to 'ajaxify' it.

   <composite:interface>
        <composite:attribute name="act" method-signature="java.lang.String action()"></composite:attribute>
        <composite:attribute name="text" required="true"></composite:attribute>
            <composite:clientBehavior  name="click" event="action"  targets="l"/>    </composite:interface>

   <composite:implementation>
        <h:commandLink id="l" act="#{cc.attrs.action}" immediate="true">            <b>#{cc.attrs.text}</b>         </h:commandLink>    </composite:implementation>

I expose an event through client behaviour. I use it like this:

<h:panelGroup layout="block" id="outside">

        #{mybean.otherdata} <br/>

                <mc:mylink text="Click click" action="#{mybean.click}" >
                    <f:ajax event="click" render="outside"/>"
                </mc:mylink><br/>

</h:panelGroup>

You can see what I want to do: I want to do an ajax render outside the composite definition; just setting render to "outside" gives the dreaded <f:ajax> contains an unknown id error.

Yes, I am aware of naming containers, and I know we can prepend with a colon and specify an absolute path, but that's quite clunky. If I wrap it up in several more layers (which is the whole point) I'd have to chain these references together manually.

Can I make some sort of relative reference like render="../outside" to skip the reference to the parent container of the component?

I did a jsf 1 app with a4j, and this pattern was used all over the place.

like image 765
james Avatar asked Dec 23 '22 02:12

james


2 Answers

In JSF 2.0, you can use the implicit cc and component objects inside EL. In order to fetch the full client ID for any component do:

#{component.clientId}

To retrieve the client ID for a composite component do:

#{cc.clientId}

In the same way, you can also fetch parent with #{cc.parent}. In this case, this is probably what you want. For a bit longer answer see Acquire full prefix for a component clientId inside naming containers with JSF 2.0.

like image 56
Tuukka Mustonen Avatar answered Dec 28 '22 07:12

Tuukka Mustonen


You can use render="@all" or render="@form" to render everything, or the whole from respectively.

Alternatively, you can pass in the absolute id of what you want to update as a parameter into your component. This maintains flexibility, without unnecessarily re-rendering too much of the page.

like image 33
Brian Leathem Avatar answered Dec 28 '22 07:12

Brian Leathem