4 Replies Latest reply on Jan 7, 2009 4:28 PM by Dean Hiller

    simple converter problem

    Dean Hiller Expert

      I created a custom converter for this component....
                                         <h:selectOneMenu id="com" value="#{buyApplication.company}" converter="companyConverter">
                                                <s:selectItems value="#{companies}" var="comp" label="#{comp.alias}" noSelectionLabel="Please Select..." />
                                         </h:selectOneMenu>


      but the problem is when getAsString is called, it works and I save all my values to a Map so I can prepare to retranslate them back when getAsObject is called,  BUT then when getAsObject is called, it is uses a different instance of my converter.  It is like it creates a new one.  I don't want to make the Map static
      as then there could be many threads accessing the same field...too dangerous.  why is it not using the same instance of the converter?


      thanks for any advice here.
      Dean



        • 1. Re: simple converter problem
          John Ament Master

          I think you want your converter called like this..


          converter="#{companyConverter}"


          assuming your converter is properly annotated.  how is it annotated currently?

          • 2. Re: simple converter problem
            Dean Hiller Expert

            man, I got all excited but that didn't work.  here is my java code...


            @Name("companyConverter") 
            @BypassInterceptors 
            @org.jboss.seam.annotations.faces.Converter
            public class SaasCompanyConverter implements Converter {
                 
                 private Map<String, SaasCompany> map = new HashMap<String, SaasCompany>();
            
                 @Override
                 public Object getAsObject(FacesContext arg0, UIComponent comp, String s) {
                      SaasCompany saasCompany = map.get(s);
                      return saasCompany;
                 }
            
                 @Override
                 public String getAsString(FacesContext arg0, UIComponent comp, Object obj) {
                      if(obj == null)
                           return null;
                      SaasCompany company = (SaasCompany)obj;
                      
                      map.put(company.getAlias(), company);
                      return company.getAlias();
                 }
            }



            Here is my html again...



            <s:validateAll>
                 <s:decorate id="comDecorate" template="../../web/zlogin/errorTemplate.xhtml">
                      <ui:define name="label">Company:</ui:define>
                      <h:selectOneMenu id="com" value="#{buyApplication.company}" converter="#{companyConverter}">
                             <s:selectItems value="#{companies}" var="comp" label="#{comp.alias}" noSelectionLabel="Please Select..." />
                      </h:selectOneMenu>
                 </s:decorate>                    
            </s:validateAll>
            


            • 3. Re: simple converter problem
              Dean Hiller Expert

              Why is always using a new instance?   Shouldn't it reuse the same instance?  it is so weird....must be something simple.

              • 4. Re: simple converter problem
                Dean Hiller Expert

                oh, I didn't know scope could be set on converters. That fixed it.  I thought converters would always have to be the same standard scope....weird.  oh well, scope of conversation fixed it.


                later,
                Dean