Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on using DisplayTag in JSPs

 
Sumithab Baskaran
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • 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!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65118
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Other Open Source Projects forum.
 
Madhuri Chanda
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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.
 
King Cobra
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic