• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Relational Database working with Selection Dropdowns

 
Greenhorn
Posts: 9
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

This is my first post here.

I'm and having troubling figuring out how to work some JSF magic on a Relationship that I crated on my database. Here is what I have coded.

My stateless Bean


My JSF bean process (moneyJSF.java)


XHTML


NOTE: typeJSF in the HTML code just grabs the data from the database in the table called typesOf. Money and types have a many to one relationship.

When I submit the selections, I get the following error:

Conversion Error setting value 'com.serveftp.wigm.entities.Types[ typeOfID=1 ]' for 'null Converter'

I understand that I need to convert from a string object to a Types object using the types entity, however I am not sure where to start on this one. Can someone please point me in the right direction?
 
Thomas Snyder
Greenhorn
Posts: 9
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured out what I needed to do. Once a created a convertor that implements the FacesConverter, added the <f:converter> to my xhtml, and added a ID query to my stateless bean, I was able to add items to my database.

From what I read, what I had to do is convert the Object to String for HTML, then convert back to an object once HTML was done with it. I'll post the code once I move it off my standalone computer in case anyone else is trying to do the same thing.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep. JSF talks to web browsers in HTML and HTML is a text-based format with no support for binary objects such as integer primitives or Java objects.

So Converters manage the conversion of such entities to and from text form.

Certain converters are built in, such as the integer converter. Some are pre-defined parts of the JSF system, such as the DateTimeConverter.

And some you write yourself!
 
Thomas Snyder
Greenhorn
Posts: 9
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As promised, some code that makes this work. This code works with the cod I posted already here.



Anyone know a better way I can clean the code above up. It looks messy.



 
Thomas Snyder
Greenhorn
Posts: 9
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another thing I found is this code isn't allowing me to fully do CRUD. It seems I cant use it to update/edit an item that requires an Object. Items that aren't self made Objects update just fine, just seems the Object isn't getting stored when the page does a set on the entity. Thinking I'm missing something out my bean. Anyone got a suggestion where I should start to figure out where the problem is?

I guess I'll need to run Debug on Netbeans, see if the object is getting stored before the update.
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh.

I normally just build a list or array of SelectItems and use the "f:selectItems value="#{bean.selectItemlist}" myself.

A SelectItem is a value pair. The label part is always a string. Usually when the value is a complex item, it has a key or something like that and I use it as the selectItem's value to look up the object itself instead of writing a converter.

The stuff you did looks like the approach that RichFaces uses for their shuttle controls of complex objects, which is definitely messy. I've always been of the opinion that they could have found a cleaner approach, but never really found it worth while to develop one.
 
Thomas Snyder
Greenhorn
Posts: 9
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim, How would you do this ?

Usually when the value is a complex item, it has a key or something like that and I use it as the selectItem's value to look up the object itself instead of writing a converter.



I tried something like this where I just present the ID of the item to the process but since it is a relational database I receive errors. It seems that the item had to be stored as an Object to be presented back to the database. Maybe I am looking at this from the wrong angle?
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I want to reference a complex object that has a unique key, I typically do one of 2 things.

If the collection of objects is small, I just create an internal hashtable whose key is the object key, and the value is the object itself. Then the backing bean can simply do a table lookup to get the object based on the key selected.

If it's large or dynamic and backed by a database, I'll generally just do a find by key against the database to get the object.
reply
    Bookmark Topic Watch Topic
  • New Topic