window.open in java bean - java

i need to create a pop up window from my java. Can anyone give me some samples for creating window.open popup from java bean? I have a list of records created from java. in that list i have a column called ID with anchor link. When clicking on that link it should open the popup and retrieve the details.
No Name Amount
1 xxx 15
2 uuu 20
3 uku 23
4 iko 09

I assume that you know some javaScript for this .
On click of a Link call a function this way
<script>
function PopupCenter(pageURL, title,w,h) {
var targetWin = window.open ("http:localhost:8080/MyServlet?name="+kiran"")
}
</script>
Process your request with Servlet , get the Data and show it on that page.
In case you use Struts, replace servlet with a Action class .

Related

How to automatically reload a jsp based on other page action

I have a situation that i can't handle and thats why need your help.
I have a jsp page (mention as A in below pic) where there are many rows and each of them can be edited.
At the end of the A jsp page, there is an option to print the page data.
Now, if some body clicks on the edit link/button, another page will open contain the data for that particular row and user can modify the data in the second page(i,e B).
Now, i want, as soon as the user save the B page, A page should be refreshed automatically to provid the updated data for printing.
Please guide me on how to acheive that . I'm using Spring MVC framework for the java application.
The Spring MVC way to meet your requirement is:
the Edit buttons in page A should be links calling page B with the id of the line to edit, something like Edit
the SaveAndClose button in page B should be a submit button that posts the edited values to a controller method. After server side processing, the controller method should redirect to page A. As a side effect, you use the PostRedirectGet pattern which avoids the ugly do you want to send again ... ?"
#RequestMapping(path = "...", method = RequestMethod.POST)
public String saveAndClose(...) {
...
return "redirect:/path/to/pageA";
}
Of course this will display all pages in same window.
If you want to redisplay the window containing pageA on the Save & Close from page B, still allowing the save to be known to the server, you should redirect to a special page (say pageC) that just contains javascript code asking the browser to redisplay pageA. You can either pass the name of the window containing pageA in a hidden field, or you can decide that as the programmer of the web application you know where it should be.
It can be achieved like this. Follow the steps mentioned
1] When you click on edit button in Page A, pass the id of the row to Page B as request parameter.
2]In Page B JSP receive the id of the row and store it in a hidden element.
3]Create a JavaScript function in Page A which should receive row Id and Modified data as parameter. Lets name it this function as updateRows(rowId,modifiedData). In this function write code to update the with id 'rowId' with modified data using javascript
4]Now When you click on 'Save & Close' Button in Page B. Save the data using call to server. If save succeeds then invoke the function updateRows passing it rowId stored in hidden element and modified data as parameters. This function will update the DOM with latest data.
This way you will avoid making server call to refresh the data
There is one more way if you don't want to use ajax.
In Page A define a javascript function refreshPageA(). In this function add page refreshing logic.
When you click on 'Save & Close' button in Page B save the data in server and forward to a plain jsp. In this JSP declare a onload handler. Inside onload handler add following code
opener.refreshPageA();
window.close()
This will refresh pageA and close page B window

How to use Ajax with select option tags in Jsp page ?

In my jsp page , I have 2 different select option tags menĂ¼ . I fill first one with a list from mysql database. when i select one value from this List ,I want to fill second select tag with a List which sended from Mysql . So , In Ajax , When i send a List from servlet to jsp , how to fill second Select option menu with this list in Jsp page ?
Use a javascript library like JQuery (that is well known and widely used/tested)
http://api.jquery.com/jquery.ajax/

Need Jquery to switch between 3 servlet pages

I need Jquery and the corresponding js and css files to switch between the servlet files.
For example: I am having 3 servlets Myservlet1.java, myservlet2.jave & myservlet3.java each displaying a table value. I need Jquery to switch betweent the servlets like myservlet displaying for 20 secs and then myservlet2 displays for 20 secs then myservlet3 displays for 20 sec.
The switch should be automatic. I am entirely new to Jquery and I badly need the code immediately ASAP.
Thanks in advance!!
I am displaying the results of 3 tables in corresponding java files. in the page values of tables will be displayed in servlets. Now I need to switch the servlets for every 1 min so that the record of 3 tables will be displayed in the specific interval of time
You need to use the jQuery load-function with callbacks, and perform a setTimeout for each callback. The code would look something like this (I haven't tested it):
var delayTime = 20 * 1000;
// Wait on servlet 1
setTimeout(function() {
$( "#content" ).load( "myservlet2.java", function() {
// Wait on servlet 2
setTimeout(function() {
$( "#content" ).load( "myservlet3.java", function() {
// Servlet 3 loaded
});
}, delayTime);
});
}, delayTime);
This would load the page inside a HTML-element with id content. However, it doesn't seem like a good approach. Maybe you could explain better what you want to achieve?

How can I reload only a part of code - Java

I have a JSP page that at the end comes a pop-up window from a javascript, I want after the users click to reload only a specific part of the JSP page more specific one if - loop want to be reloaded one more time ...can this happened or the idea is totally wrong ?
What you are looking for is called AJAX.
AJAX is the art of exchanging data with a server, and updating parts
of a web page - without reloading the whole page.
jQuery has a very nice ajax api.
To load html pages, you could use jQuery.load like this:
$("#result").load( "ajax/test.html" );
You can also generate dynamic html by calling a REST function of a php page using a different url. Example:
var data = { limit: 25, otherProp: "val" }
$("#result").load( "getHtmldata.php", data);

How to select the particular row data in jsp using radio button

I know its a basic question and please bear with this.
I'm new to struts frame work and I'm creating a sample application using struts 1.2. I've inserted few values into the database using form beans. And i'm displaying all the database records in the jsp page using function. and i also placed the radio button for each row..
Now my question is, i want to select a particular data from the records displayed in the jsp page by clicking the radio button and i need to store the selected records into the another table.
Give me some suggestion regarding the condition specified above...
Thanks in advance..
Once you set those unique values in radio button, you can get the values for your purpose. Like using jquery,
var selRadio = $('input:radio[name=cname]:checked').val();
You can find out fiddle explains how to get checked value.
Use some ajax for send that value to server (servlet) and add the values to new table without refresh entire page.
$.ajax({
url : "ur_servlet_url" + selRadio,
type : "POST",
async : false,
success : function(data) {
alert("success");
}
});
Let me know if this helps.

Categories

Resources