473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How i can populate all fileds dynamically in jsp page based on contents found in xml file?

vj
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.
I am able to call values from file in my jsp page.
But as dynamic values can be any in no i don't know how colud i
populate all those in my jsp again which sholud read all dta from xml.

some code i am sending which is in working condition.
Some modification to this code can solve my problem.

Here 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.

Please tell me if i can modify this code naywhere to perform so.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<%@ taglib prefix="caui" uri="http://www.ca.com/ca-corpui/r2/jsptags"
%>
<caui:uiresources />
<%@ page language="java"
import="java.io.*"
import="java.util.*"
import="org.jdom.*,
org.jdom.input.*,
org.jdom.output.*"
import="com.ca.corpui.JSPTags.*,
com.ca.corpui.model.*"
import="src.RssFileHandler,src.RssActionServlet"
%>
<%
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 etElementById('button_"+idname+"buttoncenter').cla ssName='button_center_onmouseover';document.getEle mentById('button_"+idname+"startimg').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 ('button_"+idname+"buttoncenter').className='butto n_center_new';document.getElementById('button_"+id name+"startimg').src='/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)
{
//alert(trname);
var tmp=document.getElementById(trname);
//alert(tmp);
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;
// alert("id_name is "+id_name);
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;
// alert(main_obj.innerHTML);
}
else
{
main_obj.innerHTML= string_tobe_printed;
}

StoreFormData();
LoadFormData();
}

var TotalFormData=new Array();

function StoreFormData()
{
TotalFormData=new Array();
//alert("StoreFormData");
//alert(tasks_counter);
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;
//alert(getElementBasedOnOS("Compname_"+i));
//alert(getElementBasedOnOS("Compname_"+i).value);
//alert(getElementBasedOnOS("description_"+i));
//alert(getElementBasedOnOS("description_"+i).value) ;
//alert("Task[0]" + Task[0]);
//alert("Task[1]" + Task[1]);
//alert("TotalFormData[i]" + TotalFormData[i]);
Task=null;
}
}

function LoadFormData()
{
//alert("LoadFormData");
//alert(tasks_counter);
for(var i=1;i <= tasks_counter; i++)
{
//alert(getElementBasedOnOS("Compname_"+i));
//alert(TotalFormData[i][0]);
//alert(getElementBasedOnOS("description_"+i));
//alert(TotalFormData[i][1]);
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 -->
<script language="javascript">
window.parent.document.title="RSSEditForm";
</script>
</head>
<body>
<caui:pagesection title="RSSEditForm" width='100'>
<caui:pageSectionHeaderLevelButtons>
<caui:pageSectionHeaderLevelButton id='cancel' value='Cancel'
onclick='javascript:history.go(-1)'/>
</caui:pageSectionHeaderLevelButtons>
<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/>
<table>
<tr><td id="tasks_table" width="100%">
</td>
</tr>
</table>
<script type="text/javascript">
var tasks_counter=0;
</script>
<br/>
<input type="hidden" name="total_tasks_no" id="total_tasks_no"
value="" />
<table>
<tr>
<td>
<span style="font-size:16px">
<caui:button value='Add More ' title='add more
alternatives' id='addMoreAlternatives' disabled='false'
onclick="callAddMoreFunction('','','');"/>
</span>
<!-- <input type="submit" name="update"
value="update"/-->
</td>
<td>
<span style="font-size:16px">
<caui:button type='submit' value='Save'
title='save alternatives' id='SaveAlternatives' disabled='false' />
</span>
</td>
</tr>
</table>
</form>
</caui:pagesection>
<center><p></p></center></body></html>

thanks
Vijendra

Oct 3 '06 #1
1 6471
VK

vj wrote:
How i can populate all fileds dynamically in jsp page based on contents
found in xml file?
By using XSLT maybe?

Oct 3 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: alex | last post by:
Hi, I am looking for a way to populate an HTML table from an external local text file which looks like this: DATE/TIME LAT. LON. DEPTH. ML....
0
by: T.H.M | last post by:
This is the all code. Very simple and short. I need to populate a treeView in aspx page (web form) from XML file. I get en completion error:No overload for method 'TreeNode' takes '1' arguments ....
6
by: John Ruiz | last post by:
Greetings, I originally posted this to microsoft.public.dotnet.framework.aspnet.datagridcontrol two weeks ago, but no one was able to answer. I am unable to dynamically add columns to a...
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
5
by: Arpan | last post by:
In order to populate any server control with data dynamically, is it ALWAYS NECESSARY to either BIND the DataSource to that server control or call the DataBind method of that server control? For...
4
by: Kevin Blount | last post by:
bit long winded this one, so stick with me: I'm trying to create a form that can go to one of 3 places, depending on various elements. My form control looks like this: <form runat="server"...
3
by: Yi Chen | last post by:
We have a drop down list on a PHP page, with several product names, and when people click one item, we will refresh the same page with the product name as parameter, and in turn we want to include...
0
by: vijendra | last post by:
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...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.