[jboss-user] [JBoss Seam] - Re: Fill selectOneMenu on page load.

grdzeli_kaci do-not-reply at jboss.com
Mon Feb 19 05:55:01 EST 2007


"petemuir" wrote : That (obviously) is a problem with your converter.  Either try the entityConverter as I suggested or take a look at the Seam ui-example for how to write a suitable converter.

ok i tryed to write own converter, i got it from wiki :
1.Converter

  | import java.io.Serializable;
  | import java.util.List;
  | 
  | import javax.faces.component.UIComponent;
  | import javax.faces.context.FacesContext;
  | import javax.faces.convert.Converter;
  | import javax.faces.convert.ConverterException;
  | 
  | public class ReferenceConverter  implements Converter, Serializable{    
  |     private static final long serialVersionUID = -6268456071880135380L;
  |     private static final String EMPTY = "__EMPTY__";    
  |     private List<Object> values;    
  |     public ReferenceConverter(List vals) {
  |         this.values = vals;
  |     }
  |     public String getAsString(FacesContext facesContext,
  |             UIComponent  component,
  |             Object       obj) {
  |         if (obj == null) return EMPTY;
  |         if ("-1".equals(obj)) return EMPTY;
  |         
  |         String val = String.valueOf( obj.hashCode() );
  |         return val;
  |     }    
  |     public Object getAsObject(FacesContext facesContext,
  |             UIComponent  component,
  |             String       str)
  |             throws ConverterException {
  |         if (str == null || str.length()==0 || EMPTY.equals(str)) {
  |             return null;
  |         }        
  |         int hash = Integer.valueOf(str).intValue();
  |         for (Object val : values) {
  |             if ( val!=null && val.hashCode()==hash ) {
  |                 return val;
  |             }
  |         }        
  |         return null;
  |     }
  | }
  | 

2. i posted session bean above;
3 and jps :


  | <h:selectOneMenu styleClass="font_style" required="true" value="" converter="#{billAdmin.converter}">
  | <s:selectItems value="#{billAdmin.langItems}" var="langItems" label="#{langItems.name}" />
  | </h:selectOneMenu>
  | 

what i did wrong ?

i could not find about converter into seam-ui examples.


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4018752#4018752

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4018752



More information about the jboss-user mailing list