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

Discussion in 'Javascript' started by vj, Oct 3, 2006.

  1. vj

    vj Guest

    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_"+idname+"').className='buttons_onmouseover';document.getElementById('button_"+idname+"buttoncenter').className='button_center_onmouseover';document.getElementById('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_"+idname+"').className='buttons';document.getElementById('button_"+idname+"buttoncenter').className='button_center_new';document.getElementById('button_"+idname+"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?getElementBasedOnOS("itemTitle_"+i).value:"";

    Task[1]=getElementBasedOnOS("itemLink_"+i)!=null?getElementBasedOnOS("itemLink_"+i).value:"";

    Task[2]=getElementBasedOnOS("itemDesc_"+i)!=null?getElementBasedOnOS("itemDesc_"+i).value:"";
    TotalFormData=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" + TotalFormData);
    Task=null;
    }
    }

    function LoadFormData()
    {
    //alert("LoadFormData");
    //alert(tasks_counter);
    for(var i=1;i <= tasks_counter; i++)
    {
    //alert(getElementBasedOnOS("Compname_"+i));
    //alert(TotalFormData[0]);
    //alert(getElementBasedOnOS("description_"+i));
    //alert(TotalFormData[1]);
    if(getElementBasedOnOS("itemTitle_"+i)!=null)

    getElementBasedOnOS("itemTitle_"+i).value=TotalFormData[0];
    if(getElementBasedOnOS("itemLink_"+i)!=null)

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

    getElementBasedOnOS("itemDesc_"+i).value=TotalFormData[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').value=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
    vj, Oct 3, 2006
    #1
    1. Advertising

  2. vj

    VK Guest

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


    By using XSLT maybe?
    VK, Oct 3, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vj
    Replies:
    0
    Views:
    272
  2. Tradeorganizer
    Replies:
    5
    Views:
    157
    Tradeorganizer
    Jan 31, 2007
  3. heylow
    Replies:
    6
    Views:
    122
    Tad McClellan
    Sep 15, 2007
  4. jnag
    Replies:
    2
    Views:
    290
    Nick Fletcher
    Feb 27, 2008
  5. Lewis
    Replies:
    1
    Views:
    192
Loading...

Share This Page