Question about struts inside javascript variable

Discussion in 'Java' started by spallared, May 4, 2007.

  1. spallared

    spallared Guest

    Hi, actually i'm using a struts + javascript to create HTML code that
    i use inside a popup window...

    My (working) code is:

    idoc="";
    /* var cols =
    parent.document.getElementById('rowA').getElementsByTagName('THEAD')
    [0].getElementsByTagName('TH'); */
    var idoc='<html:form styleId="InsertNewItem" action="/nw/
    insertnewitem.do?target='+parent.newPop.action+'">';
    idoc+='<TABLE><TBODY>';
    var hiddenForm = getParentObj('hidden_data_form');
    var cols = hiddenForm.getElementsByTagName('INPUT');
    var test;
    test="cippa";
    for(k = 0; k < cols.length; k++) {
    if(cols[k].id.substring(0,3) == "hh_")
    {

    idoc += "<TR><TD>";
    idoc += cols[k].id.substring(3);
    idoc += "</TD><TD>";
    idoc += '<html:text property="'+cols[k].id+'" value=""/>';
    idoc += "</TD></TR>";
    }

    }

    idoc+='</TBODY></TABLE>';
    idoc+='</html:form>';
    var towr = document.getElementById("subwin_body");
    towr.innerHTML = idoc;

    The problem is when i try to add a <html:select> to the code, more
    precisely i added just before the end of the table these lines:

    idoc += "<TR><TD>Ditta:";
    idoc += "</TD><TD>";
    idoc += '<html:select property="ditta_id">';
    idoc += '<html :eek: ptions collection="sel_ditta_list"
    labelProperty="label" property="value"/>';

    idoc += '</html:select>';
    idoc += "</TD></TR>";

    .... but i cannot get it to work because struts seems to make some
    mistake with quotes and in javascript console window i get this error:

    Error: unterminated string literal
    File source: http://localhost:8180/nw/jsp/insertNewItemOperatore.jsp
    Row: 121, Column: 10
    Source Code:
    idoc += '<option value="1">1</option>

    (note the missing ending single-quote)

    I can't understand why because with <html:text> field the same "trick"
    works fine... any ideas?

    Thanks in advance
    Luca
    spallared, May 4, 2007
    #1
    1. Advertising

  2. spallared

    Sanjay Guest

    spallared wrote:
    > Hi, actually i'm using a struts + javascript to create HTML code that
    > i use inside a popup window...
    >
    > My (working) code is:
    >
    > idoc="";
    > /* var cols =
    > parent.document.getElementById('rowA').getElementsByTagName('THEAD')
    > [0].getElementsByTagName('TH'); */
    > var idoc='<html:form styleId="InsertNewItem" action="/nw/
    > insertnewitem.do?target='+parent.newPop.action+'">';
    > idoc+='<TABLE><TBODY>';
    > var hiddenForm = getParentObj('hidden_data_form');
    > var cols = hiddenForm.getElementsByTagName('INPUT');
    > var test;
    > test="cippa";
    > for(k = 0; k < cols.length; k++) {
    > if(cols[k].id.substring(0,3) == "hh_")
    > {
    >
    > idoc += "<TR><TD>";
    > idoc += cols[k].id.substring(3);
    > idoc += "</TD><TD>";
    > idoc += '<html:text property="'+cols[k].id+'" value=""/>';
    > idoc += "</TD></TR>";
    > }
    >
    > }
    >
    > idoc+='</TBODY></TABLE>';
    > idoc+='</html:form>';
    > var towr = document.getElementById("subwin_body");
    > towr.innerHTML = idoc;
    >
    > The problem is when i try to add a <html:select> to the code, more
    > precisely i added just before the end of the table these lines:
    >
    > idoc += "<TR><TD>Ditta:";
    > idoc += "</TD><TD>";
    > idoc += '<html:select property="ditta_id">';
    > idoc += '<html :eek: ptions collection="sel_ditta_list"
    > labelProperty="label" property="value"/>';
    >
    > idoc += '</html:select>';
    > idoc += "</TD></TR>";
    >
    > ... but i cannot get it to work because struts seems to make some
    > mistake with quotes and in javascript console window i get this error:
    >
    > Error: unterminated string literal
    > File source: http://localhost:8180/nw/jsp/insertNewItemOperatore.jsp
    > Row: 121, Column: 10
    > Source Code:
    > idoc += '<option value="1">1</option>
    >
    > (note the missing ending single-quote)
    >
    > I can't understand why because with <html:text> field the same "trick"
    > works fine... any ideas?
    >
    > Thanks in advance
    > Luca
    >


    Did you try adding an extra quote? does it work?
    Sanjay, May 4, 2007
    #2
    1. Advertising

  3. spallared

    Lew Guest

    spallared wrote:
    >> Hi, actually i'm using a struts + javascript to create HTML code that
    >> i use inside a popup window...
    >>
    >> My (working) code is:
    >>
    >> idoc="";
    >> /* var cols =
    >> parent.document.getElementById('rowA').getElementsByTagName('THEAD')
    >> [0].getElementsByTagName('TH'); */
    >> var idoc='<html:form styleId="InsertNewItem" action="/nw/
    >> insertnewitem.do?target='+parent.newPop.action+'">';
    >> idoc+='<TABLE><TBODY>';
    >> var hiddenForm = getParentObj('hidden_data_form');
    >> var cols = hiddenForm.getElementsByTagName('INPUT');
    >> var test;
    >> test="cippa";
    >> for(k = 0; k < cols.length; k++) {
    >> if(cols[k].id.substring(0,3) == "hh_")
    >> {
    >>
    >> idoc += "<TR><TD>";
    >> idoc += cols[k].id.substring(3);
    >> idoc += "</TD><TD>";
    >> idoc += '<html:text property="'+cols[k].id+'" value=""/>';
    >> idoc += "</TD></TR>";
    >> }
    >>
    >> }
    >>
    >> idoc+='</TBODY></TABLE>';
    >> idoc+='</html:form>';
    >> var towr = document.getElementById("subwin_body");
    >> towr.innerHTML = idoc;
    >>
    >> The problem is when i try to add a <html:select> to the code, more
    >> precisely i added just before the end of the table these lines:
    >>
    >> idoc += "<TR><TD>Ditta:";
    >> idoc += "</TD><TD>";
    >> idoc += '<html:select property="ditta_id">';
    >> idoc += '<html :eek: ptions collection="sel_ditta_list"


    Was this copied literally? That extra space before the colon and after the
    'o' might be trouble.

    >> labelProperty="label" property="value"/>';
    >>
    >> idoc += '</html:select>';
    >> idoc += "</TD></TR>";
    >>
    >> ... but i cannot get it to work because struts seems to make some
    >> mistake with quotes and in javascript console window i get this error:
    >>
    >> Error: unterminated string literal
    >> File source: http://localhost:8180/nw/jsp/insertNewItemOperatore.jsp
    >> Row: 121, Column: 10
    >> Source Code:
    >> idoc += '<option value="1">1</option>
    >>
    >> (note the missing ending single-quote)
    >>
    >> I can't understand why because with <html:text> field the same "trick"
    >> works fine... any ideas?


    First: PLEASE indent your code (using spaces) for readability!

    I am surprised that a client-side insertion of JSP tags would work, since JSP
    tags are parsed server side.

    --
    Lew
    Lew, May 5, 2007
    #3
  4. spallared

    david.karr Guest

    On May 5, 5:36 am, Lew <> wrote:
    > spallared wrote:
    > >> Hi, actually i'm using a struts + javascript to create HTML code that
    > >> i use inside a popup window...

    >
    > >> My (working) code is:

    >
    > >> idoc="";
    > >> /* var cols =
    > >> parent.document.getElementById('rowA').getElementsByTagName('THEAD')
    > >> [0].getElementsByTagName('TH'); */
    > >> var idoc='<html:form styleId="InsertNewItem" action="/nw/
    > >> insertnewitem.do?target='+parent.newPop.action+'">';
    > >> idoc+='<TABLE><TBODY>';
    > >> var hiddenForm = getParentObj('hidden_data_form');
    > >> var cols = hiddenForm.getElementsByTagName('INPUT');
    > >> var test;
    > >> test="cippa";
    > >> for(k = 0; k < cols.length; k++) {
    > >> if(cols[k].id.substring(0,3) == "hh_")
    > >> {

    >
    > >> idoc += "<TR><TD>";
    > >> idoc += cols[k].id.substring(3);
    > >> idoc += "</TD><TD>";
    > >> idoc += '<html:text property="'+cols[k].id+'" value=""/>';
    > >> idoc += "</TD></TR>";
    > >> }

    >
    > >> }

    >
    > >> idoc+='</TBODY></TABLE>';
    > >> idoc+='</html:form>';
    > >> var towr = document.getElementById("subwin_body");
    > >> towr.innerHTML = idoc;

    >
    > >> The problem is when i try to add a <html:select> to the code, more
    > >> precisely i added just before the end of the table these lines:

    >
    > >> idoc += "<TR><TD>Ditta:";
    > >> idoc += "</TD><TD>";
    > >> idoc += '<html:select property="ditta_id">';
    > >> idoc += '<html :eek: ptions collection="sel_ditta_list"

    >
    > Was this copied literally? That extra space before the colon and after the
    > 'o' might be trouble.
    >
    >
    >
    > >> labelProperty="label" property="value"/>';

    >
    > >> idoc += '</html:select>';
    > >> idoc += "</TD></TR>";

    >
    > >> ... but i cannot get it to work because struts seems to make some
    > >> mistake with quotes and in javascript console window i get this error:

    >
    > >> Error: unterminated string literal
    > >> File source:http://localhost:8180/nw/jsp/insertNewItemOperatore.jsp
    > >> Row: 121, Column: 10
    > >> Source Code:
    > >> idoc += '<option value="1">1</option>

    >
    > >> (note the missing ending single-quote)

    >
    > >> I can't understand why because with <html:text> field the same "trick"
    > >> works fine... any ideas?

    >
    > First: PLEASE indent your code (using spaces) for readability!
    >
    > I am surprised that a client-side insertion of JSP tags would work, since JSP
    > tags are parsed server side.
    >
    > --
    > Lew


    I'm finding it hard to follow exactly what's happening here, but the
    last comment here is very important. Emitting tags like "<html:text>"
    in javascript will have absolutely no useful impact. Struts tags (and
    other tag libraries like it) are processed on the server side, when
    the JSP page is compiled into a Java servlet class. These tags are not
    interpreted by the browser in any way.
    david.karr, May 5, 2007
    #4
    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. Dave
    Replies:
    0
    Views:
    774
  2. sin
    Replies:
    3
    Views:
    708
    Sudsy
    Feb 22, 2004
  3. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Javascript inside struts

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Jan 29, 2007, in forum: Java
    Replies:
    1
    Views:
    644
    ceasaro
    Jan 29, 2007
  4. Dave
    Replies:
    0
    Views:
    417
  5. Jean-François Michaud

    Javascript inside struts

    Jean-François Michaud, Jan 29, 2007, in forum: Javascript
    Replies:
    5
    Views:
    478
    Jean-François Michaud
    Jan 29, 2007
Loading...

Share This Page