[jboss-user] [JBoss Seam] - Re: Problems using JSF Converters in Seam app

smartbinary do-not-reply at jboss.com
Wed Oct 4 11:00:48 EDT 2006


An update, as promised...

Updating the bean to use the correct attribute type did indeed resolve the problem.  I had started out that way, but backed off when Hibernate Validation & JPA annotations were creating a whole slew of other problems.

So...here are the mods:

1) Converter (just changed to be EVENT scope):

  | package org.jboss.seam.example.hibernate;
  | 
  | import java.io.Serializable;
  | 
  | import javax.faces.component.UIComponent;
  | import javax.faces.context.FacesContext;
  | import javax.faces.convert.Converter;
  | import javax.faces.convert.ConverterException;
  | 
  | import org.jboss.seam.InterceptionType;
  | import org.jboss.seam.ScopeType;
  | import org.jboss.seam.annotations.Intercept;
  | import org.jboss.seam.annotations.Name;
  | import org.jboss.seam.annotations.Scope;
  | 
  | @Scope(ScopeType.EVENT)
  | @Name("fullNameConverter")
  | @Intercept(InterceptionType.ALWAYS)
  | public class FullNameConverter implements Serializable, Converter {
  | 
  |     public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2)
  |             throws ConverterException {
  |         
  |         FullName fullName;
  |         fullName = new FullName(arg2);
  |         
  |         return fullName;
  |     }
  | 
  |     public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2)
  |             throws ConverterException {
  |         String returnString;
  |         
  |         FullName fullName;
  |         fullName = (FullName) arg2;
  |         
  |         returnString = (fullName==null ? null : fullName.toString());
  |         
  |         return returnString;
  |     }
  | 
  | }
  | 

2) Bean (just added transient attribute for testing converter):

  | .............
  | 
  | @Entity
  | @Name("appUser")
  | @Scope(SESSION)
  | public class AppUser implements Serializable
  | {
  |    private String username;
  |    private String password;
  |    private String name;
  |    private FullName fullName;
  |    
  | .............
  | 
  |    @NotNull
  |    @Length(max=100)
  |    public String getName()
  |    {
  |       return name;
  |    }
  |    public void setName(String name)
  |    {
  |       this.name = name;
  |    }
  | 
  |    @Transient
  |    public FullName getFullName()
  |    {
  |       return fullName;
  |    }
  |    public void setFullName(FullName fullName)
  |    {
  |       this.fullName = fullName;
  |    }
  | 
  | .............
  | 

3) register.xhtml (now converting new field & Ajax-enabled via Ajax4jsf)

  | .............
  | <s:validateAll>
  | 
  | .............
  | 
  | <div class="entry">
  |     <div class="label"><h:outputLabel for="name">Name:</h:outputLabel></div>
  |     <div class="input">
  |         <h:inputText id="name" value="#{appUser.name}" required="true">
  |             <a4j:support event="onkeyup" reRender="nameErrors" />
  |         </h:inputText>
  |         <br/>
  |         <a4j:outputPanel id="nameErrors">
  |             <span class="errors"><h:message for="name" /></span>
  |         </a4j:outputPanel>
  |     </div>
  | </div>
  | <div class="entry">
  |     <div class="label"><h:outputLabel for="fullName">Name (converted):</h:outputLabel></div>
  |     <div class="input">
  |         <a4j:outputPanel id="fullNamePanel">
  |             <h:inputText id="fullName" value="#{appUser.fullName}" required="true" converter="#{fullNameConverter}" >
  |                 <a4j:support event="onchange" reRender="fullName" />
  |             </h:inputText>
  |         </a4j:outputPanel>
  |     </div>
  | </div>
  | 
  | .............
  | 
  | </s:validateAll>
  | 
  | .............
  | 
  | 


Regards,

Todd

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

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



More information about the jboss-user mailing list