Call Java From Javascript (Birt) - java

I want to call Java object from within javascript in my rptdesign file (which is under a report project), after i put the jar of my class in /Web-Inf/lib directory and the .class in Web-Inf/classes i tried something like this in the open event of the data set:
gsh = new Packages.de.vogella.birt.stocks.daomock.StockDaoMock();
stock = gsh.getStockValues();
de.vogella.birt.stocks.daomock is the name of a package located in a Java Project (ClassPackage) under /src
StockDaoMock is the name of the class.
getStockValues() is the method.
But I get this error:
cannot evaluate the script. data set script method fetch returned null.expected a boolean value.
What is wrong?
I tried to replace all the code in the fetch method by
"system.out.println("essai");
return true;"
and still have this error
"Data Set script method "Fetch" returned null; expected a Boolean value."

Enable logging to see the stack trace. See the wiki.
Make sure the exception is logged (the example just logs the message) :-)
"Quick and Dirty Logging" might also help.
You might also have a classloader issue. See this blog post for classloader options and how to debug bundle discovery by OSGi when using BIRT.
[EDIT] The error message means that you forgot return true; or return false; at the end of the fetch method.

The java runs on the server, and javascripts runs in the browser, so it is obvious you can't call Java from javascript directly.
There is a library called DWR (Direct Web Remoting). It can expose Java method to Javascript methods. When you call the Javascript it makes a AJAX request, then DWRServlet handles it, executes your desired Java method, and returns the method result to the browser.

Related

Cannot search movies in Neo4j Movies sample application

On Ubuntu 16.10 I have followed the instruction from:
https://github.com/neo4j-examples/movies-java-spring-data-neo4j-4
But when I go to http://localhost:8080/ and try to search for e.g. Matrix nothing happens, it just looks empty:
I have verified that the neo4j db has been populated with the required data and I also updated user/pass in the .properties file in the maven project.
Any ideas, and is it possible to find a log somewhere?
Pressing F12 in Firefox gives:
Indicating the error in the sources as described in the below answer, did not manage to get the same error info in Chrome when pressing F12 though.
The code in the GitHub project is not properly updated. The MovieRepository.java class has findByTitleContaining method and #param is missing in this method. If you check the index.html file, javascript code is executing /movies/search/findByTitleLike?title=* URL. The quick fix will be add following method in MovieRepository.java and then execute mvn spring-boot:run command again.
Collection<Movie> findByTitleLike(#Param("title") String title);
In order to have proper source and test classes, you should replace findByTitleContaining method with findByTitleLike method in MovieRepository.java class and also fix the MovieRepositoryTest.java class to use the correct method. Delete testFindByTitleContaining method and add following method in MovieRepositoryTest.java class.
#Test
public void testFindByTitleLike() {
String title = "Matrix";
Collection<Movie> result = instance.findByTitleLike("*"+title+"*");
assertNotNull(result);
assertEquals(1, result.size());
}

Java method that writes to file does nothing when invoked from a JSP

Hey, all! I have a class method who's primary function is to get a Map object, which works fine; however, it's an expensive operation that doesn't need to be done every time, so I'd like to have the results stored in an XML file using JAXB, to be read from for the majority of calls and updated infrequently.
When I run a class that calls it out of NetBeans the file is created no problem with exactly what I want -- but when I have my JSP call the method nothing happens whatsoever, even though the rest of the information is passed normally. I have the feeling it's somehow lacking write privileges, but the file is just in the root directory so I'm not sure what I'm missing. Thanks for the help!
The code looks roughly like this:
public class DataHandler() {
...
public void config() {
MapHolder bucket = new MapHolder();
MapExporter exp = new MapExporter();
Map map = makeMap();
bucket.setMap(map);
exp.exportMap(bucket);
}
}
And then the JSP has a javabean of Datahandler, and this line:
databean.config();
It's probably a tad more fragmented than it needs to be; the whole bucket rigamarole was because I was stumbling trying to learn how to write a map to an xml file. Mapholder is just a class that I wrap around the map, and MapExporter just uses a JAXB marshaller, and it all does work properly when run from NetBeans.
OK turns out I'm just dumb; everything was working fine, the file was just being stored in a folder at the localhost location. Whoops! That'd be my inexperience with web development at work.

Google App Engine doesn't execute print statements

I just added some print statements to see what arguments are actually being passed to the methods, but nothing is ever printed to the console. For instance, I have:
#ApiMethod(name = "getListings")
public List<Listing> getListings() {
System.out.println("Getting listings");
return ofy().load().type(Listing.class).list();
}
If I make a change to the return statement (e.g. adding a filter), I can see the changes, but it never prints anything. Does anybody know what's going on here?
I use https://code.google.com/p/gwt-log/ Works with objectify just fine.
This way client code and server code can use the same logging statements. [That's useful since if I'm offline and can't call the server, I'll try handling stuff locally]. So it'll work fine in shared code and objectify objects that are being sent to/from the client/server.
See https://code.google.com/p/gwt-log/wiki/GettingStarted but basically the steps are:
1) configure *.gwt.xml
<!-- For development, a default of `DEBUG` is recommended -->
<inherits name="com.allen_sauer.gwt.log.gwt-log-DEBUG" />
2) import to your java code
import com.allen_sauer.gwt.log.client.Log;
3) log
Log.debug("Getting listings");
System.out does not write to the App Engine logs. System.err does.
Use java.util.logging. It's usually helpful to use a facade for j.u.l like http://www.slf4j.org/
In server-side programming, console print statements are generally not used.

ProgramCallDocument connecting to AS400 from Groovy Hangs

This question is specifically related to the JT400 class ProgramCallDocument, with it's method callProgram(String ProgramName)
I've tried wapping the call in a try/catch - but it's not throwing an exception, the debugger goes into the callProgram method, and just sits there indefinitely.
A small amount of specific information about the API is available here:
http://publib.boulder.ibm.com/infocenter/iadthelp/v7r0/index.jsp?topic=/com.ibm.etools.iseries.toolbox.doc/rzahhxpcmlusing.htm
Here's the code that I'm running:
AS400 as400System = AS400Factory.getAS400System()
ProgramCallDocument programCallDocument = new ProgramCallDocument(as400System, "com.sample.xpcml.Sample.xpcml")
programCallDocument.setStringValue("sampleProgramName.value", sampleValue)
Boolean didProgramCallDocumentRunSuccessfullyOnTheAS400 = programCallDocument.callProgram("sampleProgramName")
The last line of that snippet is the one that just sits there. I left out the try/catch for brevity.
The XPCML file that the ProgramCallDocument constructor uses is just a proprietary XML format that IBM uses for specifying the parameter lengths and types for a program call. I can come back and add it in if it would be helpful, but the ProgramCallDocument constructor runs validation on the XML, and it didn't come up with any validation errors. I'm not familiar with JT400, or how it does Program Calls, so any assistance would be wonderful.
As a further note, doing some more digging on a related issue today I also found this SO post:
Monitor and handle MSGW messages on a job on an IBM i-series (AS/400) from Java
I think it's relevant to this question, because it's about ways to trap MSGW status on the Java/Groovy side.
It's very likely the called program went into a MSGW status (error).
Check WRKACTJOB JOB(QZRCSRVS) to find the program call job and see the status as well as review the job log.
It may be easier to call a native program using the CommandCall class or as a JDBC stored procedure.
Here's an example of the CommandCall usage in Groovy:
sys = AS400Factory.AS400System
cmd = new CommandCall(sys)
if (!cmd.run "CALL MYLIB.MYPGM PARM('${sampleValue}')") {
println cmd.messageList
}

Variable not reachable without exception

I have a very weird problem, the classic of works on localhost and not in server.
I've tried to find a bigger problem and discovered that this code :
<div class="pageHeader"><h1>Products2 #{products.debug} </h1></div>
When :
#ManagedBean(name="products")
#SessionScoped
public class ProductsBean {
private String debug = "Debug : ";
public ProductsBean() {
debug = "Debug : ";
}
public String getDebug() {
return debug;
}
public void setDebug(String debug) {
this.debug = debug;
}
And the debug string has getters/setters,
Works perfectly in localhost but not on remote. In the remote server it doesn't echo the string at all, and no exception gets thrown and I have no idea how to start looking for the problem. The thing is that this problem gets repeated in other ways, for instance this page has a dataTable which appears empty, though it's not in localhost. when I tried file uploading in an whole different page I got exception of Target Unreachable, identifier resolved to null, which is not the problem in this case, but it seems to be related somehow I guess
Any help? I'm running on Oracle Linux Server with Oracle GlassFish
The problem is here.
Target Unreachable, identifier 'loadSimCards' resolved to null
I believe #loadSimCards resolved to null during processing.
The object is not getting created/prepopulated in your bean.
Check the code and verify if it is indeed getting populated.
You can post your Java code if you are still facing issues.
Also check beans.xml file and declaration in faces-config.xml
Reference - JEE CDI tip: Target Unreachable, identifier resolved to null
The first step in my mind would be to do a Right Click -> View Source in the browser and let us know what it shows. In the view source if the string "#{products.debug} is not getting printed, it means that the server is indeed evaluating the EL Expression, but at the time of rendering it is coming as an empty string.
Can you please provide the actual getters/setters.
Can you put loggers/SOPs in them and let us know whether they are being called and in what sequence.
Replace the pure EL Expression with a data-binding control like h:inputText and see what happens.
< h:inputText value="#{products.debug}" />
Probably unrelated, but do you have a < base /> tag declared in your page in the head section? Base tag href provides the location from which child resources are loaded. I have seen some abnormal behavior in the past while shifting servers, when the main page is loaded from from the remote while the child resources are loaded from the localhost itself on your developer box, because one forgets to change the base tag reference.

Categories

Resources