Forums Register Login

Question on using DisplayTag in JSPs

+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
Moved to the Other Open Source Projects forum.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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 have a knack for fixing things like this ... um ... sorry ... here is a consilitory tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4254 times.
Similar Threads
Conditional display of DisplayTable of DisplayTag
display:column
Dynamic Attribute assignment (in Struts)
How to pass multiple parameters. Displaytag row value not changing on dynamic link
error onclick of radio button inside display tag
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:22:48.