473,231 Members | 1,591 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,231 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 6456
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: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.