updating rich:dataTable contents
techbrainless Apr 6, 2011 4:41 AMHi All,
I have created(using jsf1.2 and richfaces) a page which list the students , when the page opens it lists all the students ,
For the purpose of search I have tried to use filterBy but the problem with it , it allows fitlering based on first character , that is why I have added to the page inputtext to search for a particular student name (even so if the typed character is at the middle of the name),
the problem is that when i search for a student i got the desired result for search but the datatable contents will not be updated accroding to the search result
any way to fix this issue ?
listStudents.xhtml
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<f:loadBundle basename="resources" var="msg" />
<ui:composition template="/templates/common.xhtml">
<ui:define name="pageTitle">#{msg.studentsManagement}</ui:define>
<ui:define name="pageHeader">#{msg.studentsManagement}</ui:define>
<ui:define name="body">
<h:form>
<rich:panel id="studentsPanel" header="#{msg.studentsList}" rendered="true">
<table align="center">
<tr>
<td><h:outputLabel value="#{msg.studentName}"
for="studentName" /></td>
<td><h:inputText id="studentName"
value="#{studentInfoListBean.searchedStudentName}" /></td>
<td><a4j:commandLink
actionListener="#{studentInfoListBean.search}"
reRender="studentsPanel,studentsList,errMessage,pan,delete,edit" value="#{msg.search}" /></td>
</tr>
<tr>
<td colspan="3" align="center"><h:outputLabel
value="#{studentInfoListBean.errorMessage}" id="errMessage"
style="color:red;" /></td>
</tr>
</table>
<rich:dataTable binding="#{studentInfoListBean.table}"
align="center" id="studentsList" rows="10"
value="#{studentInfoListBean.studentsInfo}"
var="student" rendered="true">
<rich:column sortBy="#{student.studentName}">
<f:facet name="header">
<h:outputText value="#{msg.studentName}" />
</f:facet>
<h:outputText value="#{student.studentName}" />
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="#{msg.edit}" />
</f:facet>
<h:graphicImage value="/images/edit.gif" />
<a4j:commandLink immediate="true"
actionListener="#{studentInfoListBean.editStudentInfo}"
value="#{msg.edit}"
rendered="#{userInfo.userAccessRights.editStudentInfo}">
<f:setPropertyActionListener value="#{student}"
target="#{requestScope.selectedStudentInfo}" id="edit"/>
</a4j:commandLink>
</rich:column>
<rich:column>
<f:facet name="header">
<h:outputText value="#{msg.delete}" />
</f:facet>
<h:graphicImage value="/images/delete.gif" />
<a4j:commandLink reRender="studentsPanel"
actionListener="#{studentInfoListBean.deleteStudentInfo}"
value="#{msg.delete}"
rendered="#{userInfo.userAccessRights.deleteStudentInfo}" id="delete"></a4j:commandLink>
</rich:column>
</rich:dataTable>
<rich:datascroller align="center" for="studentsList" maxPages="20" />
<h:graphicImage value="/images/create.gif" />
<a4j:commandLink
actionListener="#{studentInfoListBean.addStudentInfo}"
value="#{msg.addNewStudent}"
rendered="#{userInfo.userAccessRights.addStudentInfo}"></a4j:commandLink>
<span>&nsbp;&nsbp;&nsbp;</span>
</rich:panel>
</h:form>
<a4j:include id="pan" viewId="#{dialogManager.currentDialogURI}" rendered="true"></a4j:include>
</ui:define>
</ui:composition>
</html>
StudentInfoListBean.java
import com.student.api.StudentInfo;
import com.student.backoffice.api.exception.StudentInfoException;
import com.student.backoffice.api.managers.IStudentInfoManager;
import com.student.backoffice.utilities.Log;
import org.richfaces.component.UIDataTable;
import java.util.List;
import javax.faces.event.ActionEvent;
public class StudentInfoListBean extends BaseBean {
private IStudentInfoManager studentInfoManager;
private UIDataTable table;
private String errorMessage;
private String clearErrorMessage;
private DialogManager dialogManager;
private String searchedStudentName;
private List<StudentInfo> studentsInfo;
/**
* Creates a new UserInfoListBean object.
*/
public StudentInfoListBean() {
Log.getLogger().info("#####StudentInfoListBean Constructor");
}
public UIDataTable getTable() {
return this.table;
}
public void setTable(UIDataTable table) {
this.table = table;
}
public String getErrorMessage() {
return this.errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public String getClearErrorMessage() {
return this.clearErrorMessage;
}
public void setClearErrorMessage(String clearErrorMessage) {
this.clearErrorMessage = clearErrorMessage;
}
/**
* DOCUMENT ME!
*
* @param students DOCUMENT ME!
*/
/**
* DOCUMENT ME!
*
* @param ae DOCUMENT ME!
*/
/**
* DOCUMENT ME!
*
* @param ae DOCUMENT ME!
*/
public List<StudentInfo> getStudentsInfo() {
List<StudentInfo> studentsInfo = null;
try {
if ((this.searchedStudentName != null)
&& (this.searchedStudentName.trim().length() > 0))
studentsInfo = this.studentInfoManager
.getStudentsInfo(this.searchedStudentName);
else
studentsInfo = this.studentInfoManager.getStudentsInfo();
} catch (StudentInfoException e) {
e.printStackTrace();
}
Log.getLogger(this.getClass())
.debug("The students size is " + studentsInfo.size());
return studentsInfo;
}
/**
* @return the studentInfoManager
*/
public IStudentInfoManager getStudentInfoManager() {
return studentInfoManager;
}
/**
* @param studentInfoManager the studentInfoManager to set
*/
public void setStudentInfoManager(IStudentInfoManager studentInfoManager) {
this.studentInfoManager = studentInfoManager;
}
/**
* @return the dialogManager
*/
public DialogManager getDialogManager() {
return dialogManager;
}
/**
* @param dialogManager the dialogManager to set
*/
public void setDialogManager(DialogManager dialogManager) {
this.dialogManager = dialogManager;
}
public void addStudentInfo(ActionEvent ae) {
this.dialogManager.openDialog(ae, "addStudentInfo");
}
/**
* DOCUMENT ME!
*
* @param ae DOCUMENT ME!
*/
public void deleteStudentInfo(ActionEvent ae) {
try {
StudentInfo studentInfo = (StudentInfo) this.table.getRowData();
this.studentInfoManager.deleteStudentInfo(studentInfo);
} catch (StudentInfoException e) {
Log.getLogger(this.getClass())
.error("Unable to to delete the student info. Reason [ " +
e.getMessage() + " ]");
e.printStackTrace();
}
}
/**
* DOCUMENT ME!
*
* @param ae DOCUMENT ME!
*/
public void editStudentInfo(ActionEvent ae) {
StudentInfo studentInfo = (StudentInfo) this.table.getRowData();
Log.getLogger().debug("#####selected Student id :"+studentInfo.getStudentId()+" and name :"+studentInfo.getStudentName());
this.dialogManager.openDialog(ae, "editStudentInfo");
}
public void search(ActionEvent ae) {
this.studentsInfo = getStudentsInfo();
}
public String getSearchedStudentName() {
return searchedStudentName;
}
public void setSearchedStudentName(String searchedStudentName) {
this.searchedStudentName = searchedStudentName;
}
public void setStudentsInfo(List<StudentInfo> studentsInfo) {
this.studentsInfo = studentsInfo;
}
}