Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>ok, I found how to do it with MyFaces. It also requires a bit of ugly reflection...</p> <pre><code>public static UIComponent instantiateTagComponent(Location loc, String namespace, String localPrefix, String componentName, TagComponentParam params[]) { final String ERROR_MESSAGE = "Erreur lors de l'instanciation d'un tag component"; FacesContext ctx = FacesContext.getCurrentInstance(); AbstractFaceletContext fctx = (AbstractFaceletContext) ctx.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY); fctx.pushPageContext(new PageContextImpl()); FaceletViewDeclarationLanguage vdl = new FaceletViewDeclarationLanguage(ctx); UIPanel panel = (UIPanel) ctx.getApplication().createComponent( UIPanel.COMPONENT_TYPE ); try { Method createCompiler = FaceletViewDeclarationLanguage.class.getDeclaredMethod("createCompiler",FacesContext.class); Method createFaceletFactory = FaceletViewDeclarationLanguage.class.getDeclaredMethod("createFaceletFactory",FacesContext.class,org.apache.myfaces.view.facelets.compiler.Compiler.class); createCompiler.setAccessible(true); createFaceletFactory.setAccessible(true); org.apache.myfaces.view.facelets.compiler.Compiler compiler = (org.apache.myfaces.view.facelets.compiler.Compiler) createCompiler.invoke(vdl, ctx); FaceletFactory ff = (FaceletFactory) createFaceletFactory.invoke(vdl, ctx, compiler); TagLibrary tl = compiler.createTagLibrary(); TagConfig tc = new JSFUtilsTagUnit(tl, namespace, localPrefix, componentName,params,loc); TagHandler th = tl.createTagHandler(namespace, componentName, tc); Field declaredField = FaceletCompositionContext.class.getDeclaredField("FACELET_COMPOSITION_CONTEXT_KEY"); declaredField.setAccessible(true); FaceletCompositionContextImpl faceletCompositionContextImpl = new FaceletCompositionContextImpl(ff,ctx); Class&lt;?&gt; dfcClass = Class.forName("org.apache.myfaces.view.facelets.impl.DefaultFaceletContext"); Field fMCTX = dfcClass.getDeclaredField("_mctx"); fMCTX.setAccessible(true); fMCTX.set(fctx, faceletCompositionContextImpl); FacesContext.getCurrentInstance().getAttributes().put((String)declaredField.get(null),faceletCompositionContextImpl); FaceletCompositionContext mctx = (FaceletCompositionContext) FaceletCompositionContext.getCurrentInstance(fctx); mctx.startComponentUniqueIdSection(); th.apply( fctx, panel ); } catch (IOException ex) { log.error(ERROR_MESSAGE, ex); } catch (InvocationTargetException ex) { log.error(ERROR_MESSAGE, ex); } catch (NoSuchMethodException ex) { log.error(ERROR_MESSAGE, ex); } catch (NoSuchFieldException ex) { log.error(ERROR_MESSAGE, ex); } catch (SecurityException ex) { log.error(ERROR_MESSAGE, ex); } catch (ClassNotFoundException ex) { log.error(ERROR_MESSAGE, ex); } catch (IllegalArgumentException ex) { log.error(ERROR_MESSAGE, ex); } catch (IllegalAccessException ex) { log.error(ERROR_MESSAGE, ex); } finally { fctx.popPageContext(); } return panel; } </code></pre> <p>The JSFUtilsTagUnit class is :</p> <pre><code>static class JSFUtilsTagUnit implements TagConfig { private final TagLibrary library; private final String namespace; private final String name; private Tag tag; public JSFUtilsTagUnit(TagLibrary library, String namespace, String localPrefix, String name, TagComponentParam params[], Location loc) { this.library = library; this.namespace = namespace; this.name = name; if(loc == null) { loc = new Location("virtual", -1, -1); } TagAttribute[] tas; if((params != null) &amp;&amp; (params.length &gt; 0)) { tas = new TagAttribute[params.length]; int iCurrent = 0; for(TagComponentParam tcpCur : params) { tas[iCurrent] = new TagAttributeImpl(loc,"",tcpCur.getName(), tcpCur.getName(), tcpCur.getValue()); iCurrent++; } } else { tas = new TagAttribute[0]; } TagAttributes tattrs = new TagAttributesImpl(tas); tag = new Tag(loc, namespace, name, localPrefix+":"+name, tattrs); } public FaceletHandler getNextHandler() { return new FaceletHandler() { public void apply(FaceletContext ctx, UIComponent parent) throws IOException { } }; } public Tag getTag() { return tag; } public String getTagId() { return "-1"; } } </code></pre> <p>Hope it will help someone else !</p>
    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.
 

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