Solved

struts form-bean question

Posted on 2004-09-15
6
455 Views
Last Modified: 2010-05-18
i want to make certain radio button checked based on the values of another form-bean.
0
Comment
Question by:ldbkutty
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:boonleng
ID: 12064888
Do you mean that there's 2 form-bean called in the same jsp page,
and the radio button from form-bean A is checked based on the value of form-bean B?
0
 
LVL 32

Author Comment

by:ldbkutty
ID: 12065040
yes
0
 
LVL 14

Expert Comment

by:boonleng
ID: 12065295
I assume you are using session scope for using multiple form bean,
you can retrive the form bean from httpsession attribute using the form-bean class name.
then take the value from the form-bean and set to the radiobox.

Example:
public ActionForward execute(ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) throws Exception {

      FormBeanA thisForm = (FormBeanA) form;

      FormBeanB formB = (FormBeanB ) request.getSession().getAttribute(FormBeanB.class.getName());
      thisForm.setMyRadio(formB.getSomeField());
            
      return mapping.findForward("SUCCESS");
}
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 32

Author Comment

by:ldbkutty
ID: 12065977
I will explain a bit more. :-)

I have main.jsp(which has a form 'myform1) which includes page1.jsp(which has a form 'myform2').

I have

MainForm.java(Form-Bean),
MainAction.java(Form-Action) and

Page1Form.java(Form-Bean),
Page1Action.java(Form-Action)

Based on the selection of a form-field in the main.jsp i want to make one of the radio buttons to be checked in page1.jsp

I think we can set radio buttons CHECKED only in form-bean. like,

private String myRadio = "some_value";

where "some_value" is the value of the radio button that gets checked. So, i want to generate that "some_value" in the page1Form.java based on the selection of the main.jsp field.
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 12066356
Well, in the MainAction, you can actually called the .do of the Page1Action and send the value of the radio button as the parameter such as blah.do?params=value

Then in the Page1Action.java, you can simply get the params by request.getParameter("params"); and you can assign the value easily to the radio button.

I hope that helps
0
 
LVL 14

Accepted Solution

by:
boonleng earned 250 total points
ID: 12071441
Opps.. sorry.. the attribute name should be the form name, not the form-bean class name.
you initiate a Page1Form form-bean, set the value of the radio button. then store the form-bean to request/session attribute.

MainAction.java
public ActionForward execute(ActionMapping mapping,
     ActionForm form,
     HttpServletRequest request,
     HttpServletResponse response) throws Exception {

     MainForm thisForm = (MainForm) form;

     Page1Form formB = new Page1Form();
     formB.setMyRadio( thisForm .getSomeField() );
     request.setAttribute( "page1Form", formB );
         
     return mapping.findForward("SUCCESS");
}
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

760 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

21 Experts available now in Live!

Get 1:1 Help Now