Go Back   Velocity Reviews > General Computer Discussion > Software
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
Old 10-03-2006, 02:27 PM   #1
Default How i can populate all fileds dynamically in jsp using javascript?


How i can populate all fileds dynamically in jsp page based on contents
found in xml file?I have written jsp servlets and java class file.
i transferred automatic data from jsp to servlet then to java class
which creates a xml file based on values entered in dynamic jsp page.
Now i want to read all those values entered to xml in my other jsp
page.But as dynamic values can be any in no i don't know how could i
populate all those in my jsp again which sholud read all data from xml.
Items can be any so like we create them dynamically with fileds
item title/link/description.I need to read them from xml file and display them dynamically here.

<%@ page language="java"
import="java.io.*"
import="java.util.*"
import="org.jdom.*,
org.jdom.input.*,
org.jdom.output.*"
%>
<%
String s1=null,s2=null,s3=null,s4=null,s5=null,s6=null;
%>
<%
try{SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File("c:\\Rss.xml"));
Element root = doc.getRootElement();
doc.getParent();
Element channel = root.getChild("channel");//channel

s1=channel.getChild("title").getText();
s2=channel.getChild("link").getText();
s3=channel.getChild("description").getText();

List item = channel.getChildren("item");//item
Iterator itr = item.iterator();
while (itr.hasNext()) {
Element items = (Element) itr.next();
s4=items.getChild("title").getText();
s5=items.getChild("link").getText();
s6=items.getChild("description").getText();
}
}catch (Exception e) {
e.printStackTrace();
}
%>
<head><title>RSS Channel Display Page</title></head>
<script type="text/javascript">
var browser_name=navigator.userAgent;
function getDeleteButtonForGivenID(idname)
{
var result="";
result+="<span style='font-size:16px'>";
result+="<table cellspacing='0' cellpadding='0' border='0'>";
result+="\n <tr><td class='button_side'>";
result+="\n <img
src='/castylesr2/images/pagebutton-start.png' width='0' height='0'
id='button_"+idname+"startimg' alt='' />";
result+="\n </td>";
result+="\n <td class='button_center_new'
id='button_"+idname+"buttoncenter' >";
result+="\n <button type='button' value='delete'
onclick='callDeleteThis('task_table_"+idname+"');'
id='button_"+idname+"' title='delete this task'
onmouseover='document.getElementById('button_"+idn ame+"').className='buttons_onmouseover';document.g etEle mentById('button_"+idname+"buttoncenter').classNam e='button_center_onmouseove r';document.getElementById('button_"+idname+"start img').src='/castylesr2/images/pagebutton-start-over.png';document.getElementById('button_"+idname +"endimg').src='/castylesr2/images/pagebutton-end-over.png';'
onmouseout='document.getElementById('button_"+idna me+"').className='buttons';document.getElementById ('bu tton_"+idname+"buttoncenter').className='button_ce nter_new';docum ent.getElementById('button_"+idname+"startimg').sr c='/castylesr2/images/pagebutton-start-over.png';document.getElementById('button_"+idname +"endimg').src='/castylesr2/images/pagebutton-end-over.png';'>";
result+= "delete";
result+= "</button>";
result+="\n </td>";
result+="\n <td class='button_side'>";
result+="\n <img
src='/castylesr2/images/pagebutton-end.png' width='0' height='0'
id='button_"+idname+"endimg' alt='' />";
result+="\n </td>";
result+="\n </tr>";
result+="\n</table>";
result+="\n</span>";
return result;
}
function getElementBasedOnOS(idname)
{
if(browser_name.indexOf("Mozilla") != -1)
return document.getElementById(idname);
else
return document.all[idname];
}
function callDeleteThis(trname)
{
var tmp=document.getElementById(trname);
tmp.innerHTML="";

}

function getElementBasedOnOS(idname)
{
if(browser_name.indexOf("Mozilla") != -1)
return document.getElementById(idname);
else
return document.all[idname];
}
function callAddMoreFunction(itemTitle, itemLink, itemDesc)
{
tasks_counter++;
var obj = getElementBasedOnOS("tasks_table");
var counter=1;
var obj_id=null;
var id_name="task_table_"+counter;

var main_obj=obj;
for (;obj_id=getElementBasedOnOS(id_name)
{
if(obj_id==null)
break;
var temp_Compname_id=getElementBasedOnOS("itemTitle_"+ counter);
if(temp_Compname_id==null)
{
main_obj=obj_id;
break;
}

counter++;
id_name="task_table_"+counter;
obj_id=null;
}

var string_tobe_printed="<table><tr><td
id='task_table_"+counter+"'><table><tr><td
style='font-size:12px;font-weight:bold;'> Serial No "+counter+"
</td><td>"+getDeleteButtonForGivenID(counter)+"</td></tr>"+
"<tr><td width='30%'> itemTitle </td><td><input type='text'
id='itemTitle_" +counter+ "' name='itemTitle_" +counter+ "'
value='"+itemTitle+"' size='60'/> *</td></tr>"+
"<tr><td width='30%'> itemLink </td><td><input type='text'
id='itemLink_" +counter+ "' name='itemLink_" +counter+ "'
value='"+itemLink+"' size='60'/> *</td></tr>"+
"<tr><td width='30%'> itemDesc </td><td><textarea rows=5 cols=50
id='itemDesc_" +counter+ "' name='itemDesc_" +counter+ "'
>"+itemDesc+"</textarea></td></tr>"+

"<tr><td width='30%'><br/></td></tr>" +
"</table></td></tr></table>";

if(main_obj.id == obj.id)
{
main_obj.innerHTML = main_obj.innerHTML + string_tobe_printed;
}
else
{
main_obj.innerHTML= string_tobe_printed;
}

StoreFormData();
LoadFormData();
}
var TotalFormData=new Array();
function StoreFormData()
{
TotalFormData=new Array();
for(var i=1;i <= tasks_counter;i++)
{
var Task=new Array(3);
Task[0]=Task[1]=Task[2]="";

Task[0]=getElementBasedOnOS("itemTitle_"+i)!=null?getElem entBasedOnOS("itemTitle_"+i).value:"";
Task[1]=getElementBasedOnOS("itemLink_"+i)!=null?getEleme ntBasedOnOS("itemLink_"+i).value:"";
Task[2]=getElementBasedOnOS("itemDesc_"+i)!=null?getEleme ntBasedOnOS("itemDesc_"+i).value:"";
TotalFormData[i]=Task;
Task=null;
}

}

function LoadFormData()
{
for(var i=1;i <= tasks_counter; i++)
{
if(getElementBasedOnOS("itemTitle_"+i)!=null)
getElementBasedOnOS("itemTitle_"+i).value=TotalFor mData[i][0];
if(getElementBasedOnOS("itemLink_"+i)!=null)

getElementBasedOnOS("itemLink_"+i).value=TotalForm Data[i][1];
if(getElementBasedOnOS("itemDesc_"+i)!=null)

getElementBasedOnOS("itemDesc_"+i).value=TotalForm Data[i][2];

}
TotalFormData=null;
}

</script>
<!-- End of the Dynamic Table structures -->
</head>
<body>
<body bgcolor="#ffffff">
<form action="RssActionServlet"
onsubmit="getElementBasedOnOS('total_tasks_no').va lue=tasks_ counter;"
id="tasks_form" method="post">
<input type="hidden" name="sendto" value="InsertAlternative"/>
<br>
<table align="center" border="1">
<tr align="left" valign="middle">
<td align="right"><b>
Channel Title:</b></td>
<td align="right">
<input name="channel_title" size="66" type="text" value="<%= s1
%>"></td>
</tr>
<tr align="left" valign="middle">
<td align="right">
<b>Channel Link:</b></td>
<td align="right"><input name="channel_link" size="66" type="text"
value="<%= s2 %>"></td></tr>
<tr align="left" valign="middle"><td align="right">
<b>Channel Desc:</b></td>
<td align="right"><textarea name="channel_desc" rows="5"
cols="50"/><%= s3 %></textarea></td></tr>
</table>
<table align="center" border="1">
<tr align="left" valign="middle">
<td align="right"><b>Item Title:</b></td>
<td align="right"><input name="item1_title" size="66" type="text"
value="<%= s4%>"></td>
</tr>
<tr align="left" valign="middle">
<td align="right"><b>Item Link:</b></td> <td align="right">
<input name="item1_link" size="66" type="text" value="<%= s5%>"></td>
</tr>
<tr align="left" valign="middle">
<td align="right"><b>Item Desc:</b></td> <td align="right">
<textarea name="item1_desc" rows="5" cols="50" wrap = "virtual"><%=
s6%></textarea></td>
<br><td>
<span style="font-size:16px"><caui:button type="submit" value="Edit"
title="edit alternative" id="EditAlternative"
onclick="callEditThisItem();"/>
<br>
<span style="font-size:16px"><caui:button type="submit" value="Delete"
title="Delete this alternative" id="DeleteAlternative"
onclick="callDeleteThisItem();"/>
</td>
</tr></table>
<table>
<tr>
<td>
<span style="font-size:16px"><caui:button
value='Add More' title='Add More Alternatives. [Alternatives will be
added in the end]' id='addMoreAlternatives' disabled='false'
onclick="callAddMoreFunction('','','');"/></span>
</td>
<td>
<span style="font-size:16px"><caui:button
type='submit' value='Save' title='save alternatives'
id='SaveAlternatives' disabled='false' /></span>
</td>
</tr>
</table>
<br/>
</form>
</cauiagesection>
<center><p></p></center></body></html>

thanks
Vijendra


vijendra
vijendra is offline   Reply With Quote
Old 10-06-2006, 01:33 PM   #2
arpit1988
Junior Member
 
Join Date: Oct 2006
Posts: 3
Default
this is very easy simply do some simple steps listed on java tutorials.


arpit1988
arpit1988 is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46