I recently tried to write some simple JSF page using AJAX. It's basically just two numeric fields which are then added together in another
<head>
<style>
.standardText {
font-family: Arial, serif;
}
.result {
font-family: Arial, serif;
border-top: solid blue 5px;
text-align: right;
width: 30%;
}
.input-field {
font-family: Arial, serif;
font-weight: bold;
margin-left: 5px;
}
</style>
</head>
<h:body>
<h2 class="input-field">Type in your arguments and the glorious machine will tell you the <br/>
<span style="color: slateblue; text-overline: true;">TRUTH</span>!!</h2>
<h:form>
<p></p>
<h:outputLabel value="Your first argument" for="arg"/>
<h:inputText value="#{test.arg}" id="arg">
<f:ajax event="change" render="result"/>
</h:inputText>
<p></p>
<h:outputLabel value="Your second argument"
styleClass="standardText" for="arg2"/>
<h:inputText value="#{test.arg2}" id="arg2">
<f:ajax event="change" render="result"/>
</h:inputText>
<h:panelGroup layout="block">
<h:outputText value="Your result is: #{test.result}" id="result"/>
</h:panelGroup>
</h:form>
</h:body>
The bean is just as simple as the page: just the three properties arg
, arg2
and result
(The result is calculated in the getter).
package com.jsf;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import java.io.Serializable;
@Named("test")
@ViewScoped
public class Test implements Serializable {
private static final long serialVersionUID = 1L;
private Integer arg;
private Integer arg2;
private int result;
public int getResult() {
result = arg + arg2;
return result;
}
public Integer getArg() {
return arg;
}
public void setArg(Integer arg) {
this.arg = arg;
}
public Integer getArg2() {
return arg2;
}
public void setArg2(Integer arg2) {
this.arg2 = arg2;
}
}
When running the facelet and filling in a value, the result output doesn't change.
After some time of debugging, I'm guessing that two components cannot have the same render
target?
I've tried to group the h:form
under one f:ajax
tag - without sucess.
Ideas for a solution?