We help IT Professionals succeed at work.

Java+Struts!

KirtipurItagol
on
Medium Priority
607 Views
Last Modified: 2008-02-01
Hi Experts, I want to have one of my radio buttons already checked where as another one already disabled using the Struts tag. How can I do it? Below is the html code:
<td width="15%" class="detailbold" valign="top">Opening a London Account?</td>
<td width="15%" class="details" valign="top"><Input type="radio" name="londonacct" value="yes" CHECKED>Yes</input>
&nbsp;&nbsp;
<Input type="radio" name="londonacct" value="no" DISABLED>No</input></td>
Thanks,
Comment
Watch Question

Commented:
<td width="15%" class="detailbold" valign="top">Opening a London Account?</td>
<td width="15%" class="details" valign="top"><html:radio property="londonacct" value="Yes" />
&nbsp;&nbsp;
<html:radio property="londonacct" value="no" disabled="true"/>
</td>

to make radio a default selection, in the Form class assigne the value for the property="londonacct" as Yes.

public yourForm extends ActionForm{
 private String londonacct="Yes";
...
...
}

fargo

Author

Commented:
Fargo. should I make any changes in the struts-config.xml file regarding this??

Commented:
No. No need to change the struts-config file.

But surely u have to add the struts taglib directive in your jsp page.

<%@ taglib
      uri="/WEB-INF/struts-bean.tld"
      prefix="bean"%>
<%@ taglib
      uri="/WEB-INF/struts-html.tld"
      prefix="html"%>
<%@ taglib
      uri="/WEB-INF/struts-logic.tld"
      prefix="logic"%>

fargo

Author

Commented:
awesome......One more question Fargo.
What is the characteristic of value attribute in :
<html:radio property="" value""/>

Commented:
Hi,

value attribute is to define the value for the given property in radio tag. It is mandatary attribute and can get runtime expressions too.

Like in your case,

1) <html:radio property="londonacct" value="Yes" />
2) <html:radio property="londonacct" value="no" />

As you know only radio buttons is not multi selected, i mean out of the radio buttons with same property only one can be selected. So whatever is selected the valule will be passed.

In the action form, if you set the value to "Yes", then the first one will be automatically selected.

You can also have values like the following (run time expressions)

<%
String value="Yes";
%>
<html:radio property="londonacct" value="<%=value%>" />

Hope it clears.
fargo

Author

Commented:
In the action form, even though we set:
private String londonacct ="Yes";

We still need to have getters and setters for londonacct, isnt' that right??
But Fargo, I'm still confused with value attribute. Such as in here:
<td valign="center" class="detailbold">&nbsp;&nbsp;Zip Code</td>
<td valign="center" colspan="2" class="details">
<html:text property="zip" value="" size="24"/></td>

what is the value attribute doing here?? Any crystal clear advise so that I can proceed??

Commented:
We still need to have getters and setters for londonacct, isnt' that right??
>> YES

Ok.
Say for ex:

How do we define the value to be there in text field in normal html?
<input type="text" name="nameOfproperty" >propValue</input>

same in struts is
<html:text property="nameOfproperty" value="propValue" />

Value is basically the value given to the form field.

fargo



Author

Commented:
Good discussion but I'm still confused...A good book will be fine, but you are better than a book...so I'm gonna redefine my question again....

See in my first question above I 've :
<Input type="radio" name="londonacct" value="yes" CHECKED>Yes</input>
It has a value="yes" and then another Yes which showed a checked radio button labeled Yes on the side. This is where I got lost....
Clarify me please...

Author

Commented:
And property is the name we should use in our action forms, right?? I think I know this!!
Commented:
Hi,

I was wrong there...the following html

<Input type="radio" name="londonacct" value="yes" CHECKED>YesLabel</input>
struts equals
<html:radio property="londonacct" value="Yes"/>YesLabel

i just change the label name to clarify.
value attribute pass the value assigned to the radio button and YesLabel is just the label for the radio button.

sorry for confusion.

fargo


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Principal Solutions Architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
http://husted.com/struts/tips/016.html

check out the above link and for a small good book check out "struts complete reference" is simple & ok.
Many online downloadable e-books are available like struts live etc.

About checkinga radio button just set the corresponding property of the radio button to a defult value which you wanted it to be checked.

i.e
String shiva="yes";

<html:radio property="shiva" value="Yes"/>Yes
<html:radio property="shiva" value="no"/>no

here yes will be checked out by default.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.