Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>One approach to making composite controls is to use the <em>binding</em> attribute to associate the tag with your own code:</p> <pre><code>&lt;f:view&gt; &lt;h:form&gt; &lt;h:panelGroup binding="#{compositeControlBean.panelGrid}" /&gt; &lt;/h:form&gt; &lt;/f:view&gt; </code></pre> <p>The bean configuration in <em>faces-config.xml</em>:</p> <pre><code>&lt;managed-bean&gt; &lt;managed-bean-name&gt;compositeControlBean&lt;/managed-bean-name&gt; &lt;managed-bean-class&gt; composite.CompositeControlBean &lt;/managed-bean-class&gt; &lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt; &lt;/managed-bean&gt; </code></pre> <p>The bean code:</p> <pre><code>/** * Configure this bean in request scope as "compositeControlBean". */ public class CompositeControlBean { private transient UIComponent panelGrid; public UIComponent getPanelGrid() { if (panelGrid == null) { panelGrid = createCompositePanel(); } return panelGrid; } public void setPanelGrid(UIComponent panelGrid) { this.panelGrid = panelGrid; } private UIComponent createCompositePanel() { initContextMemebers(); UIComponent commandLink = createCommandLink(); String id = view.createUniqueId(); UIComponent panelGrid = application .createComponent("javax.faces.HtmlPanelGroup"); panelGrid.setId(id); panelGrid.setRendererType("javax.faces.Group"); panelGrid.getChildren().add(commandLink); return panelGrid; } private UIComponent createCommandLink() { // create control String id = view.createUniqueId(); UIComponent commandLink = application .createComponent("javax.faces.HtmlCommandLink"); commandLink.setId(id); commandLink.setRendererType("javax.faces.Link"); // set attributes (bind to printHello method) Map&lt;String, Object&gt; attributes = commandLink .getAttributes(); MethodExpression action = expressionFactory .createMethodExpression(elContext, "#{compositeControlBean.printHello}", String.class, new Class&lt;?&gt;[0]); attributes.put("value", "print hello"); attributes.put("actionExpression", action); return commandLink; } private transient FacesContext context; private transient Application application; private transient ELContext elContext; private transient ExpressionFactory expressionFactory; private transient UIViewRoot view; private void initContextMemebers() { context = FacesContext.getCurrentInstance(); application = context.getApplication(); elContext = context.getELContext(); expressionFactory = application.getExpressionFactory(); view = context.getViewRoot(); } public String printHello() { System.out.println("Hello"); return null; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload