
This simple tip is an example of how to redirect without submit button using the JavaScript onclick:
<form>
<input type="button" value="To Page" onClick="location.href='newpage.html'">
</form>
Because I am constantly busy working on something, I have never had time to actually put everything in words and pictures. But, since you got here, then you must have already seen some part of my work - and this is the way I’m talking.I'm 23, born in Romania, student at UPG Romania in software development field. I started from 0, mostly with basic stuff, and I’m evolving every day to an expert. I'm focused on freelancing projects, from small websites, to really heavy stuff. I know that I look and act differently from most developers, but this is why you will love to work with me!

<p:graphicImage id="avatarImageId" url="#{uploadBean.avatarUrl}" width="50" height="50"/>And, the upload component look like this:<h:form enctype="multipart/form-data" prependId="false">
<p:fileUpload id="uploadAvatarId" fileUploadListener="#{uploadBean.handleAvatarUpload}"
update="avatarImageId,uploadMessages" sizeLimit="102400" multiple="false"
label="choose" auto="false" allowTypes="*.jpg;" description="Images"/>
</h:form>
As you probaly know, <p:fileUpload> component provides PPR integration "FileUpload is powered by PrimeFacs Partial Page Rendering so after a file is uploaded you can update any JSF component." - http://www.primefaces.org:8080/prime-showcase/ui/fileUploadUpdate.jsf, and this is exacly what the update attribute should do....
Random random = new Random();
String randomString = String.valueOf(random.nextInt(100000));
avatarUrl = "../resources/scripts/web/avatars/" + localAvatar + ";" + randomString;
...
…
<h:form enctype="multipart/form-data" prependId="false">
<p:growl id="messages" showSummary="true" showDetail="true" />
<p:fileUpload fileUploadListener="#{uploadBean.handleFileUpload}"
update="messages" sizeLimit="1073741824"
multiple="true" label="choose" allowTypes="*.jpg;*.png;*.gif;"
description="Images"/>
</h:form>
…The PrimeFaces p:growl component “brings the Mac's growl widget to JSF with the ability of displaying FacesMessages. Growl simply replaces h:messages component.”public class UploadBean {
private static final int BUFFER_SIZE = 6124;
/** Creates a new instance of UploadBean */
public UploadBean() {
}
public void handleFileUpload(FileUploadEvent event) {
ExternalContext extContext = FacesContext.getCurrentInstance().
getExternalContext();
File result = new File(extContext.getRealPath
("//WEB-INF//upload") + "//" + event.getFile().getFileName());
try {
FileOutputStream fileOutputStream = new FileOutputStream(result);
byte[] buffer = new byte[BUFFER_SIZE];
int bulk;
InputStream inputStream = event.getFile().getInputstream();
while (true) {
bulk = inputStream.read(buffer);
if (bulk < 0) {
break;
}
fileOutputStream.write(buffer, 0, bulk);
fileOutputStream.flush();
}
fileOutputStream.close();
inputStream.close();
FacesMessage msg = new FacesMessage("Succesful",
event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (IOException e) {
e.printStackTrace();
FacesMessage error = new FacesMessage("The files were
not uploaded!");
FacesContext.getCurrentInstance().addMessage(null, error);
}
}
}The upload example is ready, but we still need to add some configuration in web.xml descriptor (these configurations are not altering the PrimeFaces default configurations). These are specific to upload process and they are listed next:<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>• optionally, you may specify a temporary folder for storing the uploaded files, like this:<init-param>
<param-name>uploadDirectory</param-name>
<param-value>/tmp/fileUpload</param-value>
</init-param>• add the PrimeFaces FileUpload Filter as a filter for the Faces Servlet (keep in mind that this should be the first filter in web.xml, if you have more):<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>
org.primefaces.webapp.filter.FileUploadFilter
</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
Now, if test our upload you will see something like in figure below:
<h:form id="form">
<h:panelGrid columns="3">
<h:outputLabel for="email" value="Email Address:" />
<h:inputText id="email" value="#{bean.email}" label="Email">
<rich:beanValidator summary="Invalid Email address"/>
</h:inputText>
<rich:message for="email"/>
<h:outputLabel for="age" value="Age:" />
<h:inputText id="age" value="#{bean.age}" label="Age">
<rich:beanValidator
summary="Invalid age, must be between 18 and 90"/>
</h:inputText>
<rich:message for="age"/>
</h:panelGrid>
<h:commandButton value="Submit"></h:commandButton>
<rich:messages/>
</h:form>The validator restrictions are specified in Hibernate style using the corresponding annotations in a bean. In our example, the Bean bean looks like below:package bean;
import org.hibernate.validator.Email;
import org.hibernate.validator.Range;
import org.hibernate.validator.NotEmpty;
public class Bean {
private String email;
private Integer age;
@Range(min=18, max=90)
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@NotEmpty
@Email
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
For more Hibernate validators check the org.hibernate.validator package. In our example we have used the @Email, @NotEmpty and @Range validators.
<form name="formId">
<select id = "listId" name="listName" size="1">
<option value="value_1">Value 1
<option value="value_2">Value 2
<option value="value_3">Value 3
</select>
</form>Now, the JavaScript code can enable/disable this list like below://enabled
document.formId.listId.disabled = false;
//disabled
document.formId.listId.disabled = true;

<img id="imgId" src="picture.gif" width="1" height="1">Now, we can show/hide the picture from JavaScript, like this://show
document.getElementById("imgId").setAttribute("width", 20); //20 is just an example
document.getElementById("imgId").setAttribute("height", 20);
//hide
document.getElementById("imgId").setAttribute("width", 1);
document.getElementById("imgId").setAttribute("height", 1);

<input id="buttonId" type="button" value="Button Label"/>Now, we can use the id attribute to enable/disable this button like below://enabled
document.getElementById("buttonId").disabled = true;
//disabled
document.getElementById("buttonId").disabled = false;