I created a HTML data table in a page say DATABROWSER.JSP through Java script (including all its row and there on click function in JS). I want to pass the selected(highlighted) row value to another JSP page(a new page that i open after selecting) without submiting the first page. !!
There's no way to get to another JSP without going back to the server.
I would place the items you select in hidden form fields and then submit the form. This would allow you to bring back a new JSP.
Related
I need to change the values displayed in the timetable based on the room I select from the dropdown list but I don't know how to do it.
The code for dropdown list is:
select option list
And on the same page, the code for the timetable:
timetable JSP page
Right now it shows all values from the database regardless of the selected room.
AJAX(Asynchronous Javascript and XML) can do this for you. AJAX allows for the updating of contents within an HTML object without reloading the page. W3Schools and the JQuery reference both have lots of helpful info on the matter.
My problem is, I have a jsp page(say one.jsp) which contains fields(eg: name, city etc) and after I hit on submit button, a new jsp(two.jsp) is opened in a new tab it contains a radio button 'I accept'. when the user now clicks on this radio button, the business logic should get executed. But the problem is the form values of one.jsp(values of name, city etc) are lost.
opening of the new jsp page using window.open is not a new request to the server. I wonder why the form values are lost.
Since you are using Struts 1 ,Please make sure you declare the fields whose values are to be retained in the ActionForm of the "I Accept" action and do set the values as Form2.setName(Form1.getName());
Or You have to maintain these values as hidden fields in two.jsp.
I guess the above two points would help you !
You are going from from one jsp to another jsp.But form values processed from one jsp to another jsp only>but you are expecting that values to submit form.
So you can do one thing you have get that values using request.getParameter();
and then you have to set that values to which you need.
Let me explain the problem in very simple manner,
In my app, I've a JSP which contains 2 tiles.
Tile 1 is a jsp containing Search Form. Suppose it has only one search parameter that is set into ActionForm on submit action.
Tile 2 is containing the
DisplayTag showing all results which were stored in session
attribute (After we press submit form of Tile 1).
Now 1st page of display Table is working fine. But when I click on another page links (i.e. 2,3,Last) it loads the blank page. Problem is, Search param is not accessible from here so it can not be appended behind the requestURI. (Definitely, I return the zero records when no conditions appended on sql query.)
So question is, how can I access the property of another JSP (My search form - another tile) ?
My proposed solutions (but I am not satisfied):
I can put my Display Tag code into the same Tile of search form.
Works fine. But I want separation.
I can use hidden params into Tile 2. But it may result in duplicate params same as Tile 1.
Please let me know about some efficient solution as I am new with Struts Tiles concept.
Display tags works with form scope session.
Put the form that you are using to display the data in table in session scope.
I'm looking to create a horizontal menu in a jsp page - the menu items vary by user but stay consistent over every page in the site for that user apart from the appearance of the active tab. Seems a simple enough problem at first (the appearance is modified using css) but I can't decide where to construct the menu.
Menu code:
<ul>
<li>item1</li>
<li id="active">item2</li>
</ul>`
As I see it there are 3 choices of when to retrieve menu items:
Upon receipt of HTTP Request to any controller for the first time store two arrays in the session - [url1, url2] and [item1, item2]. Then make the all the jsp pages form this into the above code. The jsp would have to know it's url to make against the [url1, url2] array in order to insert the active id.
Create the above html separately in each controller. Since a controller knows it's own url, it's simple to add the active id.
Create above html without any active id, store the html in the session and make either the jsp pages/controllers modify the html string.
None of these seem particularly appetising.
Does anyone have any advice on this?
Since a JSP is where all the HTML belongs, I'd go for option 1, but then with a List<MenuItem> instead of two loose arrays. You can find JSP's own URL by ${pageContext.request.requestURI}. The JSTL functions library should be helpful in determining whether the URL matches.
How many JSPs to create to maintain one table for data entry. Add.jsp to enter a new record and Update.jsp to update an already entered record. Is this a good idea or create only one jsp and use that for add and update using some parameter as all the fields and functionality remains same. Only difference is at the time of update few fields will be disabled and you need to pre-populate the form. I can use struts or jsf to develop this.
Better use one page, and differentiate between new and existing based on some criteria - for example, if the id of the object is 0.
Even if you make two pages, you can include the common content so that you don't copy-paste.
I like the one page approach too.
You could have a dropdown box containing the ids' or some other value that provides an easy way for the user to find a specific record and whatever other html elements you need on the page for displaying a record.
They make a choice using the drop down box if they wish to edit a record and then that records data is displayed on the page for editing, the user enters the corrections and hits the submit button.
If they want to enter a new record, then they do not make a choice using the dropdown box and instead just fill in the fields on the page and hit submit.
When posting back to the page you can check and see if a selection was made using teh dropdown box and if not enter a new record and if a choice was made then you update the record that corresponds to the selection made from the dropdown box.