Link to home
Start Free TrialLog in
Avatar of KirtipurItagol
KirtipurItagol

asked on

Java+Struts!

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,
Avatar of fargo
fargo

<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
Avatar of KirtipurItagol

ASKER

Fargo. should I make any changes in the struts-config.xml file regarding this??
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
awesome......One more question Fargo.
What is the characteristic of value attribute in :
<html:radio property="" value""/>
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
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??
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



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...
And property is the name we should use in our action forms, right?? I think I know this!!
SOLUTION
Avatar of fargo
fargo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Siva Prasanna Kumar
Siva Prasanna Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial