包括动态生成面板的方法 [英] Ways to include a dynamically generated facelet
问题描述
在当前项目中,我需要创建一个面板,其中包含用户在应用程序其他位置创建的HTML内容。这个内容可以很容易地插入:
< h:outputText value =#{myBean.dynamicHTMLContent}escape = 假/>
一个示例内容:
< p>用户文本< / p>
现在我们需要给予用户更多的自由,并允许他在HTML代码中使用令牌,稍后由应用程序解决:
< p>用户文本< / p>< p>用户图像:{niceImage }< / p为H.
应用程序在 myBean.dynamicHTMLContent 中解析用户内容,并替换 {niceImage(param)} 与
< a4j:mediaOutput element =imgcreateContent ={myBean .generateNiceImage}/>
这已经是一个面孔代码片段,无法在 h中进行评估和呈现:outputText 。
在EL表达式尚未评估的阶段,我正在寻找一种将这种动态内容包含在脸孔中的好方法。像
< ui:include src =src/>
但动态组件将是最佳解决方案。
$ b $任何想法?
最终,我用简单的方法将用户HTML中的所有自定义(大括号)令牌替换为相应的JSF元素,并生成一个临时的 ui:composition
facelet file:
public String getUserHtmlContentPath() {
文件temp = File.createTempFile(userContent,.tmp);
temp.deleteOnExit();
FileWriter fw = new FileWriter(temp);
fw.write(getUserHtmlContentComposition());
fw.close();
返回file://+ temp.getAbsolutePath();
}
和父面孔:
< ui:include src =#{myBean.userHtmlContentPath}/>
In current project I need to create a panel that will contain an HTML content created by the user elsewhere in the application. This content can be easily inserted like this:
<h:outputText value="#{myBean.dynamicHTMLContent}" escape="false"/>
An example content:
<p>User text</p>
Now we need to give the user more freedom and allow him to use tokens in the HTML code that will be resolved by the application later:
<p>User text</p><p>User image: {niceImage}</p>
The application parses user content in myBean.dynamicHTMLContent and replaces {niceImage(param)} with
<a4j:mediaOutput element="img" createContent="{myBean.generateNiceImage}"/>
This is already a facelet snippet and cannot be evaluated and rendered in h:outputText.
I was looking for a good way to include this kind of dynamic content within a facelet at the stage when EL expressions are not yet evaluated. Something like
<ui:include src="src"/>
but for dynamic components would be the best solution.
Any ideas?
Eventually I took the easy way by replacing all custom (curly braces) tokens in the user HTML with corresponding JSF elements and generating a temporary ui:composition
facelet file:
public String getUserHtmlContentPath() {
File temp = File.createTempFile("userContent", ".tmp");
temp.deleteOnExit();
FileWriter fw = new FileWriter(temp);
fw.write(getUserHtmlContentComposition());
fw.close();
return "file://" + temp.getAbsolutePath();
}
and in the parent facelet:
<ui:include src="#{myBean.userHtmlContentPath}"/>
这篇关于包括动态生成面板的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!