Play's flash is a "temporary storage mechanism that is kept for the duration of the next request", using cookies.
Is it possible to read the flash from javascript?
I want to implement a generic client-side notification mechanism, and also access that mechanism from the server. What I imagine is for any controller to do:
flash.put("notification", "You have been notified");
And then for my main.js to check if the "notification" flash exists, and if it does display it above (similar to Stack Overflow's notification mechanism).
However, I suspect that flash might be encrypted in a way that the client side cannot read it. I haven't found any code samples that show how to read it from the client side JS (not in a template). Is this possible directly?
As I'm writing this question, I'm actually coming up with a way to implement this: I can put a hidden div in the main template that all my views extend, and access that div from JS. Does it make sense? Is there a simpler approach?
I don't think it's possible to use JavaScript to read flash, even via the cookie. That cookie is actually encrypted with a security seeds (application.secret) configured in your application.conf.
However it is possible to implement what you want.
Create a tag to export flash variables into Javascript object.
Call that tag in your view.
Your main.js use that exposed variable to do whatever it want.
For me you have two solutions
In your view call a javascript function with the value as an argument, then in javascript you can store it in an object for later use
The flash cookie isn't encrypted, it is sign, so you can read it but you can't modify. Use a tool like firebug to see the content of your flash cookie
Related
I would like to get a reference to the DOM of a displayed webpage so that I can add and remove elements. I would like to add and remove those elements by sending HTTP requests from, say, a servlet. Further, I would like to be able to construct a DOM, node-by-node, in the browser, via java, from http messages coming from said servlet.
Suppose someone requests a url (say): http://helloWorld.xhtml
I would like to render the content by sending HTTP messages, which, node by node, build the displayed document. Then, if I need to change something in the document, I would like to be able to remove html node-wise, or add html in the same manner; I would like to make partial changes to the html document via http.
Does anybody know of specific way(s) to accomplish this?
I don't want to use JavaScript, unless it means a utility method to accomplish the communication mechanism only. I don't want to use a client-side applet either, but that might be a way of getting around the limitations of http (i.e., sending back java object responses via jaxb).
I don't want to use javascript because I just want to use an html browser as a displayer of elements that relay the occurence of events back to the server. Then, I want to be able to add or remove elements without redrawing the page. Also, I would like to use XSLT to generate HTML, but again, I would like a way of updating the web page without using hidden elements and without redrawing the whole page.
I thought of something else also. I might use a JApplet embedded in an HTML page, and then just communicate with the JApplet via JAXB? I am assuming that you can do that.. (maybe it does not work that way). Then, in the JApplet, just using a means of displaying an HTML page; there might be a better option amongst the components than the JLabel.
I think that the best option would either be using the HTTP mechanism (if possible) or else, using some sort of middle layer that would enable me to send Java back and forth between the webpage and the server.
I've thought about this a minute, and perhaps, if browsers would change their update policy, then, we would be able to use http to facilitate a view that is updateable on a per-element basis, via a browser behavior that supports additions or subtractions of elements?
Why you don't want to use JS is beyong me since this is THE language for editing the dom.
The easiest way to accomplish your scenario would be using Jquery.ajax.
For parsing/building Json i would recommend Google's Gson.
You can look here for a small sample.
I have an application which needs to accept a POST request from an outside server, to confirm payment. I don't want to break the default wicket render strategy (REDIRECT_TO_BUFFER) which is serving to give the users a nicer experience than ONE_PASS_RENDER would, however, the external service is not happy with the 302, and keeps retrying until it gives up.
Is there some sensible way that I can tell wicket to use ONE_PASS_RENDER for only the specific page that handles this request?
Try using a Resource instead of a Page to handle this request. That way, you can return whatever response you want (both HTTP headers and payload) to keep the external service happy.
It's a lower level API, though. If you need to respond with a rendered page, you may need to render it yourself (with lots of println() calls), or hack some way to Wicket to do it.
But since it is a response to a external service, I assume it will expect some kind of simple text, XML or JSON response, which are easy enough to do by hand.
I have been developing an AJAX web application using GWT. I've read several blogs and forums about this question and left with no clear idea. I understand that GWT is an AJAX application, that supports only stand-alone web application. By stand-alone, I meant GWT to be a single web page that would suffice the user requirements. However the use case I have is pretty complex and I'm stuck in this use case that doesn't let me proceed.
My usecase(s) goes like this:
Usecase #1: There is an order entry form where user will enter a search string to search for a particular item. With GWT, I could display the result in a table (say celltable). However, when I click a column in the cellTable, I want the value of the column to be sent to the server and display another page that will display only the details of the selected column. I'm not sure how to accomplish this.
Usecase #2: Let's say the web application I develop is called "InventoryControl" and I have different requirements such as:
display Available stock
display Order stock
display Manufactured unit
and Using Java servlets, I could just type http://localhost/availableStock?stockId=1234 on my browser to get the "Display available stock" for the given stockId and then http://localhost:orderStock?stockId=1234 to get the "display order stock" and similarly "display manufactured unit". Is the same possible using GWT? i.e. when I type http://localhost/availableStock?stockId=1234, is it possible to read the parameter being passed and then display the corresponding page?
If these are not meant to be guaranteed by GWT, should I stick with Plain old JAVA servlets/JSP?
Thanks in advance.
Ashok - Please note, what filip suggests above does not require multiple "pages" in the sense of additional html host pages. You can build a panel holding your display of the details, and swap it into the rootpanel of your host in the onSuccess() of your rpc call. The GWT history mechanism allows you to assign anchors to these "places" and provide a mechanism to map these anchors to specific display classes in your code.
GWT already has a mechanism for handling multiple page applications. Have a look at Activities and Places. You can define each page as a place in your application, and use the GWT mechanism to go from place to place at any time. Using places also allows you to easily add tokens/query parameters to each "page", in an OO manner, without having to worry about populating/querying the URL directly. Have a good read of the link!
Using jQuery AJAX, can we call a specific JAVA method (e.g. From an Action class)
The returned data from that Java method would be used to fill in some HTML code.
Please let me know if this can be done easily using jQuery (like it does in DWR)..Also for multiple data points in HTML, do we need to make multple AJAX requests?
The simple answer is you map your ajax calls to urls, which are in turned map to methods in your java code. The Ajax -> URI mapping happens on the client side (which ever js framework you are using, and the URI -> specific handler mapping happens within the java application)
What java framework are you using? There should be very clear and simple documentation on how to do this. For standard Java EE mappings (meaning you are not using any frameworks like Spring or Roo) I found this on google: http://javapapers.com/servlet/what-is-servlet-mapping/
"For multiple data points in HTML" I assume you are talking about having multiple parts of the html update. You can do this with multiple requests, or you can do it with one request. If you do the latter, the server needs to return all the data you need to update the dom appropriately.
It's not as transparent as with DWR--DWR handles making JavaScript look like Java. With jQuery you'll get JSON (or just HTML if/when it's easier that way). It's still pretty straight-forward, though. You'd send the Ajax request to a URL, rather than having it look like a local method call.
I'm not sure what you mean by "multiple data points in HTML" -- you get back whatever data you get back, and you can do with it whatever you want. If the response has all the data you need, then you wouldn't need to make multiple requests.
I would like to send a request to a Java Servlet from PHP and receive the response from the same and show it on the PHP page. How should this be done?
Thanks and Regards
Abishek R Srikaanth
If all you want is to print the response of a GET request to an external resource plain vanilla into the PHP response, then you can use file_get_contents() for that.
<?php echo file_get_contents("http://example.com/someservlet"); ?>
The servlet's doGet() method will be invoked and whatever response it returns (which can even be a forwarded JSP) will be printed as string to the PHP response.
If you want a little more fine grained control, e.g. using POST or something, then head to curl() instead. The linked PHP manual contains several examples.
Regardless of the way, please note that whenever it returns HTML, that you should ensure that you end up with valid HTML. For example, nesting <html> tags is illegal. Pass the PHP page through the w3 validator if you're unsure. Otherwise you'd better have to parse the HTML to extract the <body> pieces of interest or to use an <iframe> instead.
<iframe src="http://example.com/someservlet"></iframe>
If I'm understanding you correctly you want to read the response of a servlet in php and then output it from php?
You can use file_get_contents to the url (Probaly not the best way, but for simplicities sake it the easiest) and then just echo the output.
For example:
$content = file_get_content('http://www.google.com');
echo $content;
But if you want to be able to login or use the session at the servlet side you will need think of something else. As each request to the server from php will be a new one, it does not store cookies etc.. like browsers do.
Hope that helps
This is a situation which might do well to be rethought, but, if there are no other options...
If there is a way to actually update the portlet, then I would recommend creating some form of service call -- SOAP, custom RPC, etc -- on the Java side. Technically this is the most correct way to do things.
Failing that, if this is a simple GET request, then use file_get_contents.
If it has to be a POST/PUT/DELETE, then you can use cURL. cURL also has the benefit of being able to handle simulated sessions, which means that you are then able to simulate a log in and actions following that (though not without some difficulty).
If you don't have cURL and you need to POST/PUT/DELETE, then the streams library might be able to give you what you need.
If you don't have the streams library or cURL and you need to POST/PUT/DELETE, then there are other means of accomplishing that, but maybe you should really re-rethink that situation.
If all of the above don't work, then you will need to tame the Spectral Wolf. The Spectral Wolf fears only fire. I can no longer help you, but if you master the Spectral Wolf, he will guide you. Godspeed.
If you really want to do that, you can create a Java app that takes parameters to populate request and response objects, instantiates a servlet, runs the correct method, gets the result and displays it, then call this Java app from PHP.
Or you can use the experimental and unrecommended PHP / Java Integration module.