JSF & Ajax4jsf - Problem with a
Hi all!
I start working with JSF and Ajax4jsf technology a few weeks ago and i've reach a problem that I can't fix.
I can't understand or control why my application calls to the "setters" a second time, ignoring the value that i've set before that second call.
Here is an example:
JSP page:
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
<%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
<html>
<head>
<title></title>
</head>
<body>
<f:view>
<h:form>
<t:selectOneListbox id="lista" value="#{myProblem.list}"
valueChangeListener="#{myProblem.catchListValue}">
<f:selectItems value="#{myProblem.listItems}"/>
<a4j:support event="onchange" reRender="input" />
</t:selectOneListbox>
<t:inputText id="input" value="#{myProblem.text}"/>
</h:form>
</f:view>
</body>
</html>
Bean class:
package clases;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.faces.component.html.HtmlInputText;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
publicclass MyProblem{
// ATTRIBUTE METHODS
private String text ="Start";
private String list;
public String getText(){
return text;
}
publicvoid setText(String text){
System.out.println("[setText] text value before \"set\" --> " + this.text);
this.text = text;
System.out.println("[setText] text value after \"set\" --> " + this.text);
}
public String getList(){
return list;
}
publicvoid setList(String list){
this.list = list;
}
// CATCH METHOD
publicvoid catchListValue(ValueChangeEvent event){
System.out.println("[catchListValue]Before catching any value, text = " + this.text);
this.list = ((String)event.getNewValue());
System.out.println("[catchListValue]Value catched --> " + this.list);
setText(this.list);
System.out.println("[catchListValue]After catching the value, text = " + this.text);
}
// LIST METHODS
private List<SelectItem> listItems =null;
public List getListItems()throws SQLException{
if(listItems ==null)
initListItems();
return listItems;
}
publicvoid initListItems()throws SQLException{
listItems =new ArrayList<SelectItem>();
listItems.add(new SelectItem("o1","Option 1"));
listItems.add(new SelectItem("o2","Option 2"));
listItems.add(new SelectItem("o3","Option 3"));
listItems.add(new SelectItem("o4","Option 4"));
}
publicvoid setListItems(List<SelectItem> items){
listItems = items;
}
}
In this example I settextattribute to the value I select in the list but after that, the setText method is called again and set thetextattribute back to its initail value.
Can anyone help me, please?
I'm looking for an explanation for that second set and a way to control it, thanks.

