Solved

More Stripes

Posted on 2006-07-06
4
253 Views
Last Modified: 2006-11-18
Hi stripes users,
How can pass a data field value from JSP to my ActionBean class.
e.g:
1.myPage.jsp has n fields
2.i want to be able to retrieve those values from myPage.jsp
and construst some object with in ActionBean class
0
Comment
Question by:komlaaa
4 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 17056142
Will the array of string be helpful?

String[] nameOfComponent;

David
0
 
LVL 8

Accepted Solution

by:
thomas908 earned 200 total points
ID: 17056831
Are these value form fields?
If Yes and each field has only value associated with it then you'll have to do

String field1 = request.getParameter("field1");
String field2 = request.getParameter("field2");
......

If teach field can have multiple values (like a checkbox) then
String []field1 = request.getParameterValues("field1");

0
 
LVL 3

Assisted Solution

by:anumalas
anumalas earned 100 total points
ID: 17056939
Hi

You can do in the following way.

1.
public class YourForm {

ActionBean aBean = new ActionBean();
// some other variables;
// getter and setters of your actionbean;
}

public class ActionBean{

// your n number of variables and their getter and setters;
}

public class YourAction(.......){

yourform.getActionBean().setXX(); // set your values in your actionbean using setters;

}

In your jsp

<bean:define id="yourForm" name="YourForm" type="com..forms.YourForm"/>
<bean:define id="actionBean" name="yourForm" property = "actionBean" />

after this to set values in n number of your fields
for eg you have to set item number in your action bean
<td>
<html:text name="yourForm" size="10" maxlength="10" property=actionBean.itemnumber"/>
</td>

after doing this in your action form your bean varibels are available in a single object.

you can retrive those values using getters like

yourForm.getActionBean().getItemNumber();

Hope this will help :)
0
 

Author Comment

by:komlaaa
ID: 17060976
thomas, I dont thinks it is a good idea to use request.... in ActionBean class beacause, i want to be able to use JUnit to test my methods.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Hyena v12.2 is now available for downloading and is available in English, French, German and Spanish versions.
We have come a long way with backup and data protection — from backing up to floppies, external drives, CDs, Blu-ray, flash drives, SSD drives, and now to the cloud.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now