Jack Tauson

Ranch Hand
+ Follow
since Mar 27, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jack Tauson

Norm Radder wrote:A comment on the code in the loop
The test: if (i > 0) {    on line 6
with   } else {  on line 18 is slightly confusing.
The else block is for the first time around the loop when i == 0
the if block is for the rest of the iterations.
This would make more sense to me:



Yeah, makes sense. Thanks for your suggestion.
1 month ago

Carey Brown wrote:You have several duplicate lines in the two blocks of code that could be moved after the blocks. This follows the "DRY" (Don't Repeat Yourself) principal.



Right. I guess I can leave testCases.setSelectedCellValue...  inside the loop and take out other things.
1 month ago
Turned out it was an Hibernate object creation issue because of the saveOrUpdate method used behind the scenes. Had to move object creation step inside the loop to get it fixed like this:


[Don't repeat the preceding post if it's not adding new information.]
1 month ago

Ron McLeod wrote:Since you don't use the index for anything else, you could simplify the code a bit by using an enhanced for loop:




Thanks. I started using it but then I ended up using the index again as shown below and running into an issue related to the for loop I believe. Please find my code below. Haven't included other details as I'm suspecting it's a for loop issue.


The print statements for above code are coming out like this:



I have a table with three columns  - selectedTestVal, cellValue and testcase

With above code, I'm trying to save the values - which should put 4 records in the table. However, I'm only seeing the last value getting inserted in the table which is :

testCase = KLM45677  , cellValue = 30 and selectedTestVal = 45555

Do you see anything wrong in my for loop above?

In addition to above last record, I was also expecting following records in my database table:

1 month ago

Ron McLeod wrote:You didn't provide a lot of details, but assuming that TestFileUtils#getTestFileItemsByLaneNumberRange returns a collection of Java objects, I don't understand why you would want to transform them to a JSON representation, and then try to figure out how to reduce it.

If you had a class like this which held the test results:
and TestFileUtils#getTestFileItemsByLaneNumberRange returned a collection of that type, then you could get a list of testcases doing something like this:



Thanks. Yes, you are right. I don't need it to convert to JSON here. What I ended up doing is the following:

1 month ago
I'm using jackson ObjectMapper (import com.fasterxml.jackson.databind.ObjectMapper;) like this in my class:



And above print statement is giving me the following JSON result back:




I just want to retrieve the values of testCase (ABC1234,DEF234 and GHIJ4567) one by one and wondering how should I be able to get these value from the JSON? Should I
use something different than objectMapper.writeValueAsString to not generate JSON and hande it in different way?
1 month ago

Piet Souris wrote:Maybe you can use a Textblock.format? See for instance baeldung textblock. That is a great help when it comes to using Json.



Thanks. I'm not concerned about building JSON or HTML(or maybe I should?), it's just that how can I use all the four values of the arrays in one string. I am sure that there are only 4 values and I can make the string as shared before - like this:



But I am not sure if above approach is the best approach to use since I'm hardcoding array values.
1 month ago

Carey Brown wrote:



Question:

What would be an efficient way to build a result string like the following:

result = "<div class=\"parent\"> <div class=\"heading\">"+arr[0]+"</div> <div class=\"heading\">"+arr[1]+"</div></div><div class=\"parent\"> <div class=\"resultname\">"+arr[2]+"</div> <div class=\"resultname\">"+arr[3]+"</div></div>";



Since I know there are 4 values, using above approach works but I think that's not the best way to do it?

If I put it like this - it's not gonna work:

1 month ago

Carey Brown wrote:



Thanks or I could use the following inside the for loop:


1 month ago

Jack Tauson wrote:

Carey Brown wrote:Split() is the typical way to do this so if an array is not what you're looking for then what did you have in mind?



If I'm using the split like this:



It's giving me the following output:



I'm mainly looking for values 555,777 ,AB and CD together and not as separate values. Also, I'm not looking for "|" in the output as shown above. Am I doing anything wrong here?

Edit:
Why "|" is showing in the output. Just to clarify more, I'm mainly interested in the values 555, 777, AB and CD only.



I needed to do this:



However, it's still printing a blank value in the output:
1 month ago

Carey Brown wrote:Split() is the typical way to do this so if an array is not what you're looking for then what did you have in mind?



If I'm using the split like this:



It's giving me the following output:



I'm mainly looking for values 555,777 ,AB and CD together and not as separate values. Also, I'm not looking for "|" in the output as shown above. Am I doing anything wrong here?

Edit:
Why "|" is showing in the output. Just to clarify more, I'm mainly interested in the values 555, 777, AB and CD only.
1 month ago
I have a string like this:



I want to extract the contents -  555,777,AB and CD.


I tried using String[] arr = str.split("|") ; but that splits everything into an array. Is there a regex way I should consider and what would it be as the online regex things I've found are very confusing.

1 month ago
I noticed a spring controller defined like this in my code:



so carfortypemanual is a jsp page which exists with a form defined inside it but I'm trying to understand what does "formJspName" here do here? I don't see any GET or POST method defined here.
3 months ago

Vasanth Selvamani wrote:Prefix v?



Sorry, I didn't understand what you were trying to say.
4 months ago
JSP
Trying to get rid of struts related spring modules /validator stuff from my code as we are no longer using struts. I'm seeing the following defined in my JSP

I have spring-validator.jsp which contains the following:



And then in one of my JSP page, I see it being called like this:




1. What does defining the prefix "v" and "javascript" mean in the above code?

2. What does dynamicJavascript = "true" means?


So far whenever I've seen the usage of springframework tags, which are defined like this:


I've used that it's being used in the form using prefix "form" prefix, which was easy to understand. But the spring-validator stuff is something I'm trying to understand such that I can get rid of it and what I need to do to get it replaced.
4 months ago
JSP