vulturistic vulturistic - 1 month ago 7
Java Question

my program doesnt read one of my static method

this is just a basic question and I'm just wondering why my program doesnt read one of my static method. I'm sorry I'm just a newbie here. Here's my code.

public class SMSDataBean implements Serializable {

private static final long serialVersionUID = 1L;
static File smsLogFile;
static String smsLogFilePath;
static PrintWriter printWriter;
static final String newLine = System.getProperty("line.separator");

private static final SMSLog[] smslog = new SMSLog[] {
new SMSLog("123", "test1", "31235", "jan 3", "4122", "test", "dsdaae")
};

public SMSLog[] getSmslog() {
return smslog;
}



public static class SMSLog {

String msisdn;
String message;
String from;
String date;
String resCod;
String resDesc;
String resMsg;

public SMSLog(String msisdn, String message, String from, String date,
String resCod, String resDesc, String resMsg) {
this.msisdn = msisdn;
this.message = message;
this.from = from;
this.date = date;
this.resCod = resCod;
this.resDesc = resDesc;
this.resMsg = resMsg;

}

public String getMsisdn() {
return msisdn;
}

public void setMsisdn(String msisdn) {
this.msisdn = msisdn;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public String getFrom() {
return from;
}

public void setFrom(String from) {
this.from = from;
}

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public String getResCod() {
return resCod;
}

public void setResCod(String resCod) {
this.resCod = resCod;
}

public String getResDesc() {
return resDesc;
}

public void setResDesc(String resDesc) {
this.resDesc = resDesc;
}

public String getResMsg() {
return resMsg;
}

public void setResMsg(String resMsg) {
this.resMsg = resMsg;
}
}



public static void printSMSRequest(String msisdn, String message,
String fromNo, String responseCode, String responseDescription,
String responseMsg) {
String msg;
try {
if (smsLogFile == null) {
smsLogFile = new File(smsLogFilePath);
}
if (!smsLogFile.exists())
smsLogFile.createNewFile();
printWriter = new PrintWriter(
new FileOutputStream(smsLogFile, true));
msg = "s:{'msdn':'" + msisdn + "','msg':'" + message + "','from':'"
+ fromNo + "','date':'" + new Date().toLocaleString()
+ "','resCode':'" + responseCode + "','resDesc':'"
+ responseDescription + "','resMsg':'" + responseMsg + "'}";
printWriter.write(newLine + msg);
} catch (IOException ioex) {
ioex.printStackTrace();
} finally {
if (printWriter != null) {
printWriter.flush();
printWriter.close();
}
msg = null;
}
}

public static String getSmsLogFilePath() {
System.out.println("pathhhhhhh: "+smsLogFilePath);
return smsLogFilePath;
}

public static void setSmsLogFilePath(String smsLogFilePath) {
SMSDataBean.smsLogFilePath = smsLogFilePath;
}

}


here's my faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>


<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>

</faces-config>


and here is my default.xhtml file

<?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">
<h:head>
<title>print</title>
<!-- <h:outputStylesheet library="css" name="styles.css" /> -->
</h:head>
<h:body>
<h2>DataTable Example</h2>
<h:form>
<h:dataTable value="#{sms.smslog}" var="smslog"
styleClass="employeeTable"
headerClass="employeeTableHeader"
rowClasses="employeeTableOddRow,employeeTableEvenRow">
<h:column>
<f:facet name="header">msisdn</f:facet>
#{smslog.msisdn}
</h:column>
<h:column>
<f:facet name="header">message</f:facet>
#{smslog.message}
</h:column>
<h:column>
<f:facet name="header">from</f:facet>
#{smslog.from}
</h:column>
<h:column>
<f:facet name="header">date</f:facet>
#{smslog.date}
</h:column>
</h:dataTable>
</h:form>
</h:body>
</html>


my program doesnt read the printSMSRequest method. Do I need to instantiate it? But as I read you don't need to instantiate the static method. Help please. Thanks. Sorry for my noob question.

Answer

check your <h:dataTable value="#{sms.printSMSRequest}" var="print" styleClass="employeeTable" headerClass="employeeTableHeader" rowClasses="employeeTableOddRow,employeeTableEvenRow"> if it's working or not. I think it has the problem.