Your converter is a managed bean.

It would be:

public class MyConverter implements Converter { ... }

Then in your faces-config.xml :

<managed-bean>
<managed-bean-name>myConverter</managed-bean-name>
<managed-bean-class>com.foo.MyConverter</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

Then, in your JSP:

<h:selectOneMenu value="#{myBean.myProperty}" converter="#{myConverter}">
<f:selectItems value="#{myBean.mySelectItems}" />
</h:selectOneMenu>


On Wed, 16 Mar 2005 23:08:21 +0000, Kostas Karadamoglou
<[EMAIL PROTECTED]> wrote:
> How does the getAsString method that you gave me have access to the
> _beanBaseMap?
> Which is in the session scope the converter or the map?
> If the converter has session scope, how do you declare it in the config.xml?
> If the map is in the session scope how do you access it?
> 
> Heath Borders wrote:
> 
> >The getAsString method takes 3 arguments, the FacesContex, the
> >UIComponent doing the conversion, and the Object value.  It is
> >perfectly fine for a Converter to only work with certain types of
> >Objects.
> >
> >Let's say that all your beans extend a common base class BeanBase
> >which has a property id.
> >
> >Then, your getAsString method might look like this:
> >
> >public String getAsString(FacesContext ctx, UIComponent comp, Object value) {
> >BeanBase myBean = (BeanBase) value;
> >// assuming this is a member variable that is a Map
> >_beanBaseMap.put(myBean.getId(), myBean);
> >
> >return myBean.getId();
> >}
> >
> >
> >On Wed, 16 Mar 2005 22:39:54 +0000, Kostas Karadamoglou
> ><[EMAIL PROTECTED]> wrote:
> >
> >
> >>Very good idea!
> >>So I have understood from the converter's getAsString and getAsObject
> >>methods you call the getAsString and getAsObject respectively
> >>of the session scoped bean. But Is it possible to do this call? I mean
> >>does the converter has access to the session scope bean?
> >>How can I do it?
> >>
> >>Sorry for my questions but I am quite new to JSF.
> >>
> >>Heath Borders wrote:
> >>
> >>
> >>
> >>>We have a session-scoped managed bean that implements converter.
> >>>Whenever one of our objects goes into the getAsString method, we put
> >>>the object in a map keyed by its id.  Then, when the getAsObject
> >>>method is called, we remove the object from the map and return it.
> >>>
> >>>
> >>>On Wed, 16 Mar 2005 22:25:56 +0000, Kostas Karadamoglou
> >>><[EMAIL PROTECTED]> wrote:
> >>>
> >>>
> >>>
> >>>
> >>>>Sorry about my previous email, I didn't read it correctly!
> >>>>
> >>>>Another question if I don't bother you
> >>>>
> >>>>As far  as I understood  the methods getAsString and getAsObject
> >>>>serialize and deserialize an object isnt true?
> >>>>If yes then we send the object to the client and we don't keep it in the
> >>>>server. In your previous reply you send that
> >>>>MyFaces keeps the object in the memory but I cannot understand how it is
> >>>>done OR How I have to do it.
> >>>>Can you explain me this confusion that I have?
> >>>>
> >>>>Thank your in advance, Kostas
> >>>>
> >>>>Heath Borders wrote:
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>>>It could be a good idea for JSF to store the objects in the server side 
> >>>>>>and just submit an
> >>>>>>identifier to with the html. Once the request is received to the server 
> >>>>>>JSF can indentify the
> >>>>>>referenced object by the identifier.
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>We did exactly this.
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>On Wed, 16 Mar 2005 21:34:26 +0000, Kostas Karadamoglou
> >>>>><[EMAIL PROTECTED]> wrote:
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>>In you previous message you said:
> >>>>>>
> >>>>>>We elected to keep
> >>>>>>everything in memory since we don't have that many concurrent users.
> >>>>>>
> >>>>>>I didn't understand it can you explain it?
> >>>>>>
> >>>>>>It could be a good idea for JSF to store the objects in the server side 
> >>>>>>and just submit an
> >>>>>>identifier to with the html. Once the request is received to the server 
> >>>>>>JSF can indentify the
> >>>>>>referenced object by the identifier.
> >>>>>>
> >>>>>>
> >>>>>>Heath Borders wrote:
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>>Depending on the size of your object graph, you might run into
> >>>>>>>performance problems doing that.  It really depends on your situation,
> >>>>>>>but that's something you could definitely try.  We elected to keep
> >>>>>>>everything in memory since we don't have that many concurrent users.
> >>>>>>>
> >>>>>>>
> >>>>>>>On Wed, 16 Mar 2005 19:37:20 +0000, Kostas Karadamoglou
> >>>>>>><[EMAIL PROTECTED]> wrote:
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>>and what if my bean that I want to convert includes another nested 
> >>>>>>>>objects?
> >>>>>>>>
> >>>>>>>>Is it a good idea to use libraries that serialize and deserialize 
> >>>>>>>>object
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>from and to xml?
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>>Heath Borders wrote:
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>>getAsString converts the Object to a String and getAsObject converts
> >>>>>>>>>the String back to an Object.
> >>>>>>>>>
> >>>>>>>>>The behaviour should be like this:
> >>>>>>>>>
> >>>>>>>>>MyBean foo = // get a bean from somewhere
> >>>>>>>>>Converter converter = // get a converter that converts MyBeans.
> >>>>>>>>>String fooString = converter.getAsString(foo);
> >>>>>>>>>MyBean bar = converter.getAsObject(fooString);
> >>>>>>>>>
> >>>>>>>>>foo.equals(bar);  // should return true.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>Basically, the converter needs to convert an object to a String that
> >>>>>>>>>can be used later to recreate that Object.  You can do this many
> >>>>>>>>>different ways.  We have a unique id for every type of object and
> >>>>>>>>>store all objects in session.  Our converter just returns that unique
> >>>>>>>>>id and pulls the objects from session using a Map.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>On Wed, 16 Mar 2005 16:49:25 +0000, Kostas Karadamoglou
> >>>>>>>>><[EMAIL PROTECTED]> wrote:
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>>Hi again thank you for your reply,
> >>>>>>>>>>I am new to JSF so I need some information on how to create 
> >>>>>>>>>>converters.
> >>>>>>>>>>Do you know any site one the internet that has such information?
> >>>>>>>>>>
> >>>>>>>>>>I have already looked on the internet but I only foound converters 
> >>>>>>>>>>for
> >>>>>>>>>>String not for
> >>>>>>>>>>other classes.
> >>>>>>>>>>
> >>>>>>>>>>Can you give directions on how to implement the getAsString and
> >>>>>>>>>>getAsObject ?
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>Heath Borders wrote:
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>>Yes, you must write a converter for Category.
> >>>>>>>>>>>
> >>>>>>>>>>>The object you pass as the 'value' of your SelectItem objects 
> >>>>>>>>>>>should
> >>>>>>>>>>>be of a type that is assignment-compatible with the property you've
> >>>>>>>>>>>bound to your component.
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>On Wed, 16 Mar 2005 10:05:13 +0000, Kostas Karadamoglou
> >>>>>>>>>>><[EMAIL PROTECTED]> wrote:
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>>Hello I have a problem with the selectItems tag
> >>>>>>>>>>>>Bellow I have the method that brings the value attribute of the 
> >>>>>>>>>>>>tag:
> >>>>>>>>>>>>
> >>>>>>>>>>>>public List getCategories() {
> >>>>>>>>>>>>  ArrayList retValue = new ArrayList();
> >>>>>>>>>>>>  retValue.add(new SelectItem("","Choose a category..."));
> >>>>>>>>>>>>  for(Iterator iter=this.eventRegistry.getCategories().iterator();
> >>>>>>>>>>>>iter.hasNext();){
> >>>>>>>>>>>>      Category category=(Category)iter.next();
> >>>>>>>>>>>>      retValue.add(new SelectItem(category,category.getTitle()));
> >>>>>>>>>>>>  }
> >>>>>>>>>>>>  return retValue;
> >>>>>>>>>>>>}
> >>>>>>>>>>>>
> >>>>>>>>>>>>When I run the web application I get the following exception:
> >>>>>>>>>>>>
> >>>>>>>>>>>>javax.faces.FacesException: There is no registered converter for 
> >>>>>>>>>>>>class
> >>>>>>>>>>>>essex.cc403.hbeans.Category
> >>>>>>>>>>>>
> >>>>>>>>>>>>Do I really  need to write a converter for the Category? Can I 
> >>>>>>>>>>>>avoid it?
> >>>>>>>>>>>>Can you axplain me what I have to do because I am not familiar 
> >>>>>>>>>>>>with JSF
> >>>>>>>>>>>>
> >>>>>>>>>>>>Thank you in advanec, kostas
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>
> >
> >
> >
> >
> 
> 


-- 
-Heath Borders-Wing
[EMAIL PROTECTED]

Reply via email to