[jboss-user] [JBoss Seam] - Problem with custom converter for class access in facelets u
Rincewind77
do-not-reply at jboss.com
Sun Feb 10 05:44:18 EST 2008
I try to register a custom converter for my business model enums in Seam 2.0.1.GA. This works fine until I do use facelets EL to access my properties.
That's my enum:
public enum Gender {
| MALE, FEMALE
| }
Here's my converter (it's not finished, I know ;-):
@Name("genderConverter")
| @org.jboss.seam.annotations.faces.Converter(forClass = Gender.class)
| public class GenderConverter implements Converter, Serializable {
|
| private static final long serialVersionUID = 3237852262587078904L;
|
| public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String string) {
| // TODO
| return Gender.MALE;
| }
| public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object object) {
| String retVal = null;
| if (object instanceof Enum) {
| final Enum<Gender> instance = (Enum<Gender>) object;
| final String resourceKey = instance.name();
| // final String resourceKey = instance.getClass().getName() + "." +
| // instance.name();
| try {
| retVal = ResourceBundle.instance().getString(resourceKey);
| } catch (MissingResourceException e) {
| // Ignore
| System.out.println(e);
| }
| if ("".equals(retVal)) {
| retVal = instance.name();
| }
| }
| System.out.println("retrieved gener " + retVal);
| return retVal;
|
| }
|
| }
Now it depends on the facelets page if the above code is working.
This works fine and retrieves the translation for the key from the messages properties ("male"):
<div class="entry">
| <div class="label">Geschlecht:</div>
| <div class="output"><h:outputText value="#{member.gender}"/></div>
| </div>
This doesn't work, because only the name of the enum ("MALE") is displayed:
<div class="entry">
| <div class="label">Gender:</div>
| <div class="output">#{member.gender}</div>
| </div>
Has anyone a idea why my custom converter doesn't work with the second style?
Thanks, Maik.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4128161#4128161
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4128161
More information about the jboss-user
mailing list