aspose file tools
The moose likes Struts and the fly likes How to set a Struts FormBean member from Javascript? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "How to set a Struts FormBean member from Javascript?" Watch "How to set a Struts FormBean member from Javascript?" New topic
Author

How to set a Struts FormBean member from Javascript?

Saif Taher
Greenhorn

Joined: Mar 21, 2012
Posts: 2

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

Joined: Jan 30, 2011
Posts: 329

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.


Have Fun with Java
little,little.. little by little makes a lot..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56168
    
  13

You need to understand how JSP operates. Please read this article.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Saif Taher
Greenhorn

Joined: Mar 21, 2012
Posts: 2

Thank you guys, your posts were much helpfull
 
I agree. Here's the link: jrebel
 
subject: How to set a Struts FormBean member from Javascript?
 
Similar Threads
passing values from ActionClass to jsp struts 1.1
JSON JQuery Grid Not getting value in JSP
NOT EMPTY or NOT NULL?
Action[/demo] does not contain method named edit
Using checkboxes with nested logic:iterate tags