• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

populating a javabean with the return value of javascript function

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm trying to modify some text in a textarea wtih javascript, and submit that modified value to a javabean via a jsp page.

Here is the form in my jsp page:



here's the jsp file it's going to:




somewhere along the way I'm screwing up the placement of the onsubmit att....also, there may be good reason not to do this with javascript, but it's bugging me that I can't.
BTW...I didn't post the javascript function (tagTextAsXML) but it does work.

any ideas?
thanks!
bp
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In all that code I can't see the forest for the trees. It's be best to point out the pieces that you are referring to.

Edmund Castermund wrote:but it's bugging me that I can't.


You will continue to be bugged because it simply isn't possible. JavaScript executes on the client after the HTML page created by the JSP is created on the server.

Please read this article to understand the principles of JSP.

If you want to send data back to the server, you'll need to submit a new request.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sort of question has come up often enough that it now has a new JspFaq entry.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In wading through the code, it looks like you might have created the second JSP just to set the property?

Firstly, a poor choice of technology. A JSP should be used for view creation, and nothing else.

Secondly, the bean generated by that page dies with the page. So what's the point?

Perhaps what you need to do is to describe what you are really trying to accomplish. This is perhaps a classic "X Y" problem. You are asking how to do Y because you've decided that it's what you need to do in order to accomplish X; but it turns out that it's not, and you really should be asking how to do X in the first place.

And lastly, the JSP actions setProperty and getProperty are JSP1 dinosaurs that were obsoleted in 2002 with the introduction of JSP2. You should be using the JSTL and EL in modern JSP.
 
Edmund Castermund
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the replies, and apologies for the code excerpt. I had done some googling and had gotten the idea that this may not work, but thanks for confirming.

What I'm trying to do, is to take all the values of the form and pass to a java bean. I had hoped to code the values as xml with javascript, but I think it would be better to have the java bean do the xml coding server side.

My thinking (apparently incorrect) re: the mulitple requets was that a) the user clicks the link to the form jsp page, and it loads. b) the user fills in all the values, and c) when the user clicks submit, the javascript would be invoked, thus sending the coded string to the server as a param.

But that's not how it works, I guess. Anyway, thanks for pointing out the need for jstl, I'll definitely read up on that.
bp
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Edmund Castermund wrote:What I'm trying to do, is to take all the values of the form and pass to a java bean.


Simple. Submit the form to a servlet, create a bean, set the properties of the bean from the submitted parameter. That's a ubiquitous scenario.

I had hoped to code the values as xml with javascript


Why?

but I think it would be better to have the java bean do the xml coding server side.


Yes. Or at least server-side code. I'm not sure a bean is the right choice (yet).

My thinking (apparently incorrect) re: the mulitple requets was that a) the user clicks the link to the form jsp page, and it loads. b) the user fills in all the values, and c) when the user clicks submit, the javascript would be invoked, thus sending the coded string to the server as a param.


Well, that is pretty much how it works. Except I don't see the need for intervening JavaScript, except maybe to validate the form. At least in this scenario.
reply
    Bookmark Topic Watch Topic
  • New Topic