File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
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: 61773
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Saif Taher
Greenhorn

Joined: Mar 21, 2012
Posts: 2

Thank you guys, your posts were much helpfull
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set a Struts FormBean member from Javascript?