Solved

struts form-bean question

Posted on 2004-09-15
6
463 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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 …
Suggested Courses

628 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