I have this backing bean:
public class PageBean
{
private List<SelectItem> selectPages;
private List<SelectItem> selectRowsPerPage;
private String selectedPage;
private String selectedRowsPerPage;
private int pages = 0;
// getter methods
public boolean getRender()
{
boolean rendered = pages > 0? true: false;
return rendered;
}
public List<SelectItem> getSelectPages()
{
int value = 0;
selectPages = new ArrayList<SelectItem>();
for (int i = 1; i < (pages + 1); i++)
{
if (i > 1) { value = i * 10; }
selectPages.add(new SelectItem(Integer.toString(value), Integer.toString(i)));
}
return selectPages;
}
public String getSelectedPage()
{
if (selectedPage == null) {
selectedPage = "1";
}
return selectedPage;
}
// setter methods
public void setSelectPages(List<SelectItem> selectPages) {
this.selectPages = selectPages;
}
public void setSelectedPage(String selectedPage) {
this.selectedPage = selectedPage;
}
// action methods
public void changePage(ValueChangeEvent event)
{
PhaseId phase = event.getPhaseId();
if (phase.equals(PhaseId.INVOKE_APPLICATION)) {
System.out.println((String) event.getNewValue());
setSelectedPage((String) event.getNewValue());
FacesContext.getCurrentInstance().renderResponse();
} else {
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
event.queue();
}
}
}
And the h:selectOneMenu is:
<h:selectOneMenu id="page" value="#{pageBean.selectedPage}"
valueChangeListener="#{pageBean.changePage}" onchange="submit()">
<f:selectItems value="#{pageBean.selectPages}" />
</h:selectOneMenu>
The above codes for the changePage() method do not return the new selected page value from the h:selectOneMenu. Instead, it returns the page value prior to submit. I don't understand why.
Can someone please help? Have been stuck on this for 2 days now.