I have such button on my page
#{if someCondition}
All requests
#{/if}
#{else}
Filtered requests
#{/else}
Is it possible to make it as checkbox without any button? Action should be executed by checking checkbox. In other words. If checkbox is checked I want to execute #{MyPage.index(true)} and if uchecked #{MyPage.index(false)}.
I've tried
<input type = "checkbox" onchange = "#{MyPage.index(true)}" value = "withMe" />
but it doesn't work. Any suggestions?
The template engine on the server side is run when your page is rendered. After the server returns the page back to the user (client side), you can't call the template engine anymore. onchange is a JavaScript trigger, you can't mix that with your template commands.
Here's how it works:
Client Server
------ ------
1
2 -----> 3
4
5
7 <----- 6
8
user navigates to a URL on your site
browser sends HTTP request to server
server receives the request and maps it via routes to a controller
controller does its tricks and calls the view
view is rendered using the template engine and a page containing only HTML, CSS (this is generally left out of the page rendered on server and used from a separate static file though) and JavaScript is created
server sends above page in a HTTP response back to browser
browser receives response
browser loads up the page
On server side you can use Java, template engine, poll data from DB, etc. On the client side you can use HTML, CSS and JavaScript.
When the user is clicking checkboxes on the page, there's no connection to the server anymore. Thus in order to invoke the server when a checkbox is clicked you'll have to make a new request.
If you need to say show some extra content on the page when a specific checkbox is clicked, you have a couple of options:
Make a HTTP request to server synchronously and load the page again with more content.
Make a HTTP request to server asynchronously with AJAX and just use JavaScript to add more content on the page.
Load all the data on the page when the first call is made, but only show the relevant bits initially when a page is loaded. When checkbox is clicked, use JavaScript to show new content with rest of data in it.
I'd recommend 2 or 3, since 1 is quite old fashioned and annoying to the user.
Related
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
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.
I'm using blockui with standard form post(java+struts1) no ajax or anything. It works great, but Im just wondering is this considered an ok thing to do. Basically all I wanted to do was lock
the browser screen upon submitting the form (when click on link) and show a message. I'm asking because it seems a lot of blockui examples use an ajax request.
My requirement is avoid user hitting multiple links on the page at a time. now as soon as clicking on one link blocking the page with this blockui (https://github.com/malsup/blockui/) until the process finishes and load the page with new data.
--------------- updated ----------------
I did 2 steps:
dowloaded the 'jquery.blockui.min.js' from https://github.com/malsup/blockui/ and added this js file in my workspace
added below code snippet in my jsp
$('#linkX').click(function() {
$.blockUI({ message: '<h1><img src="busy.gif" /> Just a moment...</h1>' });
});
now when i click on any links (all links has same class name) the page blocks with popup message "jest a moment". since i have form action in the jsp as <html:form action="/xxx.do"> it perfomrs the process backside and enter some data in the database (until that process completed few seconds main page blocks with this popup message which i needed to control the user hitting another link which interupts the 1st link process), and it loads the page back (with new data). Automatically on page load this unblocks the ui.
this blockui perfectly fulfilling my requirement. But every where this blockui getting used with Ajax calls not with regular form submit so i wonder whether it can be also used with regualr form submit too or not? (or if there is any other simple solution to block the ui as Im not using Ajax)and is this dowloaded blockui javascript file is safe to use (as Im working for the federal company)?
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);
I have made a html page which has a text field and a submit button ,the user enters a word in the text field and clicks submit . There is a servlet which fetches the users input through request.getParameter(). Now i want to send this input word to thesaurus.com and retrieve the synonym for the word and send this synonym back to user as response i want to include this functionality in the above said servlet itself....plz help!
you can use java.net api or alternatively use can apache HTTP client .using java.net api just create url object and open connection and send parameter using write method and get the response.
To check what parameter is sent you can use http live header plugin of mozila