Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

struts form-bean question

Posted on 2004-09-15
6
Medium Priority
?
466 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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 1000 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

704 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