Struts 2 - How to populate a combobox considering another combobox choice - java

I would like to know what I am doing wrong or if I am on the wrong track, trying something impossible.
In my jsp I have two s:select and some textfields. Considering the choice of the first one I have to go search some informations on my database. What I am trying to do is everytime I choose some option in my first combobox I call a method im my action, this method get the informations I need from my mysql and populate my list(this list is the options of the second combobox), but of course this is not working because I am not reloading my jsp, the problem is that I cannot reload because I don't want to lose the information I have in the textfields.
I appreciate any kind of help.

you'd better use Ajax to load the data for your first ComboBox or some other fields data (page without re-loading,thus)

Related

Swing applications that prints the MySql Database records

I need some help with choosing the right swing component to print the records from database, to be honest I was thinking its going to be easy with
http://mysql.aldenwebhosting.com/JAVAtutorial/uiswing/components/table.html
BUT it doesnt cache, its just prints raw code into tabel. Can someone help me?
In its final stage, my app would download records after I press the button, then print them into some form of label, tabel,field whatever (bassicaly I dont know which swing component choose) . Next step is going to be editing one of the column parameter (binary-like yes/no) and saving it to database - I don know if thats important - im writing it just in case, so you can see the whole "picture"
Greetings!
To build an editable table in swing, I would suggest you to use a JTable with a custom table model and choose a JTextField component for your cells.
If you are not using any JPA frameworks like Hibernate, IBatis.., etc. I would recommend to use one because it helps lot in dynamic persistence in this case.

Connecting two columns in two different comboBoxes

I connected MySql database with Java app, I see data from two different columns (Items, Price) but I want to connect them somehow, for example, if choose in first combobox item "Desk" the other combobox should automatic find "Desk" price and display it in second combobox. Anyone have idea how to make that ?
You could write a changelistener for the first box, then have it go into another sql query which will populate the second box. Check out this guide, it'll explain to you how to do it
https://docs.oracle.com/javase/tutorial/uiswing/events/changelistener.html
First, I think that you don't want to ComboBoxes being correlated in such a way. There must be a better design for your gui.
Is your ComboBox from JFace? There are JFace Data Bindings. Normally, you use them to automatically update your model if someone changes values in the user interface. If your model contains an id from your database, both comboboxes can have a binding to this id.

How to put multiple checkboxes into a form with Apache Wicket?

I want to create a webpage that looks like this one:
This is done using a table. Each row describes an object and I want to be able to select multiple of those objects. When one of the submit-buttons is clicked, I want to get the list of selected objects. I know there is the class CheckBoxMultipleChoice, but the generated output is not what I need.
I think I should use a ListView, but since the number of objects is dynamic, I do not know how to access the states of the checkboxes. Could you please tell me how I can achieve this layout?
You should use a CheckGroup with one Check component in each row.

Multiple JTables with dynamic names

I'm working on my first java program. I'm making a Project Manager program.
The base idea is that i have a JList which contains the names of the Co-workers. If you double click one of the names a JTabbedPane will pop up a new tab and will be populated a JTable what is containing the specific persons tasks.
And here comes the tricky part. I want to use this JTable to modify the datas so i need to give a specific name to the JTable so i can use that later on in my methods to call it.
The question is how can i create dynamic names to these tables so i can call it later (something like this: table+tabID).
OR
Is there a better solution to my problem?
Any help or advice is greatly appreciated.
I solved it. The solution was:
I made an ArrayList<JTables> to store the tables and I'm using the tab indexes to get the proper table.

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