??xml version="1.0" encoding="utf-8" standalone="yes"?>
public String logout() {
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
session.invalidate();
return "login_page";
}
如果你想有一个动画gif囄?/span>"L(fng)?.."?当表单提交后该图片应该从新加?因此,再一ơ指定图片的id,q且dl过一D|间g时后重新加蝲的代?下面是个例子: <script>
下面的代码片D늤例了如何在JSP面中结束session:
<% session.invalidate(); %><c:redirect url="loginPage.jsf" />
<h:commandLink actionListener="#{productBean.downloadAction}" styleClass="highLightLink">
<h:outputText value="download"/>
<f:param name="productId" value="#{productBean.id}"/>
</h:commandLink>
public void downloadAction(ActionEvent event) {
try {
String fileName="D:\\temp\\images\\products\\" + this.id + ".xls";
logger.debug("file name=" + fileName);
ByteArrayOutputStream baos=this.serviceLocator.getFileService().downloadFile(fileName); //调用ServiceҎ(gu)Q获得文件的ByteArrayOutputStream
HttpServletResponse response=FacesUtils.getServletResponse();
response.setHeader("Content-disposition", "attachment; filename=" + id+ ".xls" ); //不是内嵌昄(inline)Q而是作ؓ(f)附g下蝲
response.setContentLength(baos.size());
ServletOutputStream sos=response.getOutputStream();
baos.writeTo(sos);
baos.close();
sos.flush();
} catch (IOException ex) {
logger.debug(ex);
}
}
public ByteArrayOutputStream downloadFile(String fileName) throws IOException {
FileInputStream fis=new FileInputStream(fileName);
BufferedInputStream bis=new BufferedInputStream(fis);
ByteArrayOutputStream baos=new ByteArrayOutputStream();
BufferedOutputStream bos=new BufferedOutputStream(baos);
int i;
while((i=bis.read())!=-1) {
bos.write(i);
}
bos.flush();//提交文g,很关?br /> bis.close();
return baos;
}
前台实现QMyfaces
后台理BeanQ?/span>
<h:form target="mainFrame"> |
mainFrame |
<h:form target="mainFrame"> |
mainFrame |
当inputText的值改变的时候会(x)触发processValueChanged事gQ此事情内部通过参数Q获取HtmlInputText的控Ӟ然后讑֮readonlyQ同时设定panelGrid的模型changePanel的属性,因ؓ(f)panelGridl定了changePanelq个模型?br />
2、Action events(动作事g)
上面q个是静态outcome事gQ在faces-config.xml中配|相应的属性后Q点击该按钮?x){向相应的Ҏ(gu)?br />
如果d了actionListener属性的话,点击之后Q在转向其他面之前Q会(x)触发指定的事Ӟ处理之后再{向?br />
q里的doSomeActionҎ(gu)的声明是void doSomeAction(ActionEvent actionEvent)?br />
上面q个是动态outcome事gQ当点击该按钮之后会(x)直接触发loginForm中的login事gQlogin事gq回的是一个字W串Q在login处理完相应操作之后需要返回一个属性中已经配置q的字符Ԍ例如successQ然后JSFҎ(gu)faces-config.xml中的配置Q蟩转到相应的页面。login的声明一般是String login();
当然也可以通过E序来添加监听器Q不q监听器c需要实现ActionListener接口Q?br />
3、Data model eventsQ数据模型事Ӟ
上面的代码攑օ初始化程序中Q当行的选择改变的时候就?x)触发相应的日志打印?br />
q是因ؓ(f)q段代码ldataTable控g定义了一个数据模型,数据和相应的事g全部存在q个数据模型里面Q然后将dataTable与这个模型进行绑定即可用它所有的数据和事件。点击dataTable上面的一行自然也׃(x)出发相应的行选择事g?
4.Phase eventsQ阶D事Ӟ
q个事g是ؓ(f)了捕捉一些阶D和q程而设定的Q有以下几个阶段可以捕捉Q?br />
具体可以参?/span>http://java.sun.com/javaee/javaserverfaces/1.1_01/docs/api/javax/faces/event/PhaseId.html
通过讑֮在实现类中设定相应的PhaseId以及(qing)d到faces-config.xml中就可以捕捉相应阶段事gq添加响应的代码
实现c?/span>
在faces-config.xml中添?br />
当然可以d无限个的监听?br />
下面是请求处理的生命周期Q大家可以直观的看一下各个阶D|行顺序:(x)
各个阶段的说明以?qing)所能触发的事g