【发布时间】:2014-01-14 10:02:49
【问题描述】:
我有点困惑。我尝试做一个简单的例子,我们可以从 xhtml 页面上传文件,在上传文件时会显示 something.jpg。 我这样做:
<h:outputScript library="javascript" name="showProgres.js" />
<h:outputScript library="javascript" name="prototype-1.6.0.2.js"/>
<h:form id="form" prependId="false" enctype="multipart/form-data">
<h:panelGrid columns="2">
<h:inputFile id="upload1" value="#{demoBean.file1}">
<f:ajax onevent="com.corejsf.showProgres" render="@form" />
</h:inputFile>
<h:graphicImage id="pole" library="images" name="orange-barber-pole.gif"
style="display: none"/>
<h:commandButton action="#{demoBean.upload()}" value="upload"></h:commandButton>
</h:panelGrid>
</h:form>
在资源目录中我有showprogres.js 文件。使用showProgres 函数如下:
if(!com) var com = {};
if(!com.corejsf) {
com.corejsf = {
showProgres: function(data){
var inputId = data.source.id;
var progresBarid = inputId.substring(0,
inputId.length - "upload2".length) + "pole";
if(data.status == begin)
Element.show(progresBarid);
else if (data.status == success)
Element.hide(progresBarid);
}
}
};
当我开始对 glassfish 进行采样时,结果出乎我的意料。像这样的东西(在整个 xhtml 页面上没有错误):
此 XML 文件似乎没有任何关联的样式信息。文档树如下所示。
<partial-response id="j_id1">
<changes>
<update id="j_id1:javax.faces.ViewState:0">
<![CDATA[ -3528225672520671936:9111168294196781686 ]]>
</update>
</changes>
</partial-response>
有人知道会发生什么吗?我没有任何错误。没有 ajax 一切都很好(上传工作)。
【问题讨论】:
-
我很困惑:
<h:inputFile>会知道你的活动吗?onevent的参数应该是由<h:inputFile>组件实际触发的事件名称。也许您打算将其附加到commandButton? -
好的,当我把它放在那里时,我得到了相同的结果!你的意思是我的渲染有问题吗?可能没有正确定义组件 ID,特别是如果我将 ajax 放在 comandButton 组件中?