Solved

struts form-bean question

Posted on 2004-09-15
6
456 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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.

914 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