Whoops...got confused. This solves a different problem. But I *do* have
a link in my table which updates other data on the screen. Here's THAT
code (sorry for the confusion):
<display:column headerClass="data" class="data_right" title=" ">
<div id="${GradeTestAction.FIELD_EXAM_STUDENT_LINK}${row.id}">
<c:choose>
<c:when test="${empty matches[row.id]}">
<c:set var="url"
value="Public?app.active=ajax&app.template=ajaxForwarder&Ajax.action=mat
chStudentToExamScan&Ajax.scanId=${row.id}&Ajax.studentId=-1"/>
<a
href="javascript:getStudentInfoForMatch('${url}');">Match</a>
</c:when>
<c:otherwise>
<c:set var="url"
value="Public?app.active=ajax&app.template=ajaxForwarder&Ajax.action=mat
chStudentToExamScan&Ajax.scanId=${row.id}&Ajax.studentId=${matches[row.i
d].id}"/>
<a
href="javascript:getStudentInfoForUnmatch('${url}');">Unmatch</a>
</c:otherwise>
</c:choose>
</div>
</display:column>
Here are the two javascript functions referenced above. They rewrite the
DOM for the page based on selected values. The basic trick is to use
discreet DIV tags for each field you want to change, named with unique
values (I use the primary keys for the referenced object in the table).
Then use javascript to find those fields, and rewrite the DOM with the
new data.....
/*
* Get select box options by calling a Pluglet action
*/
function getStudentInfoForMatch(url) {
makeHttpRequest(url, 'setStudentInfoForMatch', null, returnXML);
}
function setStudentInfoForMatch(textToUse) {
if (textToUse == '803') {
return;
}
// split the document
var returnElements = textToUse.split("||");
// add the name text to the document
var nameField = document.getElementById('name_' +
returnElements[0]);
nameField.innerHTML = "";
nameField.appendChild(document.createTextNode(returnElements[1]));
// add the hidden input field to the document
var inputField = document.createElement("input");
inputField.type = "hidden";
inputField.name = "studentId_" + + returnElements[0];
inputField.value = returnElements[2];
nameField.appendChild(inputField);
var url =
"Public?app.active=ajax&app.template=ajaxForwarder&Ajax.action=matchStud
entToExamScan&Ajax.scanId=" + returnElements[0] + "&Ajax.studentId=" +
returnElements[2];
// create new Unmatch link
var newLink = document.createElement("a");
newLink.href = "javascript:getStudentInfoForUnmatch(\'" + url +
"\');";
newLink.appendChild(document.createTextNode("Unmatch"));
var matchField = document.getElementById('link_' +
returnElements[0]);
matchField.innerHTML = "";
matchField.appendChild(newLink);
// remove selected name from all select boxes
var selects = document.getElementsByTagName('select');
for (var i=0; i<selects.length; i++) {
for (var j=selects[i].options.length-1; j>=0; j--) {
if (selects[i].options[j].value ==
returnElements[2]) {
selects[i].remove(j);
}
}
}
}
/*
* Get select box options by calling a Pluglet action
*/
function getStudentInfoForUnmatch(url) {
makeHttpRequest(url, 'setStudentInfoForUnmatch', null, returnXML);
}
function setStudentInfoForUnmatch(textToUse) {
if (textToUse == '803') {
return;
}
// split the returned text
var returnElements = textToUse.split("||");
// add removed person to all select boxes
var selects = document.getElementsByTagName('select');
var firstSelect = selects[0];
for (var i=0; i<selects.length; i++) {
var selLength = selects[i].length;
selects[i].options[selLength] = new
Option(returnElements[1], returnElements[2]);
}
// add new select box for this row
var newSelect = document.createElement("select");
for (var j=0; j<firstSelect.options.length; j++) {
var text = firstSelect.options[j].text;
var value = firstSelect.options[j].value;
var selLength = newSelect.length;
newSelect.options[selLength] = new Option(text, value);
}
newSelect.id = "examStudent_" + returnElements[0];
newSelect.name = "examStudent_" + returnElements[0];
newSelect.setAttribute("onchange", "studentChanged(this);");
// add select box to page
var nameField = document.getElementById('name_' +
returnElements[0]);
nameField.innerHTML = "";
nameField.appendChild(newSelect);
var url =
"Public?app.active=ajax&app.template=ajaxForwarder&Ajax.action=matchStud
entToExamScan&Ajax.scanId=" + returnElements[0] +
"&Ajax.studentId=-1";
// create new Unmatch link
var newLink = document.createElement("a");
newLink.href = "javascript:getStudentInfoForMatch(\'" + url +
"\');";
newLink.appendChild(document.createTextNode("Match"));
// create new Match link
var matchField = document.getElementById('link_' +
returnElements[0]);
matchField.innerHTML = "";
matchField.appendChild(newLink);
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Paul
Cooper
Sent: Tuesday, November 20, 2007 12:18 PM
To: [email protected]
Subject: Re: [displaytag-user] Using Link on Column to populate
fields(plural!) in parent screen
I have "ajaxish" javascript code working by row in a displaytag table.
Here's my code, though it has some proprietary tag code in it too. But
it should help:
<display:column headerClass="data" class="data_left" title="Student
Name">
<div id="name_${row.id}">
<c:choose>
<c:when test="${empty matches[row.id]}">
<premis:comboBox
name="examStudent_${row.id}"
items="${missingExam}"
onchange="studentChanged(this);"/>
</c:when>
<c:otherwise>
<input
type="hidden"
name="student_${row.id}"
value="${(matches[row.id]).id}"/>
${(matches[row.id]).person.name.formatted}
</c:otherwise>
</c:choose>
</div>
</display:column>
The magic here is that each row has a combobox called "examStudent_XXX"
where XXX is the id of the record, the onchange event calls a javascript
function "studentChanged" that takes the value of the selected combobox
row.
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
tstronge
Sent: Tuesday, November 20, 2007 9:45 AM
To: [email protected]
Subject: Re: [displaytag-user] Using Link on Column to populate fields
(plural!) in parent screen
I got a bit carried away with enthusiasm ;-(
What I got it to work yesterday only had one row in the table (the
single
thus last row in the table!). However, on trying it with multiple rows
in
the table I realised that I cannot get at the correct row object.
My
tstronge wrote:
>
> String fieldValue = evaluate(listObjFieldName,
> ctxt.getAttribute("tableRow")).toString();
>
doesn't work because ctxt.getAttribute("tableRow") gives me the item in
the
last row of the table and not the item that's being selected by the user
clicking on the link.
So I'm back to square 1
- I can't use a TableDecorator as I don't know the column name up front
to
write a getSomeColumnName() method in the table decorator
- I can't use a ColumnDecorator as I can't access values other than the
column in question
Any help really appreciated on this as I am losing hairs by the hour!!
My latest (failed!) attempt has
> public Object decorate(Object columnValue, PageContext ctxt,
> MediaTypeEnum mt) throws DecoratorException {
> String returnAssignmentsStr = "";
>
> String[] returnValueAssignmentPairs = (String[])
> ctxt.getAttribute("returnValueAssignmentPairs");
>
> for (int i = 0; i < returnValueAssignmentPairs.length; i++) {
> String parentObjFieldName =
> returnValueAssignmentPairs[i].split("=")[0];
> String listObjFieldName =
> returnValueAssignmentPairs[i].split("=")[1];
>
> String fieldValue = evaluate(listObjFieldName,
> ctxt.getAttribute("selection")).toString();
>
> returnAssignmentsStr = returnAssignmentsStr + parentObjFieldName
+
> "=" + fieldValue;
> if (i < returnValueAssignmentPairs.length - 1) {
> returnAssignmentsStr += ";";
> }
> }
>
> return "<a href=\"#\" class=\"DATA-LINK\"
> onclick=\"javascript:populate_parent('" + returnAssignmentsStr +
> "')\">"
> + columnValue.toString() + "</a>";
> }
>
in the ColumnDecorator and
> <display:column media="html"
> property="${columnName}"
> .... blah ....
>
decorator="com.XXXX.XXXX.XX.web.decorator.ReturnValueLinkColumnDecorator
"
> >
> </display:column>
>
in the JSP
--
View this message in context:
http://www.nabble.com/Using-Link-on-Column-to-populate-fields-%28plural%
21%29-in-parent-screen-tf4811614.html#a13858332
Sent from the DisplayTag - General mailing list archive at Nabble.com.
------------------------------------------------------------------------
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
displaytag-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-user
------------------------------------------------------------------------
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
displaytag-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-user
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
displaytag-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/displaytag-user