loading xml file problem in jboss developer studio managed bean
jayesh_rhds Jun 28, 2011 3:14 AMI am using JBoss developer Studio 4 GA and JBoss 6x. I am trying to implement Richfaces Data Table Sorting from this link. I have created the jsf project and redirected to the page containing sample code given in the website. I have created managed beans for capitalsBean, capitalsSortingBean, capital, capitalsParser in the faces-config. I have included the java classes as found here.
On running the project i get the error :
Unable to set property capitals for managed bean capitalsBean
I have used the sample java class file:
package org.richfaces.demo.tables;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import org.richfaces.demo.tables.model.capitals.Capital;
@ManagedBean
@SessionScoped
public class CapitalsBean implements Serializable{
/**
*
*/
private static final long serialVersionUID = -1509108399715814302L;
@ManagedProperty(value = "#{CapitalsParser.capitalsList}")
private List<Capital> capitals;
public CapitalsBean() {
// TODO Auto-generated constructor stub
}
public List<Capital> getCapitals() {
return capitals;
}
public void setCapitals(List<Capital> capitals) {
this.capitals = capitals;
}
}
This uses the capitalParser class:
package org.richfaces.demo.tables.model.capitals;
import java.net.URL;
import java.util.List;
import javax.faces.FacesException;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@ManagedBean
@ApplicationScoped
public class CapitalsParser {
private List<Capital> capitalsList;
@XmlRootElement(name = "capitals")
private static final class CapitalsHolder {
private List<Capital> capitals;
@XmlElement(name = "capital")
public List<Capital> getCapitals() {
return capitals;
}
@SuppressWarnings("unused")
public void setCapitals(List<Capital> capitals) {
this.capitals = capitals;
}
}
public synchronized List<Capital> getCapitalsList() {
if (capitalsList == null) {
//ClassLoader ccl = Thread.currentThread().getContextClassLoader();
//URL resource = ccl.getResource("pages/capitals.xml");
JAXBContext context;
try {
context = JAXBContext.newInstance(CapitalsHolder.class);
CapitalsHolder capitalsHolder = (CapitalsHolder)context.createUnmarshaller().unmarshal(new FileInputStream("/pages/capitals.xml"));
capitalsList = capitalsHolder.getCapitals();
}catch (JAXBException e) {
throw new FacesException(e.getMessage(), e);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
return capitalsList;
}
}
At times I am able to see just the table column headers without any error displayed and any data displayed. At other times i get the error of property mentioned above. Is there anything wrong in referencing the capitals.xml file? or is there any other error?
With regards,
Jayesh
-
jsfHello.rar.zip 3.0 MB