my dog learned polymorphism*
The moose likes Struts and the fly likes using Formbean field in scripting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "using Formbean field in scripting" Watch "using Formbean field in scripting" New topic
Author

using Formbean field in scripting

Henrik Krievs
Ranch Hand

Joined: Jan 05, 2004
Posts: 59
Howdy!

How do I, easily, turn a formbean field into a scripting fild for use in JSP?

Eg. If I wan't to do some advanced calculation on a field for use in the layout?

Regards, Henrik
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In order to use your ActionForm bean in a JSP scriptlet, you have to retrieve it from the scope in which it is saved. So, if myActionForm is in request scope, the code to retrieve it would be:

<%
MyActionForm myActionForm = (MyActionForm)request.getAttribute("myActionForm");
%>

Once you have this reference to the bean, you can call any of it's methods, just as you would in regular Java.

Another alternative might be to put the complex calculation into a getter method in the ActionForm bean (e.g. getMyComplexData()). If you do this, you can access the results of the calculation with <bean:write name="myActionForm" property="myComplexData" />


Merrill
Consultant, Sima Solutions
 
jQuery in Action, 2nd edition
 
subject: using Formbean field in scripting
 
Similar Threads
using javascript to get set value of property name with a '.' in it
Can We do two types validations on same?
Dynamic Language Support in Java 7
Cannot compile servlet
Struts FORM