aspose file tools*
The moose likes Other Open Source Projects and the fly likes YUI Autocomplete with XML and JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "YUI Autocomplete with XML and JSP" Watch "YUI Autocomplete with XML and JSP" New topic
Author

YUI Autocomplete with XML and JSP

Sony Kumar
Greenhorn

Joined: May 31, 2010
Posts: 5
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
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 31, 2010
Posts: 5
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 31, 2010
Posts: 5
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

No. Although you could cheat and put it in the DTO. Why can't you change it?
Sony Kumar
Greenhorn

Joined: May 31, 2010
Posts: 5
Sorry I could not understand. In what way i have cheated?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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?
praveen kumar reddy
Greenhorn

Joined: Jun 07, 2010
Posts: 1
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please start new threads for new topics, and make sure you post in the correct forum. Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: YUI Autocomplete with XML and JSP