• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Do a form using Struts.

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all! I need your advice in this question!

I'm doing a web applicaton and I have a MySQL database. I'm using Spring and Hibernate frameworks. They are working ok. Also I'm using Struts for view layer and I have done some JSP where I show all the information from the data base.

The question is the following:

I need to create a form because, users need to put data into the database. So... I want to do a form similar like this:




I have done this form using Struts, except down list that I have used Javascript but I think that I can't use it.

I have no problems with the fills where I use this kind of tag:
<s:textfield key="anuncio.descripcion"/>.


If I use this kind of tag I can save new data into the database.

The problem is that I don't know how can I create a downlist (or a comboboxlist, I don't mind) and save the information alongside all the fills.

I don't know if I explained me...

PS:

This was my JSP when I didn't use a down list (or combobox)



Also I have done Action class, I have modified struts.xml and it works nice, but now I need to use a down list! hehehe

Sorry for my English and... happy new year!
 
Ranch Hand
Posts: 247
MyEclipse IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi samuel.

You can use Select strusts tag and you can prepopulate it as per your need.
you can find it here

Thanks n Regards
Raza.
 
Samuel Castillo Romero
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raza Mohd wrote:hi samuel.

You can use Select strusts tag and you can prepopulate it as per your need.
you can find it here

Thanks n Regards
Raza.



Thank you for your advice.

If I use "select" struts tag and I create something like this....



when I execute my web application and I select an option (for example.... "busco") and later I submit my form... I get this error:





I know the problem is that key="anuncio.busco_ofrezco is null but I don't know how fill this key with the option (value) that I have selected

Thank you again!


EDIT: I have been reading more about Struts tag and maybe the problem could be in submit button? I mean... maybe when I click in submit button, the formulary reset himself automaticaly. Is it possible?
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like the error is actually being thrown by Hibernate:



My suggestion would be to wrap your code in a try-catch block and get a decent stack trace so you can see where the problem occurs, then log the values you are trying to set in the database so you can make sure your code does what you think it does.
 
Samuel Castillo Romero
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I try to set the values in the database, I get this error becase "anuncio.busco_ofrezco" is null.

If I use <s:textfield key="anuncio.busco_ofrezco"/> instead of select struts tag, it works nice and I have no problems about Hibernate Nullability.

I have a hibernate problem because when I did my database design, and mi java model design (AnuncioModel.java), I stablished this restriction, I mean... "busco_ofrezco" field can not be null, so if I don't put anything in this field, I get this exception, is normal.

I think that the problem is in select tag. I don't know how get the information from the list that I have declared -- list="{'Busco','Ofrezco'}" -- and save it later in anuncio.busco_ofrezco. I thought that I should use: key="anuncio.busco_ofrezco" to save it.

Also I have read this document: http://struts.apache.org/2.0.6/docs/select.html.
It says that field "key" sets the key (name, value, label) for this particular component. But I don't know how set the key, maybe is the problem...


Sorry for my English and thank you!


EDIT:

Hi buddies! I have good news

If I put this code



instead of this other




it works nice! I don't know why but now I can store the values in the data base.

Thanks for all!
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Samuel Castillo Romero wrote:
it works nice! I don't know why but now I can store the values in the data base.



The problem appears to be the use of the "name" attribute with the "key" attribute. I've seen them used separately: these examples use "name", these examples use "key", but I don't see them being used together. This makes sense because "key" associates a form field with a class variable (as well as message property) and "name" does the same thing and you have them pointing at two different values.
 
Samuel Castillo Romero
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joe Ess wrote:

Samuel Castillo Romero wrote:
it works nice! I don't know why but now I can store the values in the data base.



The problem appears to be the use of the "name" attribute with the "key" attribute. I've seen them used separately: these examples use "name", these examples use "key", but I don't see them being used together. This makes sense because "key" associates a form field with a class variable (as well as message property) and "name" does the same thing and you have them pointing at two different values.



Oh!! Thank you for the info!! It will be very usefull for the next time ;)
 
reply
    Bookmark Topic Watch Topic
  • New Topic