Hi I'm totally new in java. I have some basics in c#. I want to make simple task. I added two buttons and a label to form. When you click first button you should get +value in the label. When you click second button you should get -value in the label. This is my code:
<?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"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<p:button value="Add" action="#{Number.addOne()}">
</p:button>
<p:button value="Substract" action="#{Number.subOne()}" >
</p:button>
<p:outputLabel id="result" value="#{Number.getNum()}"/>
</h:form>
</h:body>
</html>
Java code:
import javax.faces.bean.ManagedBean;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
@ManagedBean
@SessionScoped
public class Number implements Serializable{
private int num=0;
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public void addOne()
{
this.num+=1;
}
public void subOne()
{
this.num-=1;
}
}
Sth. is wrong in my code. In C# web forms there is onclick method but this technology is really different. Can someone show me the code which make my task properly and explain what i did wrong in my code?