Jump to content
We've recently updated our Privacy Statement, available here ×

Problem fixing a new Custom datasource


jagarrido

Recommended Posts

Hi all:

 

I need showing a graphic who obtain data from a custom datasource. I see the demo sample of datasources in the jasperreports1.2.5 package and I simulate that situation, but I don't find the static method in that sample for textfield "The static method to call to retrive the JRDataSource" who appears in Ireport1.2.5 when I try fixing a new custom datasource(test fail).

 

Mu custom DataSource sample code is:

package com.emergya.esteve.tcerebral.web.util;

 

import net.sf.jasperreports.engine.JRDataSource;

import net.sf.jasperreports.engine.JRException;

import net.sf.jasperreports.engine.JRField;

 

 

public class SupervivencyDataSource implements JRDataSource

{

 

private Object[][] data =

{

{new Integer(1), new Float(100)},

{new Integer(2), new Float(98.6)}

};

 

private int index = -1;

 

 

public SupervivencyDataSource()

{

}

 

 

public boolean next() throws JRException

{

index++;

 

return (index < data.length);

}

 

 

public Object getFieldValue(JRField field) throws JRException

{

Object value = null;

String fieldName = field.getName();

 

if ("mounth".equals(fieldName))

{

value = data[index][0];

}

else if ("percent".equals(fieldName))

{

value = data[index][1];

}

 

return value;

}

}

 

Any suggestions to resolve? Thank for all

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

You correctly wrota the datasource, now you need a factory class to instance it, something like:

 

Code:


package com.emergya.esteve.tcerebral.web.util;


public class SupervivencyDataSourceFactory {

public static JRDataSource createDatasource()
{

return new SupervivencyDataSource();

}

}

 

Giulio

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...