Struts 1.x Java- form data gets lost - java

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.

Related

Oracle ADF stop validation on empty table row, validate in popup form instead

I'm currently developing a simple application which does crud operations on a few tables.
It looks like this:
I have a problem with the add item form, invoked by pressing the button saying "Nova jedinica mjere". It opens a popup containing an ADF form as follows:
As you can see it does a create insert operation on popup fetch event, creating an empty row. When I fill the form with data, and press OK(the ok button is handled in the bean, doing a commit operation), I get an empty error message as follows:
This only happens if the table is editable(consisting of input text elements). If it is set to click to edit, this problem does not occur. How can I make validation only occur on form fields?
If you need any more info, please let me know because I too am new to adf.
EDIT:
This is the page in question:(posted as a pastebin link to not take up much space).
http://pastebin.com/5TKyPxEs
The form in the popup is a static region from a task flow with a method call and a page:
http://pastebin.com/9h69fRW4
You mean to say that when you enter the value in the form and Click OK, it should be there in the Table,If so, the values are not getting displayed in Table. It means your Iterator is not fetching the values. You have to Refresh your Iterator, VO and Table Compoent through Bean. So that the values in the form once you click OK, it will be there in the Table.

struts 1.3 tiles with Display Tag

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.

Passing select row of HTML table to next JSP page

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.

how to select radio button depends on condition in jsp with struts

i have jsp page with following code snippest...and it will show two radio buttons like car and bike
<bean:message key="label.vehicleType"/> : <html:radio value="Bike" property="vehicleType" idname="vehicleType" name="vehicleType">Bike</html:radio>
<html:radio value="Car" property="vehicleType" idname="vehicleType" name="vehicleType">Car</html:radio><br/>
If I select a radio button named as a car then it should show another two radio button like civic and BMW. or etc.
How can I achieve this with <logic:equal> tag of struts tab library.
I am new with struts tag library and javascript.
Thanks in advance.
<logic:equal> will be of no avail here. You need JavaScript for that. Go like this,
Set grid/div having sub-radios to invisible
Define a function to show the grid/div having sub-radios
Upon selection of radios, invoke the function you defined
Hints:
radio's onchange event can be used here.
In that function you need to validate some values before performing some real action.
You might need to hide the one and show the other one in case the selected radio is different.
If you are using struts 2.x
you can use
<s:if test="some condition">
your required code
</s:if>
You can't.
Everytime you use a JSP tag (Struts Tag extends JSPTag), the tags reads data from the servlet request or session. If you want to use the <logic:equal> tag, you will have to send your radio selection to your Struts Action, retrieve a list of data to populate, and retrn back to your forward and display the data.
If not, use Javascript. You will have to check if the property of your form is checked and enable a div that contains the list of cars that you so wish. This means that you will have to load all your relevant data beforehand and hide your div on onload().
Hope this helps.

Add.jsp and Update.jsp or only one

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.

Categories

Resources