Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 591
  • Last Modified:

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,
0
KirtipurItagol
Asked:
KirtipurItagol
  • 5
  • 5
2 Solutions
 
fargoCommented:
<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
0
 
KirtipurItagolAuthor Commented:
Fargo. should I make any changes in the struts-config.xml file regarding this??
0
 
fargoCommented:
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
KirtipurItagolAuthor Commented:
awesome......One more question Fargo.
What is the characteristic of value attribute in :
<html:radio property="" value""/>
0
 
fargoCommented:
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
0
 
KirtipurItagolAuthor 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??
0
 
fargoCommented:
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



0
 
KirtipurItagolAuthor 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...
0
 
KirtipurItagolAuthor Commented:
And property is the name we should use in our action forms, right?? I think I know this!!
0
 
fargoCommented:
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


0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
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.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now