`

"h:outputText"也可以这样用,如果是碰到JS语句也可以运行比如alert()

阅读更多
(1)
在我的JSF页面中想表达这样的语句:
<h:outputText id="scripthere" escape="false" value="<b>This is a text</b>" />
但是页面报错误:The value of attribute "value" associated with an element type "h:outputText" must not contain the '<' character.
查了下,这个比较好解决,办法如下:
<b><h:outputText id="scripthere" escape="false" value="This is a text" /></b>
(2)但是我要达到这样的效果就难了。
<h:outputText id="scripthere" escape="false" value="<script>alert('提示信息');</script>" />
我也用了上面的那个办法,但是还是报那个错误。至今还没有找到办法....
找到了办法:
<script>
<h:outputText id="scripthere" value="alert('提示信息')"/>
</script>
这样每行每行写就不会全部飘红了。(注意这里的id,其实在后面已经验证了这里不要id)
其实我最终的目的不是这样写的,
最终目的写法:
<script>
<h:outputText id="scripthere" value="#{publishTemplate.script}"/>;
</script>
这样写也没有达到我要的效果,因为页面重新加载一次就使得我private String script;这个为空(这里为空的原因在后面也说了是因为按钮的原因我这里用的是ajax4jsf的,在后面也改成普通的按钮,以便点击后来刷新整个页面)
public String getScript() {
System.out.println("getscript="+script);
return script;
}
public void setScript(String script) {
System.out.println("setscript="+script);
this.script = script;
}
我在判断没有目录的时候会设置它的值:
else{
System.out.println("must be publish template at first !");
this.setScript("alert('提示信息');");
}
但是当页面重新加载一次我就得不到它的值了。所以可能这种方法行不通啦 !!!
最后实在没办法了,就把那个script属性设置成static,这时候就弹出对话框来了,因为很难看它当页面还没有加载完的时候就弹出对话框把整个屏幕都全笼罩了,所以修改template.xhtml里面的那段代码:
<script>
window.onload = new Function("<h:outputText value="#{publishTemplate.script}"/>");
</script>
这样修改就好看些了。
但是当用已经存在的目录来操作时,因为它是static所以达不到效果,所以最后放弃这种方式。
哈哈,上面的情况总得不到值是因为我的按钮的问题,我原来用的是:
<a:commandButton value="Publish" action="#{publishTemplate.publishOneDirectory()}" rendered="#{templateBean.select}" />
xmlns:a="http://richfaces.org/a4j"
这里是ajax4jsf的按钮,a 是ajax的功能  它提交执行后 不再重绘整个页面  
,重绘整个页面时它会去bean里取的。所有改成h:commandButton了。这样在后台就可以得到值,但是在前台还是没有得到。待解决中...
最终的解决办法找到啦!!!
完整的代码如下:
(1)类:
private String script;
public String getScript() {
return script;
}
public void setScript(String script) {
this.script = script;
}
public void publishOneDirectory(){
if(localFilePath != null && flag == true){
   //这里的代码省略了
}else{
   this.setScript("alert('must be publish template at first !');");
}
}
(2)页面中:这outputText里面的id已经去掉啦,不去掉会报错。
<script>
window.onload = new Function(" <h:outputText value="#{publishTemplate.script}"/> ");
</script>
<h:commandButton value="Publish" action="#{publishTemplate.publishOneDirectory()}" rendered="#{templateBean.select}" />
分享到:
评论

相关推荐

    人事信息管理系统

    jsf和jpa 期末大作业 ... &lt;h:outputText value="删除"&gt;&lt;/h:outputText&gt; &lt;f:param name="p_id" value="#{person.id}"/&gt; &lt;/h:outputLink&gt; &lt;/h:column&gt; &lt;/h:dataTable&gt; &lt;/h:form&gt; &lt;/f:view&gt;

    h outputText 使用css 換行1

    . 解法如下拿DIV把h:outputText 罩住 &lt;div class="textAreaWrap" style="width:600px"&gt; 

    jboss as 7 support jsf2.2.1 modules

    通过使用Express Language 3(Java EE 7的一部分),多个属性也可以通过EL表达式直接定义。 &lt;h:outputText value="Something" &gt; &lt;f:passThroughAttributes value="{"one":1, "two":2, "three":3}" /&gt; &lt;/h:...

    JSF2datatable分页控件与左侧菜单

    而且也有很多很好的控件给发出来了,如:richfaces、primefaces、myfaces等,就日前来讲primefaces功能很强大,控件很多,但有一点不好就是不支持IE6,特别是下拉列表,p:dialog等,其它的分页p:datatable实际使用...

    JSF2.xdatatable分页控件与左侧菜单最简单应用

    而且也有很多很好的控件给发出来了,如:richfaces、primefaces、myfaces等,就日前来讲primefaces功能很强大,控件很多,但有一点不好就是不支持IE6,特别是下拉列表,p:dialog等,其它的分页p:datatable实际使用...

    C#调用VB进行简繁转换的方法

    本文实例讲述了C#调用VB进行简繁转换的方法。分享给大家供大家参考。具体分析如下: 首先在C#项目中引用Microsoft.VisualBasic.dll,版本自己选择合适的 然后在项目中添加引用...另外还可以进行全角与半角转换,平假名

    JSF文件下载实现

    如Abean中download方法调用了该方法,前台可以这样调用: &lt;h:commandButton value="download" action="#{aBean.download}"&gt;&lt;/h:commandButton&gt; 或者 &lt;h:commandLink value="download" action="#{fileUploadForm....

    JSF文件上传

    &lt;h:outputText value=" "/&gt; &lt;h:commandButton value="Submit" action="#{myBean.processMyFile}"/&gt; &lt;h:outputText value=" "/&gt; &lt;/h:panelGrid&gt; &lt;/h:form&gt; &lt;/f:view&gt; 其中tags.jsp文件如下: ...

    DELPHI执行DOS命令控件.rar

    property OutputText:TStrings read fOutputText; property ErrorText:TStrings read fErrorText; property Running : boolean read fRunning; published property OnOutputText :TOnText read fOnOutputText ...

    ErogeHelper:基于Textractor的可视化新颖的制胜平板电脑工具

    骑手还可以,但是您不会看到Textractor OutputText回调的输出。 (idk为什么,管道可能发生了某些问题)建议使用VS + Reshaper 只需准备运行F5即可,或者您可以在ErogeHelper的属性中填写命令参数,例如"D:\Ra-se-...

    tess-two-3.02-so-libs

    直接导入jar包,并把libs目录拷进项目即可使用。 ocr识别库下载 地址:: https://code.google.com/p/tesseract-ocr/downloads/list 调用示例程序: public void testGetUTF8Text() { // First, make sure the ...

    webprint:用于从您的 Web 应用程序直接打印到打印机的库

    目的 ... 支持的打印机 网页浏览器 Sato E/Pro 网络打印机 特征 文本输出字体大小 Code 39 条码 条码高度 ... -&gt;outputText('HELLO WORLD') -&gt;setPosition(0, 0.25, $printer::UNIT_INCHES) -&gt;outputCo

    BBS网站论坛设计参考

    public static string OutputText(string inputString) { string retVal=inputString; retVal= ConvertStr(retVal); retVal=retVal.Replace("[url]", ""); retVal=retVal.Replace("[/url]", ""); ...

    jsp探针 ver0.1

    String outputText = buffer.toString(); in.close(); return outputText; } public double getCpuRatio(){ double cpuRatio = 0; if (getOSName().toLowerCase().startsWith("windows")) { cpuRatio = ...

    彩色文字图生成组件,主要用来代替彩色label等

    DrawTextOutLine Boolean 是否绘制文字描边 DrawTextShadow Boolean 是否绘制投影,不支持投影平移 Text String 源文,包含颜色代码的源文 TextRect Rectangle 给定...OutputText String 过滤颜色代码后的内容

Global site tag (gtag.js) - Google Analytics