Application has two packages one for jsp (struts.xml) and another for json results (struts-json.xml) . Actions in both packages share the same interceptors. When interceptor interrupts and returns error then for ajax request I want to return serialized json object back. Object has error code and description.
To achieve that I redirected to another method :
<result name="errorFromInterceptor" type="redirectAction">
Is there a better way to populate and return object when request is captured by interceptor?
Related
I'm using Tapestry 5.3.
In a Tapestry component, I'm trying to implement an event handler that creates responses to AJAX requests.
I know that I can call MarkupWriterFactory#newPartialMarkupWriter to get an instance of MarkupWriter and then generate the response using this instance. The built-in mixin Autocomplete generates responses to AJAX requests in this way. Here is a trivial example:
#Inject
private MarkupWriterFactory markupWriterFactory;
#OnEvent("myevent")
Object generatePartialMarkup() {
final ContentType contentType = new ContentType("text/html");
final MarkupWriter markupWriter = markupWriterFactory.newPartialMarkupWriter(contentType);
markupWriter.element("hr");
markupWriter.end();
return new TextStreamResponse(contentType.toString(), markupWriter.toString());
}
However, this is a clumsy solution for a partial HTML that is much more complex than just a hr element. I wonder if there is a chance to create such response using a Tapestry block rather than generating the response "manually" via MarkupWriter. If I just return an instance of block from the event handler, an exception is thrown when the event is triggered.
Thanks.
Looks like you're making life difficult for yourself. From what I can see you can solve this with an eventlink, a zone and an event handler which returns a Block. See here for more info.
Not entirely sure what you're doing but if you need to render a block as a string, see the capture component here
I am sending ajax request from 1 JSP to other JSP. In called JSP when I try to get value of a HTML control with the help of request.getParameter("HTML_control_name/id") It returns null.
request.getParameter("HTML_control_name/id")
request.getParameter() returns the string of the parameters sent in the HTTP Requests.
You can get the value of your form attributes through request.getParameter("Name Of form Attribute")
I'm just a rookie, and I'm trying to learn JSP (I'm using scriptlet), servlet, beans and Ajax.
I'm validating some registration forms by calling a servlet (through Ajax). Every time a character is inserted, the Ajax function is recalled and "value" is sent to a servlet whose job is to check if this value is OK. The servlet gets an HttpSession, then it operates on the passed value and saves it into a bean and finally sets session.setAttribute("bean_name", bean). In JSP I inserted the jsp:usebean tag with scope=session. I got no problem retrieving values, for example <%= bean.getUsername()%>, but the problem is all the form values don't get updated unless I refresh the page.
What could it be?
You make the AJAX call to the Servlet. The Servlet does what it needs to do, and renders a response. However, the AJAX call was made by means of JavaScript, after the page was already rendered.
What you need to do is to edit the JavaScript code that issues the AJAX call. Once the AJAX call takes place, your JavaScript code has to wait until a response is returned from the Servlet, and then use client-side facilities (such as DHTML) to edit the already-rendered page.
Is it possible to modify the form-data content of an HttpRequestMessage in a filter or HttpMessageHandler.
I want to read a value from the querystring and dependent on certain logic I want to update the contents of the form-data passed in the HttpRequestMessage before it hits the action method on the controller, that way I can still rely on the built in model binding and check the ModelState.IsValid() method.
Is this possible?
I don't believe the request content can be modified as it is a "read once" stream. What sort of changes are you making to the content?
I have a JSP page which has a form with an input text. When I submit, it goes to a servlet. The servlet processes and creates some objects and sets in request using request.setAttribute(). It then forwards to a page which has some custom JSP tags which use the objects set in servlet.
I want to replace this by Ajax. I have implemented it as follows:
First, the form is submitted through Ajax using POST, the objects which were set earlier using request.setAttribute() are converted to JSON string and sent as response. On success, there is another Ajax GET call to a JSP page which has my custom tags and the JSON string is passed as parameter. The response of this Ajax call is set inside a div.
But it are two Ajax requests. How can I make it a single Ajax request instead?
As per the comments, you just need to let the first request forward to the desired JSP instead of returning the JSON string which you in turn pass back to the JSP.
request.getRequestDispatcher("/WEB-INF/next.jsp?jsonstring=" + jsonstring).forward(request, response);