• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Question about struts inside javascript variable

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 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

[ May 04, 2007: Message edited by: Luca Spallared ]
[ May 04, 2007: Message edited by: Luca Spallared ]
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those three lines of Struts code produce the output by themselves and can't be split up. Try something like this:

idoc += '<html:select property="ditta_id"><html ptions collection="sel_ditta_list" labelProperty="label" property="value"/></html:select>';
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The difference between <html:text> and <html:options> is that <html:options> generates multiple lines of HTML code, whereas <html:text> only generates one line. When Struts is generating these multiple lines of code separated by carriage returns, it doesn't know that you've included it in a JavaScript quoted string, so it doesn't know to enclose each line in quotes. That's why it's not working.

At the moment, I can't think of a way to make this work with Struts tags. Maybe someone else will post a possible solution. Unless someone does, I'd suggest using plain old HTML tags for your select/option tags rather than Struts tags.
[ May 04, 2007: Message edited by: Merrill Higginson ]
 
Luca Spallared
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeanne Boyarsky:
Those three lines of Struts code produce the output by themselves and can't be split up. Try something like this:

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



Thanks for your reply but it didn't resolve the problem.
Seems that Struts html ptions statement cut everything follows the tag and this is bad..

BTW: Error is still...

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

Luca
 
Jeanne Boyarsky
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Luca,
Can you post the code you are using now?
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic