Solved

struts form-bean question

Posted on 2004-09-15
6
457 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

770 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