Im currently learning HTML/CSS/JSF and wrote a litte code snippet that doesnt run the way I want. So I have a JSF run WebApplication which includes only an image, an outputText and a commandLink.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<img src="logo.jpg" width="250" alt="LOGO"/>
<br/>
<h:outputText value="#{counter.counter}"/>
<h:form>
<h:commandLink value="increase Counter" action="#{counter.increaseCounter()}"/>
</h:form>
</h:body>
</html>
So the image source is a logo.jpg, which is in the same directory as the index.xhtml file and the counter value is loaded and increased from a Managed Bean.
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ApplicationScoped;
@ManagedBean
@ApplicationScoped
public class Counter {
private int counter = 0;
public Counter() {
}
public void increaseCounter() {
counter++;
}
public int getCounter() {
return counter;
}
}
When I load the page, everything is shown. The Image, the Counter with value 0 and the commandLink. As soon as I click on the commandLink the counter increases and the page reloads with counter value 1, but the Image isnt loaded anymore. After the reload it just shows the alt value.
Why doesnt it load the image again ? Do I make something wrong ? Thanks a lot for your help :)