Jump to content

help adding input control


mkusterm

Recommended Posts

Hi, please help,

Am using the jasper 3.x webservice apis

to attempt to add an input control to a

new report unit and having no success so far.

 

My code is able to add a new report unit which

i can run from iReport and the server.

however the input controls do not appear even

though i get no errors when I am adding them.

 

please give guidelines on how to add basic

controls to report units.

 

here is my code:

 

ResourceDescriptor newParam = new ResourceDescriptor();

 

newParam.setWsType(ResourceDescriptor.TYPE_INPUT_CONTROL);

 

newParam.setResourceType(ResourceDescriptor.TYPE_INPUT_CONTROL);

 

newParam.setDataType(ResourceDescriptor.DT_TYPE_TEXT);

 

newParam.setName(cleanName);

 

newParam.setLabel(label);

 

newParam.setControlType(ResourceDescriptor.IC_TYPE_SINGLE_VALUE);

 

newParam.setIsNew(true);

 

newParam.setIsReference(true);

 

newParam.setReferenceUri(jrxmlDescriptor.getUriString() );

 

reportUnit.getChildren().add( newParam );

 

thanks in advance,

mike

Link to comment
Share on other sites

  • 1 month later...
  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

You are not showing all the code, but I can see some problems.

 

The following is wrong:

newParam.setIsReference(true);

newParam.setReferenceUri(jrxmlDescriptor.getUriString() );

 

Resources can be attached to a report unit directly, or by a reference. In the code you show, you are doing both at once, and the reference takes precedence.

 

Try removing those lines.

 

Sherman

Jaspersoft

Link to comment
Share on other sites

ok,

I figured this out.  I'm sure there are other ways to do this but this appears to work fine.  It's probably worth noting how I was able to figure this out for those of you that are just learning to use the jasper web services.

Essentially I started up jasper/tomcat in debug mode and attached to it running eclipse.  Then I set a break point in:

 

ManagementService.put

 

From here you can see the xmlrequest.  Then I used iReport to perform the same functions that I'm trying to perform from my application (this let's you see what a valid request should look like) and compared ireport's requests to my own.  From there it was pretty straight forward.  I hope this helps someone out!

 

Here is my code snippet:

 

    private ResourceDescriptor putReportUnit(ResourceDescriptor rd,
            String name, String label, String desc, File report, Map params)
            throws Exception {
        File resourceFile = null;

        ResourceDescriptor tmpDataSourceDescriptor = new ResourceDescriptor();
        tmpDataSourceDescriptor.setWsType(ResourceDescriptor.TYPE_DATASOURCE);
        tmpDataSourceDescriptor.setReferenceUri(reportUnitDataSourceURI);
        tmpDataSourceDescriptor.setIsReference(true);
        rd.getChildren().add(tmpDataSourceDescriptor);

        ResourceDescriptor jrxmlDescriptor = new ResourceDescriptor();
        jrxmlDescriptor.setWsType(ResourceDescriptor.TYPE_JRXML);
        jrxmlDescriptor.setName(name);
        jrxmlDescriptor.setLabel(label);
        jrxmlDescriptor.setDescription(desc);
        jrxmlDescriptor.setIsNew(true);
        jrxmlDescriptor.setHasData(true);
        jrxmlDescriptor.setMainReport(true);

        rd.getChildren().add(jrxmlDescriptor);
        rd.setResourceProperty(
                ResourceDescriptor.PROP_RU_ALWAYS_PROPMT_CONTROLS, true);
        ResourceDescriptor reportDescriptor = server.getWSClient()
                .addOrModifyResource(rd, report);

        //
        // if there are parameters for this report then add the input controls
        Iterator it = inputControls.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry entrySet = (Entry) it.next();
            String key = (String) entrySet.getKey();
            InputControlParameters ic = (InputControlParameters) entrySet
                    .getValue();

            //
            // add an input control for every key
            ResourceDescriptor jrxmlControl = new ResourceDescriptor();

            jrxmlControl.setWsType(ResourceDescriptor.TYPE_INPUT_CONTROL);
            // jrxmlControl.setDataType(ResourceDescriptor.DT_TYPE_TEXT);

            jrxmlControl
                    .setControlType(ResourceDescriptor.IC_TYPE_SINGLE_VALUE);
            jrxmlControl.setName(key);

            jrxmlControl.setLabel(ic.getLabel());
            jrxmlControl.setDescription(ic.getLabel());

            jrxmlControl.setVersion(2);
            jrxmlControl.setHasData(false);
            jrxmlControl.setMandatory(false);
            jrxmlControl.setIsNew(true);
            jrxmlControl.setIsReference(false);
            jrxmlControl.setStrictMax(false);
            jrxmlControl.setStrictMin(false);
            jrxmlControl.setReadOnly(false);
            jrxmlControl.setMainReport(false);
            jrxmlControl.setParentFolder(rd.getUriString() + "_files");
            // jrxmlControl.setReferenceUri(rd.getUriString() + "_files/" +
            // key);
            jrxmlControl.setUriString(rd.getUriString() + "_files/" + key);
            jrxmlControl
                    .setResourceType("com.jaspersoft.jasperserver.api.metadata.common.domain.InputControl");
            ResourceDescriptor dataTypeDescriptor = new ResourceDescriptor();
            // dataTypeDescriptor.setWsType(ResourceDescriptor.TYPE_DATA_TYPE);
            // dataTypeDescriptor.setDataType(ResourceDescriptor.DT_TYPE_TEXT);
            // dataTypeDescriptor.setName("String");
            // dataTypeDescriptor.setLabel("String");
            dataTypeDescriptor.setWsType(ResourceDescriptor.TYPE_REFERENCE);
            dataTypeDescriptor.setIsReference(true);

            if (ic.getType() == ReportFieldType.STRING)
                dataTypeDescriptor.setReferenceUri("/datatypes/String");
            else if (ic.getType() == ReportFieldType.DATE)
                dataTypeDescriptor.setReferenceUri("/datatypes/Date");
            else
                dataTypeDescriptor.setReferenceUri("/datatypes/Number");

            jrxmlControl.getChildren().add(dataTypeDescriptor);

            // server.getWSClient().addOrModifyResource(jrxmlControl, null);
            server.getWSClient().modifyReportUnitResource(rd.getUriString(),
                    jrxmlControl, null);

        }
        return reportDescriptor;
    }
 

Link to comment
Share on other sites

  • 5 years later...

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