Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am currently using composite components in my JSF 2.0 application, and I often face the same problem. So I use <a href="http://blog.timmlinder.com/2011/07/jsf2-finding-and-re-rendering-components-in-different-namingcontainers/" rel="nofollow">this helper class</a>:</p> <pre><code>public class ComponentResolver { /** * Returns the absolute path of a given {@link UIComponent}. * E.g. :namingContainer1:namingContainer2:componentId. * * @param currentComponent * @return The absolute path of the given component */ public String getAbsoluteComponentPath(UIComponent currentComponent) { final char separatorChar = UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance()); String path = ""; if(!(currentComponent instanceof NamingContainer)) path = currentComponent.getId(); while(currentComponent != null) { if(currentComponent instanceof NamingContainer) { path = currentComponent.getId() + (!path.isEmpty() ? separatorChar : "") + path; } currentComponent = currentComponent.getParent(); } path = separatorChar + path; return path; } /** * Returns a whitespace-separated list of the absolute paths of all given components. * * @param components The list of components * @return A whitespace-separated list of all absolute paths. * @see ComponentResolver#getAbsoluteComponentPath(UIComponent) */ public String getAbsoluteComponentPaths(Collection&lt;UIComponent&gt; components) { String paths = ""; for(UIComponent c : components) { if(!paths.isEmpty()) paths += " "; paths += getAbsoluteComponentPath(c); } return paths; } /** * Finds all components with the given id, and returns a whitespace-separated list * of their absolute paths (e.g. &lt;code&gt;:j_id1:j_id2:myId :j_id1:j_id3:myId&lt;/code&gt;). * * @param id The id to search the component tree for * @return Whitespace-separated list of absolute component paths * @see #resolveList(String) */ public String resolve(String id) { List&lt;UIComponent&gt; components = resolveList(id); return getAbsoluteComponentPaths(components); } public String resolveWithoutRootPrefix(String id) { List&lt;UIComponent&gt; components = resolveList(id); String result = getAbsoluteComponentPaths(components); return result.substring(1, result.length()); } /** * Finds all components with the given id by traversing the component tree. * @param id Id to search for. * @return List of components that have got this id. */ public List&lt;UIComponent&gt; resolveList(String id) { return resolveList(id, FacesContext.getCurrentInstance().getViewRoot()); } /** * Recursive function that traverses the component tree and accumulates all components * that match the given id. * @param id The id to look for * @param currentComponent Component of the tree to start traversal at * @return Accumulation of all components that match the given id */ private List&lt;UIComponent&gt; resolveList(String id, UIComponent currentComponent) { List&lt;UIComponent&gt; accumulator = new LinkedList&lt;UIComponent&gt;(); if(null != currentComponent.getId() &amp;&amp; currentComponent.getId().equals(id)) { accumulator.add(currentComponent); } Iterator&lt;UIComponent&gt; childIt = currentComponent.getFacetsAndChildren(); while(childIt.hasNext()) { UIComponent child = childIt.next(); accumulator.addAll(resolveList(id, child)); } return accumulator; } } </code></pre> <p>Then you just need to set it as a manage bean, and use it as follow:</p> <pre><code>#{componentResolver.resolve('myRegion')} </code></pre> <p>So now you just need to set the id of the aimed region as <code>myRegion</code> and set the <code>render</code> attribute of your commandLink with the previous EL.</p> <p>That's pretty tricky, but I didn't find any other solution for working with nested blocs in JSF 2.0.</p> <p><a href="http://blog.timmlinder.com/2011/07/jsf2-finding-and-re-rendering-components-in-different-namingcontainers/" rel="nofollow">(source)</a></p>
 

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