vulturistic vulturistic - 1 month ago 6
Ajax Question

my table can't reload using ajax poll

i've been using ajax to my JSF to reload my table. I used jsf poll from primefaces.com. It's working when I'm only using it to increment a number but when I use it to refresh my page. It's not working anymore.

default.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>logs</title>

</h:head>
<h:body>
<center>
<h2>SMS Log</h2>
</center>
<h:form>
<h:outputText id="txt_count" value="#{sms.init}" />
<p:poll interval="1" listener="#{counterView.increment}"
update="txt_count" />
//other columns...
</p:dataTable>
</h:form>

</h:body>
</html>


the sms.init is my method that display table and counterView.increment is my listener that increments the number.

CounterView.java

public class CounterView implements Serializable {

/**
*
*/
private static final long serialVersionUID = 1L;
private int number;

public int getNumber() {
return number;
}

public void increment() {
number++;
}
}


SMSDataBean.java

public class SMSDataBean implements Serializable {


private static final long serialVersionUID = 1L;

private static String strLine = null;
private static List smslist = null;
private static String formattedString = null;
static List<SMSData> data = new ArrayList<SMSData>();


public String getInit() {
try{
data = new ArrayList<SMSData>();
FileInputStream fstream = new FileInputStream("C:/u01/app/tcsTest/LogClient/SMS/SMSLog.log");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
smslist = new ArrayList<>();
String str2;
/* read log line by line */
while ((str2 = br.readLine()) != null) {
/* parse strLine to obtain what you want */
str2 = str2.replace("s:{", "");
str2 = str2.replace("}", "");
str2 = str2.replace("'", "");

String[] split = str2.split("~~");
SMSData sms = new SMSData();

for(int i=0;i<split.length;i++){
String msisd[] = split[0].split("~*~");
String msg[] = split[1].split("~*~");
String from[] = split[2].split("~*~");
String date[] = split[3].split("~*~");
String resCode[] = split[4].split("~*~");
String resDesc[] = split[5].split("~*~");
String resMsg[] = split[6].split("~*~");

sms.setMsisdn(msisd[2]);
sms.setMessage(msg[2]);
sms.setFrom(from[2]);
sms.setDate(date[2]);
sms.setResCod(resCode[2]);
sms.setResDesc(resDesc[2]);
sms.setResMsg(resMsg[2]);


System.out.println("refreshing....");

}

strLine = str2;
smslist.add(strLine);
formattedString = smslist.toString().replace(",", "\n");

data.add(sms);
}

br.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
return "";
}
//getters and setters..


I configured it in faces-config.xml

<managed-bean>
<managed-bean-name>sms</managed-bean-name>
<managed-bean-class>main.java.com.mkyong.user.SMSDataBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

<managed-bean>
<managed-bean-name>counterView</managed-bean-name>
<managed-bean-class>main.java.com.mkyong.user.bo.CounterView</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>


my problem is that poll is not working with my table eventhough it's incrementing. When I tried it using just an incrementing number it's working. I can't see what's the problem. Thanks in advance for the help.

Answer

just add p:panel id="tobeupdated"

Comments