Win a copy of Securing DevOps this week in the Security forum!

Bear Bibeault

Author and ninkuma
Marshal
+ Follow
since Jan 10, 2002
Bear likes ...
IntelliJ IDE Java jQuery Mac Mac OS X
Author of:
Secrets of the JavaScript Ninja, 1st and 2nd editions,
jQuery in Action, 1st, 2nd and 3rd editions,
Ajax in Practice, and
Prototype and Scriptaculous in Action
Austin, TX
Cows and Likes
Cows
Total received
160
In last 30 days
4
Total given
175
Likes
Total received
4387
Received in last 30 days
24
Total given
2783
Given in last 30 days
26
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt Green check
expand Greenhorn Scavenger Hunt Green check

Recent posts by Bear Bibeault

We're still missing some context. Is this part of a larger framework that you are using?

What does it mean to "format to currency?"

Where did you get this code from?

And (from your subject), what has this to do with PDF?
That is the $1000 question because we can't tell you that without knowing more about what its purpose is.

The fact that it uses a capital as the first letter conventionally means that this function is meant to be a constructor. But it's not really written as if it were one.

The "this" in the function refers to its function context, and that is set depending upon how it is called. What is it supposed to be?

I think you're going to need to give us more information than just the code of the function in order for us to help you.
You're not being entirely clear, but what I am gathering is that you want to take this prop:which currently passes the full data of your first code example, and translate it to the simplified code of your second example?

If that is the case, the map() function of Array can easily translate the data. You can make the call to map() right in the prop, but I'd recommend doing it outside of the JSX for improved clarity.
Because you are talking about classes, and since few people are using ES6 on the web so far, I suspect your question may be more about Java and not about JavaScript.

Which is it?
2 days ago

Mo Alexwainy wrote:
Thanks. But why does the alert within this js runs at the same time the loop is executed?


It doesn't. You are writing out the same markup multiple times. Do a View Source at the browser to see what it is that you are sending to it.
Pay attention to what Paul posted. The JavaScript code does not -- I repeat does not -- execute in line with the Java code. It is run much later in the browser on the user's machine.

Please read this article -- even though it talks about JSP (why aren't you using JSP?) the same is true for HTML code emitted by a servlet.

Alex Lieb wrote:Prefer document.forms.country over $("input[name='country']").


Except you left out the fact that document.forms is a list for which you must use a positional index. This makes the code fragile as any change to the structure of the page may break the code. In the case of the jQuery equivalent (where you should be prefixing the selector with a reference to the containing form) or the modern native equivalent, the code continues to work as long as the name of the element doesn't change.

If jQuery is already loaded for other purposes it makes no sense to me not to leverage it for more robust code.
Your form action does not match your servlet mapping. And it is unnatural for the parameters to be part of the path, for form=based APIs. Why are heading in that direction?

And, you shouldn't be hard-codeine the contact path. Obtain it programmatically. See JspFaq for details.

dorel iancu wrote:All exceptions I can think about... and I can catch them right where they may happen.


For most exceptions, you will not do this. You should only catch an exception when you can do something about it.

For example, if you are converting a string to a number, you could catch a number format exception if it's bad, and supply a default value (zero perhaps) if that makes sense.

But most exceptions means something is very wrong and should not be caught. For example, a reference has an unexpected null in it, and a null pointer exception is thrown. You can't do anything useful when catching the exception (you were expecting data, and there isn't any, so what could you do?) so you should let the exception propagate upwards.

Now, the question as to whether to use checked or unchecked exceptions is a more complicate kettle of fish.
5 days ago
Oh wait... you are using jQuery (your last two examples).

So why are you using document.forms rather than jQuery which is apparently already in use? 
The notation you are using to find the elements is about two decades out of date. There is a whole API to find elements by id, by tag name, or by other selector methods.

And then, of course, there's jQuery which makes finding elements almost trivial.

Any reason you're not using jQuery or any of the modern API?

E.g.: document,querySelector()

tangara goh wrote:
I have tried the following but not sure why it is not working :


How is it not working? Just saying "it doesn't work" isn't useful.


Do you have a servlet mapping to match?

And, you shouldn't include the "http://localjost:8013" in the URL. Leave the host off when creating a URL into the same web app.

And, you shouldn't hard-code the context path. See the JspFaq for how to get this programmatically.

so I want to get the jsp to perform the Search


No you don't. A JSP should never perform any processing. Do that in the controllers (or lower delegates).
6 days ago
JSP
What do you think is handling and serving up the SOAP and RESTful APIs? In a Java web api, it's likely servlets.
1 week ago
A JSP is just a template to create the page on the server to send to the client. By the time the page gets to the browser, it is just an HTML page like any other. In other words, you would code the activity the same way in a JSP that you would any other page.

Please read this article to understand how JSP works.
1 week ago
JSP