• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to set a Struts FormBean member from Javascript?

 
Saif Taher
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator

Thank you guys, your posts were much helpfull
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic