| View previous topic :: View next topic |
| Author |
Message |
4fingers
Joined: 31 Mar 2009 Posts: 9 Location: South Africa
|
Posted: Thu Aug 27, 2009 4:19 pm Post subject: JSF : How to populate textbox from Dropdown selection |
|
|
Hi, I hope someone can please help me with this
I select a value from a Dropdown, then click on an Edit button to edit the values for the selected Item. I want my page to now display the selected values in various text boxes below the Dropdown. When I check the values in the backing bean (prerender), I can see the new values which I want and even set the fields to, but when the page is displayed, I get blanks in those fields.
I have read that JSF will do a page validation and if it detects no changes it will display the same values again?
How do I get around this problem - I have done a lot of searching and simply cannot find a solution ?
Any help will be greatly appreciated.
 |
|
| Back to top |
|
 |
4fingers
Joined: 31 Mar 2009 Posts: 9 Location: South Africa
|
Posted: Tue Sep 01, 2009 7:06 am Post subject: |
|
|
Hi
After bashing my head for a couple of days, I finally found the answer to my question. I will describe my fix below for the benefit of others just in case someone has a similar problem :
I left out a crucial piece of information in my original question
I did not mention that I was making use of Virtual Forms, which was in fact causing the problem in my code.
I added the following code in my button's Change_action() event :
form1.discardSubmittedValues("ItemDelete");
form1.discardSubmittedValues("ItemOk");
form1.discardSubmittedValues("ItemPreview");
This solved my problem of the latest value being displayed when selected
from the list and clicking the "Update" button.
Hope this helps someone else ! |
|
| Back to top |
|
 |
ceyezumma
Joined: 02 Feb 2009 Posts: 122
|
Posted: Tue Sep 01, 2009 12:53 pm Post subject: forms |
|
|
Impressive
good job.
I have been trying to work with the jsf2.0 netbeans 6.8
Is this what you are working with.
I can't get the items loaded to the dropdown list. It would be great to see your code. if possible.
I'm trying to understand the JSF
Thanks
-ceyesumma |
|
| Back to top |
|
 |
4fingers
Joined: 31 Mar 2009 Posts: 9 Location: South Africa
|
Posted: Tue Sep 01, 2009 8:28 pm Post subject: |
|
|
Hi ceyesumma
I am currently using Netbeans 6.7.1 and Faces 1.2
In my case I am populating an Option[] in my Sessionbean.
You then bind your Dropdown to this array (right-click on Dropdown and click on bind to data. Select the listItems Option array).
I populate the array by calling it from the formsBean at the point
that I need it. In my web app, I have an Items tab and when I select it,
I call getSessionBean1().loadItems();
In the SessionBean, I have the following code :
Add :
private Option[] listItems; //Use this array to populate the list
private List<ItemsDTO> myItems; //Use this array to retrieve data
private ItemsDTO[] itemsArray; //Use array to hold Item details
Generate the relavant Getters and Setters for listItems:
public Option[] getListItems() {
return listItems;
}
public void setListItems(Option[] listItems) {
this.listItems = listItems;
}
Create a load method which will populate the array
public void loadItems(){
int listcount = 0;
// Check for items in array
if (getItemsArray() != null){
listcount = itemsArray.length;
}
// Clear array
for (int i=0; i<listcount; i++){
itemsArray[i] = null;
}
List loadList = new ArrayList();
// Create a new Data Access Object - connect to Oracle db
ORACLE_DAO myDAO = new ORACLE_DAO();
//Create a new Arraylist Collection and populate from db call
myItems = new ArrayList<ItemsDTO>();
myItems = myDAO.getItems(getSelectedInitiative());
//Process records retrieved from database
if (!myItems.isEmpty()){
itemsArray = new ItemsDTO[myItems.size()];
int i = 0;
for(ItemsDTO item : myItems){
itemsArray[i] = item;
loadList.add(item.getItemName());
//Pass the index and display value to method
addOption(item.getItemId(), item.getItemName());
i++;
}
}else{
//Create empty array
itemsArray = new ItemsDTO[10];
itemsCounter = 10;
}
if (itemsArray != null){
itemsCounter = itemsArray.length;
}
}
//Method to populate Option array with new values
public void addOption(int ii, String s) {
// Add a new item to the list by creating an
// updated array that contains the new item
Option opt = new Option(ii,s);
//Create a temp array to hold existing values
Option[] current;
//Populate temp array
current = getListItems();
int size = 0;
if (current == null){
size = 1;
}else{
size = current.length + 1;
}
// Create a new Option array with the new size
Option[] newOpts = new Option[size];
if (size > 1){
// add the current items to the new array
for (int i = 0; i < size - 1; i++){
newOpts[i] = current[i];
}
}
newOpts[size-1] = opt;
// Add the new Option to the list in question
setListItems(newOpts);
}
I hope I am not confusing you with my code
Cheers |
|
| Back to top |
|
 |
ceyezumma
Joined: 02 Feb 2009 Posts: 122
|
Posted: Tue Sep 01, 2009 9:28 pm Post subject: dropdownlist |
|
|
Thanks for your code.
I am now working with netbeans 6.7 again I think 6.8 should be running in November.
I worked with actionscript for the last 6months and I trying to switch gears back into java and good examples are hard to come by.
Are you aware of a good source of examples? The netbean page isn't really working for me at the moment.
Thanks again
-ceyesumma |
|
| Back to top |
|
 |
4fingers
Joined: 31 Mar 2009 Posts: 9 Location: South Africa
|
|
| Back to top |
|
 |
ceyezumma
Joined: 02 Feb 2009 Posts: 122
|
Posted: Wed Sep 02, 2009 5:48 am Post subject: java links |
|
|
hey thanks I really need somathose.
these should help me while working on my associates in googleology  |
|
| Back to top |
|
 |
jyeary
Joined: 21 Oct 2008 Posts: 610 Location: Simpsonville, SC
|
Posted: Tue Sep 08, 2009 11:57 pm Post subject: JSF : How to populate textbox from Dropdown selection |
|
|
I have an example on my blog on how to do this sort of binding.
http://javaevangelist.blogspot.com/2009/07/woodstock-dropdown-list-binding.html
On Thu, Aug 27, 2009 at 12:19 PM, 4fingers <address-removed ([email]address-removed[/email])> wrote:
| Quote: | Hi, I hope someone can please help me with this
I select a value from a Dropdown, then click on an Edit button to edit the values for the selected Item. I want my page to now display the selected values in various text boxes below the Dropdown. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|