Skip to main content

Ajax bug?

4 replies [Last post]
gabox01
Offline
Joined: 2007-04-22
Points: 0

Hi,

I have an ajax problem. I have narrowed down my production code:

package beszterv.view;

import java.util.ArrayList;

import java.util.List;

import javax.annotation.PostConstruct;

import javax.faces.bean.ManagedBean;

import javax.faces.bean.SessionScoped;

import javax.faces.component.UIColumn;

import javax.faces.component.UIData;

import javax.faces.component.html.HtmlCommandButton;

import javax.faces.component.html.HtmlOutputText;

import beszterv.util.JSFUtils;

@ManagedBean

@SessionScoped

public class TestBean {

private UIData dataTable;

private List numbers = new ArrayList();

public TestBean() {

this.dataTable = new UIData();

}

public String addNewNumber() {

numbers.add("four");

return null;

}

public UIData getDataTable() {

return dataTable;

}

public void setDataTable(UIData dataTable) {

this.dataTable = dataTable;

}

public List getNumbers() {

return numbers;

}

public void setNumbers(List numbers) {

this.numbers = numbers;

}

private UIData populateDataTable(UIData dataTable) {

UIColumn col = new UIColumn();

dataTable.getChildren().add(col);

HtmlOutputText sequenceOutput = new HtmlOutputText();

sequenceOutput.setValueExpression("value", JSFUtils.createValueExpression("#{number}", String.class));

col.getChildren().add(sequenceOutput);

col = new UIColumn();

dataTable.getChildren().add(col);

HtmlCommandButton bt = new HtmlCommandButton();

bt.setId("btNewNumber");

bt.setActionExpression(JSFUtils.createMethodExpression("#{testBean.addNewNumber}", String.class));

bt.addActionListener(new BeszTervEditListener());

bt.setValue("Add");

JSFUtils.addAjaxBehaviour(bt, "click", "@all", "@all");

col.getChildren().add(bt);

return dataTable;

}

@PostConstruct

public void init() {

numbers.add("one");

numbers.add("two");

numbers.add("three");

this.dataTable = populateDataTable(dataTable);

}

}

When i press the button, the action method don't get invoked. Why is that?
Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gabox01
Offline
Joined: 2007-04-22
Points: 0

I solved the problem by passing null, to event attribute of f:ajax tag.

gabox01
Offline
Joined: 2007-04-22
Points: 0

No i don't it just submits. No ajax involved.

gabox01
Offline
Joined: 2007-04-22
Points: 0

My addAjaxBehavour method:

public static void addAjaxBehaviour(UIComponentBase component, String event, String execute, String render) {
Collection executes = new ArrayList();
executes.add(execute);

Collection renders = new ArrayList();
renders.add(render);

AjaxBehavior ajaxBehavior = new AjaxBehavior();
ajaxBehavior.setExecute(executes);
ajaxBehavior.setRender(renders);

component.addClientBehavior(event, ajaxBehavior);
}

driscoll
Offline
Joined: 2003-06-06
Points: 0

Instead of "click", try "action".