Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

How to set a Struts FormBean member from Javascript?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

I was really wondering if we can do the following:

I have a Struts FormBean with the following getters and setters:

public String getLogData() {
return logData;
}

public void setLogData(String logData) {
this.logData = logData;
}

I want to set this logData member from JSP page using Java and JavaScript like this:
<%
FormBean form = (FormBean) session.getAttribute("FormBean");
form.setLogData(%> call below JavaScript here!! <%);
%>

<script>
function getTestData(){
return "log data";
}
</script>

I get this data using Javascript, hence is this possible or any way to set Java Bean members through Javascript?

Thanks
 
Ranch Hand
Posts: 329
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Saif,
Welcome to Ranch!!!

Saif Taher wrote: <%
FormBean form = (FormBean) session.getAttribute("FormBean");
form.setLogData(%> call below JavaScript here!! <%);
%>


Firstly if you want to get the form bean also using scriptlets, why would you need struts in the first place?

Saif Taher wrote: I get this data using Javascript, hence is this possible


Why do we need to get this from javascript. Explain the scenario so that we can think about an approach.

Saif Taher wrote: any way to set Java Bean members through Javascript?


Well there is no way (but also think about how do you think that a populated ActionForm is received in the Action class even though you are not setting anything using javascript and why are the setters and getters required in form beans?)

Quick work around if nothing works out for you if the data is dynamic, make it hidden and assign it in javascript and submit.
 
Sheriff
Posts: 67618
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
You need to understand how JSP operates. Please read this article.
 
Saif Taher
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thank you guys, your posts were much helpfull
 
Maybe he went home and went to bed. And took this tiny ad with him:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic