reload popup page by using spring MVC - java

I am using a controller to get the form values from the html. And doing some kind of validations. If validation fails i want to reload that popup by throwing the validation message and the popup page view name to reload the popup page. Like
If i have a page A, in that page A there is a button B.
Now if i click the button B, there will be open a popup window C.
Here in the page C, if i click the form submit. It will goes to the controller.
Here in the controller i do some validations, if validation fails i just want to reload that popup page C with the error message.
Any body can help to overcome the issues.

It will be easy if you use jQuery UI Modal.
Just go through this link

Is this what you want to do here It can be achieved by basic JQuery, CSS, js. Explorer some. if you have to validate it from data base and than show use <f:ajax /> this is whole work do some effort

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

Wicket - redirecting to the same page when browser back button is clicked

I have a web application that uses the Wicket framework. It has a form that takes user input and when submitted, redirects to another page. Once the form is submitted and the browser's back button is clicked, the previous form is retrieved from the cache with the values entered. I need to override this behavior and redirect to the latter page (keep staying on the same page) when the browser back button is pressed. Is this possible in Wicket? If so, please guide me on how to achieve this. Thank you.
Wicket handles URLs so if a previous page is requested by it's recognized by page ID that is by default added to the URL, e.g. http:/dummyexample.com?1
What I use to solve that problem is a flow engine that holds the state of model object within it. E.g. you have a model object of type MyFlow containing a field 'String currentState'. In this case if you required a wrong page, that is not belong the stage where your flow is, you can redirect to the relevant page from a controcutor or onIntialize() throwing 'RestartResponseException' that causes redirect to the new page.
Just use an Ajax submit, this way the user cannot return to the input form via back-button.

How to show the content of a log file in new window when we click on a link in spring mvc

My main goal: When i click the link, a new browser window should be opened and displays the content of entire log file. And the window should not have an address bar and navigation buttons (Back, Forward).
Is there any approach to do this in Spring-MVC project?
Here is what i am doing now:
When i click the link, the controller will be called with a parameter logName.
Now the controller have access to get any kind of details of the log file like content, path, etc... I am setting all these details to an object and sending back to JSP.
Here i am not sure how to open a new window and display the content of the log file in that window.
Please suggest me an approach on this!!
It would be very helpful for me if you can share me with some examples...
Spring or JSP have nothing to do with it, the only way to force user's browser to open a link in a new tab is to use client-side Javascript. window.open() allows configuring the popup to hide certain interface elements (see all options in the documentation)
Your code would look something like:
<input type="button" value="Show Log" onclick="showLog(logName)">
function showLog(logName) {
var url = "/path-to-your-controller.html?logName=" + logName;
window.open(url, "LogPage", "toolbar=no,location=no,menubar=no");
}
However, I don't think using a customised browser popup is a good solution; it's been disappearing from the web for a reason. It would be more elegant to fetch raw data using AJAX and display it in a JS popup: it wouldn't interfere with user's page navigation (you tagged the question with jQuery, you could use jQuery UI for that).
What is more, I wouldn't be surprised if window.open wasn't supported by all browsers in the same way† - something to keep in mind if you're targeting a wider audience.
† seems that Chrome ignores location=no, for instance

How to keep popup with form open on validation failure and close it on successful save?

I have a form with validations in JSF that needs to be open in popup. When I submit the form, I am calling the bean method, the data send to the back end and if it successful then the pop up should close automatically.
Data is storing successfully, what should I need to return from bean method, so that the pop up will close automatically.
And also, How can we get the response after submitting the form? Is that possible?
Below code can be used to keep the show/hide the popup based upon the validation:
<a4j:commandButton value="Create Quote" id="createQuote" action="#{quoteAction.createQuote}"
immediate="false"
execute="envType country partner #this"
render="envType country partner"
oncomplete="if (#{facesContext.maximumSeverity == null}) {#{rich:component('quoteResultPanel')}.show();}">
</a4j:commandButton>
#{facesContext.maximumSeverity == null} will validate for any validation message(s) if this is not null then user will not be shown with the popup else user will be displayed with the popup. you can even use it the other way like close the popup only if there are no validation messages else keep the popup with the messages.
oncomplete="if (#{facesContext.maximumSeverity == null}) {#{rich:component('quoteResultPanel')}.hide();}"
Look here Using JavaServer Faces (JSF) Popup Window Example. Note that MyFaces Orchestra has support for multi-window applications out-of-the-box.
If you're using RichFaces, you might want to consider using a Rich Modal Window instead of a normal popup.
If your form is an <a4j:form>, you can use an <a4j:commandButton> for an ajax submit, and supply an oncomplete attribute to give it javascript to execute after successful submission. This javascript can be a call to Richfaces.hideModalPanel('pnl'); with the id of your modal as the argument.

How to redirect to the same view using ModelAndview in Spring MVC framework

I have a page with a link. On clicking the link a page opens up in a separate window. This new page has a form. On submitting this form, some operation takes place at the server. The result of which needs to be redirected to the same page. However after the operation on using the following:
return new ModelAndView("newUser");
//This view "newUser" actually maps to the popped up window.
A similar new window again pops up and the message gets displayed on this new page.
Any ideas as to why this behavior or how to go about this?
If you open a popup window with a form in it, any submits from here to the server will be handled in the same location, so you will get your response (and any subsequent request-responses) in that popup window.
If I understand this right, you have a page X which opens the popup, you submit in the popup and as a result you want again the content of page X, but in the popup?
If that is the case I thing the behavior is not from Spring but from what you have in the X page. Maybe a JavaScript which gets triggered on load and opens a new popup? Can't really tell without seeing more code.

Categories

Resources