File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes Question on using DisplayTag in JSPs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Question on using DisplayTag in JSPs" Watch "Question on using DisplayTag in JSPs" New topic
Author

Question on using DisplayTag in JSPs

Sumithab Baskaran
Ranch Hand

Joined: Oct 29, 2004
Posts: 52
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

Joined: Jan 10, 2002
Posts: 60048
    
  65

Moved to the Other Open Source Projects forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Madhuri Chanda
Greenhorn

Joined: Nov 09, 2005
Posts: 10
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

Joined: Oct 29, 2004
Posts: 52
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

Joined: Nov 09, 2005
Posts: 10
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

Joined: Oct 29, 2004
Posts: 52
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

Joined: Nov 09, 2005
Posts: 10
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

Joined: Nov 22, 2005
Posts: 1
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on using DisplayTag in JSPs
 
Similar Threads
Dynamic Attribute assignment (in Struts)
Conditional display of DisplayTable of DisplayTag
error onclick of radio button inside display tag
display:column
How to pass multiple parameters. Displaytag row value not changing on dynamic link