• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Question on using DisplayTag in JSPs

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I using DisplayTag to display dynamic rows of data in my jsp's.
My first column needs to be a selectable column (radio buttons). I am able to display a column of radio buttons by using the <input> tag.
My question is: How do I auto-select the first row of data? (by default the first row must be selected)

Here is the code:

<display:table name="searchResults" requestURI="" scope="session" width="100%" id="resultsList" sort="list" defaultsort="3" defaultorder="ascending" pagesize="10" cellpadding="0" cellspacing="0" border="0" >
<display:column title="Select" align="center"> <input type="radio"
name="selector" value="" /> </display:column>
<display:column property="namec" title="Name" sortable="true"
align="left" />
<display:column property="description" title="Description"
sortable="true" align="left" />
</display:table>

Please Help!
Thanks in advance!
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the Other Open Source Projects forum.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In <input> tag of type radio button, there is an option

<input type = "radio" name = "" checked>

with the "checked" word in the tag, the initial state of the radio button will be selected.

I hope this helps.
 
Sumithab Baskaran
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. I tried using checked. But, by default the last row of the list is selected always. I want the first row to be selected, not the last.

Any other suggestions?
Thanks
 
Madhuri Chanda
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess the code which you gave is only part of the code... how many radio buttons are there total..?

Make sure that only for the first radio button <input type = "radio" ... >
it is checked... the next radio button input tags should not be checked. if all the radio buttons are checked.. obviously it checks the last radio button.

By chance, are you running into the above case?

if it is not the above case, then on body onload() function add the following statement

document.FORM_NAME.selector.checked = true;

where FORM_NAME is the name of the form given in the <FORM> tag and "selector" is the name of your input radio button field.

let me know if this helps.
 
Sumithab Baskaran
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using displayTag.
In this line, <display:table name="searchResults" />
-- the searchResults is a list that the displayTag iterates through and displays 3 columns - 1) selector column with radio buttons
2) name column
3) description column
So, there can be any number rows in the list. 'searchResults' is a dynamic list that gets populated by making a call to the database in the Action class.

The code that I first posted is complete. In this situation, I want to auto-select the first row.

Thanks
 
Madhuri Chanda
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok.. since it is a dynamic list.. slight modification to the previous posted hint might work like:

function fnOnLoad(){
document.FORM_NAME.selector[0].checked = true;
// or something like
// if(searchResults.length > 0)
// document.FORM_NAME.selector[0].checked = true;
}

since, for any number of radio buttons, the name of input type will be "selector"... hope the above code might work.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Madhuri Chanda:
ok.. since it is a dynamic list.. slight modification to the previous posted hint might work like:

function fnOnLoad(){
document.FORM_NAME.selector[0].checked = true;
// or something like
// if(searchResults.length > 0)
// document.FORM_NAME.selector[0].checked = true;
}

since, for any number of radio buttons, the name of input type will be "selector"... hope the above code might work.

 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic