define a Custom Property as a Data Object - java

Found the issue on my payment Input control. There was a small computed Text field that was failing but not throwing an error. Just stopped the whole process. In any case removed the computedText and it now works. The compositeData formula that returns pItem to the custom control still fires way to often but I can't figure out how to stop that. It is all memory resident so it is probably not a major performance hit, but still.....
This question is a follow up to my previous question and I will try to refine the issue
defining an object property in a compositeData on a custom control
Here is a picture of what I am trying to do:
The repeat control is bound to an arrayList generated by the Java method Payments.getAllItems(LinkKey) and that works correctly. The button in the repeat is fairly simple it just setts the viewScope.vsShowPayment = true and vsRIndex to the repeat Index value so I know which element in the ArrayList we are working with. It then does a refresh of the panelPaymentContainer which hides the repeat and renders the custom control ccTestPayment.
ccTestPayment has a custom property called pItem of the type java.lang.Object with this code:
<xc:ccTestPaymentInput rendered="#{javascript:(viewScope.vsShowPayment)}">
<xc:this.pItem><![CDATA[#{javascript:try{
var debug:Boolean = true;
if (debug) print("Open existing row = " + viewScope.vsRIndex)
rIndex = parseInt(viewScope.vsRIndex.toString());
if (debug) print("rIndex = " + rIndex);
pItem = Payments.getItem(rIndex);
return pItem;
}catch(e){
print("Failure in Custom Prop of add item " + e.toString());
return null;
}}]]></xc:this.pItem>
</xc:ccTestPaymentInput>
the method in the class Payments Payments.getItem(rIndex) then returns the PaymentItem Object from the ArrayList of PaymentItems and displays them in custom control. the fields in the custom control are bound to compositeData.pItem.getPaymentDate etc and to this point everything is cool.
I can edit any of the fields on the custom control and that all works fine. However, when I press the "Save" button none of the code in it gets executed.
try{
print("Start Payment save");
var debug:Boolean = true;
var pos:Integer = parseInt(viewScope.vsRIndex.toString());
if (debug) print("Working with pos = " + pos + " Call saveThisItem");
if (Payments.saveThisItem(compositeData.pItem , pos)){
if (debug) print("save Payments Worked ");
}else{
if (debug) print("save Payments FAILED ");
}
}catch(e){
print("payment save Error " + e.tostring);
}finally{
viewScope.vsExpPayDate = null;
viewScope.vsShowPayment = false;
viewScope.remove("vsRIndex");
viewScope.remove("vsGotItem")
}
None of the print statements get fired. I suspect it has something to do how pItem gets defined. the code behind the custom property gets fired over and over again and I'm wondering if that is getting in the way.

The reason that the save was not working was that there was a computed Text field on the control that generated an error. The problem was that there was no error message reported on the client nor the console. After a lot of head scratching I noticed the text filed was no longer displaying the value it was supposed to. Deleted the field and the save and everything else started to work.
On the issue of the number of times the processes are called I think I have resolved many of them. I'm moving the control ccTestPaymentInput.xsp inside the repeat. It will now have direct access to the 'current' PaymentItem Object so I can access teh repeat var=pItem which is teh PaymentItem object I want to work with. Clean and far simpler than what I was doing. The only refreshes necessary are the ones related to the rpeat control and there is not much that I can do about that.

Related

JasperReports export to Excel uses only last set background color

Im pretty pretty new to Dynamic-Jasper, but due to work i had to add a new feature to our already implemented solution.
My Problem
The Goal is to add a Column to a report that consists only out of a background-color based on some Information. I managed to do that, but while testing I stumbled upon a Problem. While all my Columns in the html and pdf view had the right color, the Excel one only colored the fields in the last Color.
While debugging i noticed, that the same colored Fields had the same templateId, but while all Views run through mostly the same Code the Excel one showed different behavior and had the same ID in all fields.
My Code where I manipulate the template
for(JRPrintElement elemt : jasperPrint.getPages().get(0).getElements()) {
if(elemt instanceof JRTemplatePrintText) {
JRTemplatePrintText text = (JRTemplatePrintText) elemt;
(...)
if (text.getFullText().startsWith("COLOR_IDENTIFIER")) {
String marker = text.getFullText().substring(text.getFullText().indexOf('#') + 1);
text.setText("ID = " + ((JRTemplatePrintText) elemt).getTemplate().getId());
int rgb = TypeConverter.string2int(Integer.parseInt(marker, 16) + "", 0);
((JRTemplatePrintText) elemt).getTemplate().setBackcolor(new Color(rgb));
}
}
}
The html view
The Excel view
Temporary Conclusion
The same styles uses the same Objects in the background and the JR-Excel export messes something up by assigning the same Object to all the Fields that I manipulated there. If anyone knows of a misstake by me or potential Solutions to change something different to result the same thing please let me know.
Something different I tried earlier, was trying to set the field in an evaluate Method that was called by Jasper. In that method we assign the textvalue of each field. It contained a map with JRFillFields, but unfortunatelly the Map-Implementation denied access to them and just retuned the Value of those. The map was provided by dj and couldn't be switched with a different one.
Edit
We are using JasperReports 6.7.1
I found a Solution, where I replaced each template with a new one that was supposed to look exactly alike. That way every Field has its own ID guaranteed and its not up to chance, how JasperReports handles its Data internaly.
JRTemplateElement custom =
new JRTemplateText(((JRTemplatePrintText) elemt).getTemplate().getOrigin(),
((JRTemplatePrintText) elemt).getTemplate().getDefaultStyleProvider());
custom.setBackcolor(new Color(rgb));
custom.setStyle(((JRTemplatePrintText) elemt).getTemplate().getStyle());
((JRTemplatePrintText) elemt).setTemplate(custom);

How to loop through all documents in a View of IBM Notes (NotesView) with Java

I have a View with more than 2 documents inside. This is the code which grabs the document
Currently I have this:
Document orderRegelDocument = OrderRegelsVoorCopsView.getFirstDocument();
while (orderRegelDocument != null) {
//do something here
System.out.println("Nieuwe Orderregel");
tempOrderRegel = OrderRegelsVoorCopsView.getNextDocument(orderRegelDocument);
orderRegelDocument.recycle(); // recycle the one we're done with
orderRegelDocument = tempOrderRegel;
}
The first document is getting grabbed but after that I get a NotesException: Notes error: Entry not found in index viewName. What am I doing wrong?
And also a question next to this. If a user is in a document, but my agent also changes a field then when the user saves the document it gets a save conflict. Is there a way to overcome this.
You are apparently doing something in the code that you are not showing that is altering the view before you are calling getNextDocument. You might be deleting the document, changing an item value that causes the document to no longer be selected for the view, or changing an item value that causes the document to be re-sorted to a different location in the view collection.
The idiom that is used to avoid this sort of thing is to make that call to getNextDocument as one of the first things that it occurs in the body of your while loop. I.e., just move it up so that it occurs before your //do something here code. Like this:
Document orderRegelDocument = OrderRegelsVoorCopsView.getFirstDocument();
while (orderRegelDocument != null) {
tempOrderRegel = OrderRegelsVoorCopsView.getNextDocument(orderRegelDocument);
//do something here
System.out.println("Nieuwe Orderregel");
orderRegelDocument.recycle(); // recycle the one we're done with
orderRegelDocument = tempOrderRegel;
}
I don't know all of your code but my guess would be that assuming getNextDocument(document) gets the next and sets it in the document (otherwise you never assign it the getNext result to anything) you call getNextDocument() twice instead of once and you skip the second row and try to manupulate the 3rd (which is not present) and you get the error.
if( OrderRegelsVoorCopsView.getNextDocument(orderRegelDocument) != null){ //Here you take the next
tempOrderRegel = OrderRegelsVoorCopsView.getNextDocument(orderRegelDocument); //And here you take the next after
// Here you are at the wrong item already...

Getting a RuntimeException : Datasource user is null ? when updating User model in Play Framework 2.2.1

I am currently trying to enhance the To-Do List tutorial from Play framework's website. I've added a login form, (and of course a User class acting as a model), and it works perfectly well. I also made a small "dashboard" in which the logged user is able to change his password and his email address. But when I submit the form, I get a "Datasource user is null ?" error (RuntimeException).
The whole problem came when I wanted to restrict the edition possibilities (I first used a whole User form, which is quite over the top (User do not need to edit their ID). So I made a small inner class in my Application file called UpdateUser which gathers the required informations, just as I did for the login system.
Searching this error gave me many results but people saw their problem fixed by uncommenting the ebean.default line in the conf file, which I already did.
Here is the method I used to update user's informations :
Firstly, I made a small class in my Application to hold the form (exactly like I did for the login thing).
Then I made a update function as found here in my user class :
public static String update(String id, User newuser) {
newuser.update(id);
return("Your profile has been updated");
}
which returns the String that will be in my flash and which is according to my compiler the problem function.
This function is called in my Application like this :
public static Result updateUser(String id)
{
Form<UpdateUser> filledForm = updateUserForm.bindFromRequest();
System.out.println("Updated User : "+filledForm.get().id);
if(filledForm.hasErrors())
{
flash("success","Error while updating");
}else{
User user = new User(filledForm.get().id, filledForm.get().email, User.find.byId(filledForm.get().id).name, User.find.byId(filledForm.get().id).surname, filledForm.get().password);
flash("success", User.update(id,user));
}
return redirect(routes.Application.dashboard());
}
I tracked the data in the Form and it is not null (I mean I can get everything from the form). But I wonder if I have to create another ebean or if it's my function which is wrong. I also wonder if it's not my User creation that fail. Or maybe I should take the updateUser function and put it in my inner UpdateUser class ?
I have to admit that I worked on that all of yesterday (and probably today too), and I can't find anything on the internet except the ebean.default thing.
------EDIT
I continued to search, so here's what I tried :
1) Getting the form result into an instance of UpdateUser in order to use it
2) Use this instance instead of getting the data from the form
But it failed too. What's really weird is that I've added a toString() method for User class, and calling it on the user I want to insert (as an update) gives me the full stuff. I think it must be a configuration problem, but I can't see it.
Another thing : when I come to the error page and when I try to come back to the application by modifying the URL, I am disconnected. Is it my ebean that closes himself ?
Last edit for the day, I'm getting tired of this. I tried to delay the action (i.e. making it happen after the user has logged out), the new data are correctly saved but I still get the error when calling the update function.
Alright, I finally found it, but totally by chance.
I just had to write this :
public static String update(String id, User user) {
user.update((Object)id);
return ("Your profile has been updated");
}
Because for some reason that I don't really understand, The id String needs to be cast to Object. The rest of the code was correct. But apparently, when using update() on this particular case (is it because my id is a String or because I get the informations from another class before using it as my Model), the parameter which is supposed to be a String (even in the documentation) HAS to be cast.
That's it.

JInput Multiple Controllers?

i'm somewhat new to jinput and java in general and was wondering, what's the easiest way to set up multiple xbox 360 controllers (particularly 4) with jinput? currently, i'm currently going off of theuzo007's tutorial on jinput with controllers, and have a basic working controller setup going on. it would be fantastic if i could set what controller moves certain entities around. (i'm using my friend's homemade library, just so you know.)
screenshot -
http://imgur.com/a/1Ocu5
top one is the main block of code, last one is the header (sorry for putting them in the wrong order, imgur does that sometimes!)
if anyone could help me out, that would be great, thanks!
edit: if there's no possible way to do it, if anyone could try to reccomend a new library to me, that would be cool.
There is a possible way
That tutorial is pretty good. Furthermore, I think you can do the 4 controllers stuff by copy-pasting some code inside the zip theuzo007 provides you and a bit more. By the way, that page that you liked says that there is a better version of that tutorial where you can download an also better version of his code -> theuzo007's JInput tutorial V2
Once you download the code you can see that in JoystickTest.java there is a method called searchForControllers() that you can put (With the corresponding private ArrayList<Controller> foundControllers; as field) in a class called ControllerChecker or some cooler name. Make them all static and you will get something like this:
public class ControllerChecker {
private static ArrayList<Controller> foundControllers = null;
/**
* Just used for checking all available controllers.
*/
private static void searchForControllers() {
Controller[] controllers = ControllerEnvironment.getDefaultEnvironment().getControllers();
for(int i = 0; i < controllers.length; i++){
Controller controller = controllers[i];
if (
controller.getType() == Controller.Type.STICK ||
controller.getType() == Controller.Type.GAMEPAD ||
controller.getType() == Controller.Type.WHEEL ||
controller.getType() == Controller.Type.FINGERSTICK
)
{
// Add new controller to the list of all controllers.
foundControllers.add(controller);
// Add new controller to the list on the window.
window.addControllerName(controller.getName() + " - " + controller.getType().toString() + " type");
}
}
}
/**
* Returns null if there is no controller available. Otherwise, it retrieves the last controller in the list by removing it.
*/
public static Controller getController() {
if(foundControllers == null) {
foundControllers = new ArrayList<Controller>();
searchForControllers();
}
return foundControllers.size() == 0 ? null : foundControllers.remove(foundControllers.size() - 1);
}
}
You would use the static method getController() to make the players have a different controller, checking if the returned controller is null, meaning that there is no available controller. Also you can change my code and check for controllers everytime you ask for one, but you have to check if the controller is already in use.
I hope this helps you in your purpose. This solution just checks for all available controllers and returns then in the last order it found them (maybe using a Stack is more efficient). But probably you will want more functionality like being able to tell the program to select a specific controller by pressing a button, maybe in a screen that says "Please, connect your controller and press any key/button". This can be achieve easily if you understand theuzo007's code (the JoystickTest.java has a lot of useful lines!).
Also you can make some mechanism to detect unpluged controllers and just by plugging in them again the system recognize it. Maybe there is some controller id, I haven't found it yet.
Finally, there is more code here.

JavaScript EJB variable field holding value?

I have an ajax enabled list of records that I'm going through and each one has a dropdown box that I'm trying to make a required field for the form to submit. To complicate matters the 'Close Record' button is not the submit button so I can't just use required attribute on the select(dropdown box) that I'm using. The value for the selected dropdown box is saved in an Enterprise Java Bean so I thought I could just write a JavaScript function to check the value:
function CheckForm() {
var clearObj = document.getElementById("mySelect");
if(clearObj.value != "") {
return true;
} else {
clearObj.style.backgroundColor ='yellow';
}
return false;
}
This doesn't work because once I close one and go to the next it's maintaining the value of the previous record on the page. Basically I have an update-content event that I need to know how to handle. Any ideas as to how to manipulate the DOM or JSON object to make this select a required field? Thanks.
With the little information given, I would assume that when you close the existing record and then loading the next record, you are doing it through an ajax request. If thats the case, then you can add a call back for the ajax request, which would reset the drop down.
This should be a comment, but as you see, I dont have 50 points :-)

Categories