• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

YUI Autocomplete with XML and JSP

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI All,

I have an base action class with is an abstract class extending the Sruts Action class. In my base action class i have different methods. Few of the methods has got ServletRequest and ServletResponse as parameters. But one method has got only the request object and bean object as parameter.
Firstly i would like to know if i can get the response object in this method without changing the signature of the method? because i need the response object to flush the XML to my jsp page as part of YUI Autocomplete.

Secoondly i would like to know why i cannot print my XML page in JSP using out.println(). The obtained XML is converted to String and am trying to flush the String, but not happening.

Please help
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sony Kumar wrote:Firstly i would like to know if i can get the response object in this method without changing the signature of the method?


Depends on how it's being called, or the viability of using a thread-local response. In general, however, if you want an additional parameter, you'd need to add an additional parameter.

Secoondly i would like to know why i cannot print my XML page in JSP using out.println(). The obtained XML is converted to String and am trying to flush the String, but not happening.


You've given us nothing to go on, so it's impossible to help.
 
Sony Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry for that

public abstract class BaseAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception{
BaseDTO inputDTO = null;
BaseDTO outputDTO = null;
inputDTO = gatherInput(request, response);
request.setAttribute(INPUT_DTO, inputDTO);
//set userid
String userId = request.getRemoteUser();

if(userId == null){
userId = "1";
}
if(isExecuteLocal()){
outputDTO = doExecuteLocal(inputDTO, request);
}
else{
String commandSessionName = mapping.getCommandSession();
if(commandSessionName == null){
outputDTO = doExecute(inputDTO);
}
else{
outputDTO = doExecute(inputDTO, commandSessionName);
}
}

postExecute(inputDTO, outputDTO, request);
return selectView(mapping, inputDTO, outputDTO);
}
protected abstract BaseDTO gatherInput(HttpServletRequest request, HttpServletResponse response);

protected BaseDTO doExecute(BaseDTO inputDTO){
return doExecute(inputDTO, null);
}
protected void postExecute(BaseDTO inputDTO, BaseDTO outputDTO){
}
protected void postExecute(BaseDTO inputDTO, BaseDTO outputDTO, HttpServletRequest request){
}
protected ActionForward selectView(ActionMapping mapping, BaseDTO inputDTO, BaseDTO outputDTO){
ActionForward forward;
if(outputDTO.hasExceptions())
forward = mapping.findForward("failure");
else{
forward = mapping.findForward("success");
}
return forward;
}
protected boolean isExecuteLocal(){
return false;
}
protected BaseDTO doExecuteLocal(BaseDTO inputDTO, HttpServletRequest request){
return new VoidDTO();
}
}


In my postExecute(BaseDTO inputDTO, BaseDTO outputDTO, HttpServletRequest request) implementation, i require the response object without adding a new parameter of response to the existing method.

regards
Sony
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Code like this makes me crazy:Why should I have to read ~ ten lines when ~ two would do?Or if you're anti-ternary:Less cognitive overhead: I don't have to keep reading to find out if anything else important happens.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the "userId" local for? It's set, then never used again.

Why differentiate between commandSessionName being null or not? The call to doExecute(inputDTO) just delegates to a call using null anyway, so why bother checking?Half the lines, and removes the extraneous bits that don't actually do anything. Just sayin'... keep it clean.
 
Sony Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the advise. I am new comer in posting forums. I will make the necessary changes as advised. Please let me know if can get the response object in the postExecute(). I tried converting the xml to string and setting the string as request attribute.

In my JSP page am getting the request attribute and using response object of JSP i am trying to print the XML but in vain.

In JSP Code:


But the xml is not getting printed...Please help
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Although you could cheat and put it in the DTO. Why can't you change it?
 
Sony Kumar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry I could not understand. In what way i have cheated?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I said you *could* cheat and put the request in the DTO, thus not changing the signature of the method.

Why can't you change it?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
I am facing a autocomplete problem solving. actually i have a selection box and text box in jsp. after i selecting some value from selection box i want show the autocompleted values in text box. my flow is one jsp, servlet, DAO and DTO.

Please help me
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please start new threads for new topics, and make sure you post in the correct forum. Thanks!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic