• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Ajax Problem : passing html:select element in returnstring

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i have to pass back a html:select box when the user selects some combo box using ajax async call. Right now i have the code something like this
StringBuffer html = new StringBuffer("");
html.append("<html:select property=\"parentGroupCode\" onchange=\"getGroups()\">");
html.append("<html ption value=\"hello\">hello</html ption><html ption value=\"mello\">mello</html ption>");
html.append("</html:select>");
mLogger.debug(html.toString());

/*
html.append("<select id=\"parentGroupCode\" onChange=\"getGroups()\">");
html.append("<option value=\"hello\">hello</option><option value=\"mello\">mello</option>");
html.append("</select>");
*/
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.write(html.toString());
out.flush();

The problem it doens't render the html:select element and i could only see mello and hello there. If i pass anormal html select box as i have shown in comments in works. Any idea since i have to pass that html:select string since i have to use a property from my action form.
 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am assuming that your string buffer is in a servlet? In that case, there is no JSP rendering that goes on in order to evaluate the custom tags. Just because you are making the request via an Ajax call does not change how the request is handled. If you want JSP elements to be evaluated, they must be in a JSP.

So treat your Ajax request like any other and forward from the servlet to a JSP page to render the view.
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the prompt reply.
As you said, the string buffer creation is done in a Action Servlet. But then also even thouht i use a scriplet in jsp and try to create the Html:select tag it still doen't render on the page. for example


<%
String testStr = "<html ption value=\"hello\">hello</html ption><html ption value=\"mello\">mello</html ption>";
%>
<html:select property="parentGroupCode" onchange="getGroups()">
<%=testStr%>
</html:select>

With this also it doens't render the html page. Could you be more precise or any help on this.
Thanks a lot.
 
Bear Bibeault
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you putting custom tags in a string? That will not work even when hitting the JSP directly via the browser.
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks i realized that. so that mean Ajax is just waste of time. The reason is coz we have a web application which builds dynamci combo boxes using async calls with Ajax. Since i cant renders custom tag elements i hope Ajax is not worth it. Do you think Ajax has a workaround for this.
 
Bear Bibeault
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As I said, the problem doesn't really have anything to do with Ajax, but rather than with what you are trying to do.

There is no work-around using Ajax or anything else. You cannot build up custom tags in a string and expect them to be translated. Custom tags are evaluated at JSP evaluation time, but strings are created at execution time -- far too late for the tags within them to be evaluated.
[ October 10, 2005: Message edited by: Bear Bibeault ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic