Displaying a string, from an array within an array with JasperReports - java

I currently use iReport 5.1.0, Tomcat 7, Java, Spring MVC amongs other things.
I believe my current problem lies within the iReport itself, although it may be more complex.
I currently have an Object (Guide),
My Guide has a list of Objects, (itemsGuide)
My itemsGuide has a list of Objects, (itemsTeam)
My itemsTeam has a list of Objects, (professional)
My professional has a name.
My jasper file, receives as parameter the Guide, in the iReport software I must assign the fields and the current variables, although I must print, in a single line, parameters from the itemsTeam object (a couple of strings), and in this very specific case I will always have only one professional, although the variable lies within a list, therefore I must access the first object in this array to then display its attribute.
I keep getting the most unusual errors as I try to do this rather simple process.
The iReport either doesn't find the variables in itemsTeam or the ones in professional, when, for some unknown reason it "works" my preview of the PDF (it says "The document has no pages", to avoid the error msg I change the attribute in my report proprety, but now, it simple shows the iReport file without any field/variable, only the graphical elements).
I am utterly confused, would anyone be so kind as to lend a hand to this poor newcomer?
the JRXML file has over 37k characters and I can't post it as an edit, I uploaded as a txt file insted.
Thanks in advance.
No more need for the link to the xml ~
-- CATURDAY EDIT --
Allright, I seem to be getting closer to my solution.
At this point I've tried quite a few different approaches to my problem.
Although I couldn't completely solve it, I managed to get closer, or so I believe.
Now, all I have to find out (it seems) is:
How to access an array within an array.
I managed my way around the guide and the itemsGuide, I can't access the array within itemsGuide, I need to access a variable named "team" within that array (itemsGuide) and then print the value of a few strings in this array (which is of a specific class, itemsTeam) and a string in an object (professional).
All this, without subreport.
Anyone ?
Allright, what I spent about 4 days trying to find out, my co-worker with more experience than me found out in about 20 minutes.
The issue wasn't within iReports itself, it was necessary to create methods in the class in order to return the desired object/list, something I did not even consider given that I know very little of how iReports (and java honestly) works.
But according to what I understood from what has been done it has something to do with reflection and a couple of methods in the java class.
Thanks guys. :>

Related

two dimensional array in a UML diagram

Whenever i try to display a two dimensional array object in a diagram using NClass for example it keeps giving me an error saying its invalid declaration, however it doesn't give any error using a 1 dimensional array. Any tips would be appreciated
I have posted a screenshot of the error
enter image description here
It's so difficult to discover what the tool is used in your question. In any way, the same tools support the object description, relations etc. From your screen, I can guess, that your soft don't support java format of description like: "int[][] board" and attribute "protected". I can guess that you need to write only "int[][] board" or only "board" and in its description int[][], but attribute "protected" you need to write in another place.

Correct way to represent repeated data in stream

Any advice on how to support repeated messages? Specifically, if these message are all one type. In JSON, these would essentially be an array. In my case, I do not care about indexing however, but that is not saying that an array type would not be useful for protobuf. I have considered the below approaches, but I don' like the tradeoff's. It ins't clear from reading the Google documentation which approach is meant to be used for collections.
Use any existing message and just have a bunch of empty fields
You can use an existing type and just only include the desired collection of repeated messages. So if a user message type has repeated photo message type, send an empty user with nothing but the photo collection field.
Create a wrapper type
This is what #1 does but instead of using an existing type, create a new one. This is a little cleaner because it is explicit and doesn't use empty fields. Still has message typing too. In photo case, this would be an ArrayOfPhotos message w/ only repeated photo message field.
Use delimited stream
Not too sure about this method as I haven't tried it, but protobuf supports delimiting streams. This seems cool, but I would imagine it has downside of less strong typing. Streams could contain a grab bag of different message types.
Does seem beneficial though that this option requires no extra Message types.
In photo case, this would be delimited photo messages, but again, seems like you could throw user messages in as well.
It sounds like you're trying to ask what to do when your top-level data is an array rather than a record. (It isn't totally clear from your question whether you're asking about top-level, but otherwise I don't understand the problem.)
The questions to ask yourself are:
Is there any chance that some day you'll want to add some auxiliary data to this message which is not attached to any one of the objects? For instance, maybe your list of photos will some day have an album name attached. In this case, you certainly want to use your solution #2, since it gives you the flexibility to add other fields later without messing up some existing message type.
Will it be a problem for the client or the server to have to hold the entire data set in memory and parse/serialize it all at once? This is a requirement for a single message. For example, if you're sending 1GB of photos, you probably want each end to be able to handle one or just a few photos at a time. In this case you certainly want solution #3.
I would not advise using solution #1 in any case.

Update objects written to a text files in java

Writing Java objects or a List into a text file is ok. But I want to know how I can update or rewrite a object which was written previously without writing objects again. For example, let s assume there is a java.util.List has a set of Objects. and then that list is written to a text file. Then later that file will be read again and get all objects from list and then change one object's value at run time by a java application. Then I don't need to write entire list back to the text file. Instead only the updated object in the list is required to be rewritten or updated in the text file without rewriting the whole list again. Any suggestion, or helpful source with sample codes please.
Take a look at RandomAccessFile. This will let you seek to the place in the file you want, and only update the part that you want to update.
Also take a look at this question on stackoverflow.
Without some fairly complex logic, you won't usually be able to update an object without rewriting the entire file. For example, if one of the objects on your list contains a string "shortstring", and you need to update it with string "muchmuchlongerstring", there will be no space in the file for the longer string without rewriting all the following content in the file.
If you want to persist large object trees to a file and still have the ability to update them, your code will be less buggy and life will be simplified by using one of the many file-based DBs out there, like:
SQLite (see Java and SQLite)
Derby
H2 (disk-based tables)

Java: How can I assemble/create a single instance for classification using a Weka generated model?

I've been searching for an answer to this for a while to no avail.
First a bit of background: I'm trying to create an AI for robocode using Weka.
I'm first logging the required data from a manual robot to an ARFF file, this is working as it should.
This data is then processed this using Weka and a model created, I'm then saving this file.
I can successfully import the model and classify a dataset that has been imported from another arff file and use the results.
What I want to do now is every time the game status changes is assemble an instance and classify it, to decide for example which way to move etc. using my previously saved model.
I've tried to look it up on the wiki: http://weka.wikispaces.com/Programmatic+Use
and this ibm tutorial: http://www.ibm.com/developerworks/opensource/library/os-weka3/ to name a couple, I've also been looking through the APIs but that hasn't given me much to go on.
Much of what I've tried is deprecated, for example creating a prototype with the attributes and fast vectors then creating an empty dataset. Then creating a new instance with the required values using somthing like inst.setvalue(attrib, value) and adding it to the dataset.
Also what about the class index, or the attribute I'm predicting, in the instance does it have to be null or set to missing or something, as surley I won't know that value as I'm trying to predict it?
So are there any ideas how I can go about this?
any help is greatly appreciated,
Thank you muchly.
Managed to find the answer a while ago.
For anyone else having trouble with this basically what you have to do is in the Weka manual included with every download, (its a pdf).
Page 202 onwards in the manual - Section 16.3 "Creating datasets in memory".
Follow the steps there and it works perfectly.

Reading data for an output efficiently in Java?

I have a web application which runs on MySQL, and uses Java, Struts2 and JSP technologies.
There is an algorithm running on it and I want to test its performance (even seconds are important for me.) I will watch the output as a graphic on a page. I will get the information with Ajax and check for new information every second and write it to the graphic.
My question:
One of my classes produces an output for graphic input. What is the best way to communicate this. For example writing output to a database table and the other class will collect that value from there, or writing to a file, writing to database asynchronously (don't know how) and getting the value etc.
I need to do that operation with high performance because that algorithm uses system resources so much and should be run with best performance so I need a solution that doesn't affect my total performance.
Since you query every second, you're only interested in the latest state which means your algorithm can simply update this state as a variable in memory. The class that produces the output will have access to this variable.
I am presuming your graphic will be updated via javascript. Have the class that produces the output only produce output when something asks for it, by reading the value of the variable and returning it as a JSON string. In your case the Ajax request should query this class (every second). The class will return a JSON string which your javascript will have access to and will be able to use to update the graphic.

Categories