Java Reference
In-Depth Information
for (String cd : part.getHeader("content-disposition").split(";")) {
if (cd.trim().startsWith("filename")) {
return cd.substring(cd.indexOf('=') + 1).trim()
.replace("\"", "");
}
}
return null;
}
To make the file upload component work with Ajax, simply embed the f:ajax tag and provide the same action
as the commandButton that is used in this example:
<h:inputFile id="ajaxUploadFile" value="#{ajaxBean.file}">
<f:ajax execute="@form" listener="#{ajaxBean.uploadFile}"/>
</h:inputFile>
The new file upload component is a welcome addition to the JSF family of components. Since a file upload
component is very oftentimes required within enterprise applications, it is now much easier because there are no
third-party libraries to depend upon for acquiring this functionality.
Stateless Views
In JSF, every view by default carries some amount of statefulness. That is, when users navigate from view to view,
some amount of state is persisted from view to view so that components can be rendered accordingly. In JSF, the
component tree state is initialized upon the first Facelet request. Upon each subsequent request, only partial state
changes are made, meaning that only the components within a view's component tree that require updating would
be added to the view state. This means that the view state is always changing, which may cause application issues,
depending upon a particular application's requirements. Therefore, an enhancement has been made in JSF 2.2,
allowing the existing “transient” attribute to be added to an <f:view> tag and set to a value of true , thereby marking
the view as stateless. When JSF encounters a view that contains a true transient attribute, the view's component state
saving is skipped.
Let's take a look at a simple example. The following JSF view has been flagged as stateless since the transient
attribute has been added to the <f:view> tag with a true value.
<html xmlns=" http://www.w3.org/1999/xhtml "
xmlns:f=" http://xmlns.jcp.org/jsf/core "
xmlns:h=" http://xmlns.jcp.org/jsf/html "
xmlns:ui=" http://xmlns.jcp.org/jsf/facelets " >
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Chapter 2 - Stateless View Example</title>
</h:head>
<h:body>
<ui:composition template="../layout/custom_template.xhtml">
<ui:define name="content">
<f:view transient="true">
<h:form>
<p>
<h:outputText value="This is a stateless view..." />
<br/>
 
Search WWH ::




Custom Search