[jboss-user] [JBoss Seam] - [solution]: selectOneMenu binding to session object
joeyxxx
do-not-reply at jboss.com
Sat Jun 23 23:54:58 EDT 2007
If anyone else needs a solution, this is what I ended up doing.
|
| public class Avatar implements Serializable{
|
| private String nickName;
| private String style;
| private int index;
| /** Creates a new instance of Avatar */
| public Avatar() {
| }
|
| public Avatar(String nickName, String style, int index){
| this.style = style;
| this.nickName = nickName;
| this.index = index;
| }
|
|
| public String toString(){
| return this.index + "";
| }
|
| public String getNickName() {
| return nickName;
| }
|
| public String getStyle() {
| return style;
| }
|
| public String getSelectLabel(){
| return "***"+style + ":"+ nickName;
| }
| }
|
|
|
| @Name("avatarConverter")
| @Intercept(NEVER)
| @Converter
| public class AvatarConverter implements javax.faces.convert.Converter
| {
| @In User user;
| public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException
| {
| Integer i = new Integer(value);
| User user = (User) Contexts.getSessionContext().get("user");
| Avatar currentAvatar = user.getAvatarList().get(i.intValue());
| return currentAvatar;
| }
|
| public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException
| {
| return value + "";
| }
| }
|
|
|
| @Name("user")
| @Scope(SESSION)
| //@Startup
| public class User implements Serializable{
|
| @Logger private static Log log;
| private String userName;
| private Avatar currentAvatar;
| private List<Avatar> avatarList;
| /** Creates a new instance of User */
| public User() {
| }
|
| public User(String pUserName, List<Avatar> pAvatarList){
| this.userName = userName;
| this.avatarList = pAvatarList;
|
| if(avatarList.size()>0){
| this.currentAvatar = avatarList.get(0);
| } else {
| this.currentAvatar = new Avatar("Nick", "3d", 0);
| this.avatarList = new ArrayList();
| this.avatarList.add(currentAvatar);
| }
| }
|
| public List<Avatar> getAvatarList(){
| return this.avatarList;
| }
|
|
| @Create
| public void initialize(){
| System.out.println("User Initialized");
| }
|
| public void click(){
| log.info("User Click Invoked...");
| }
|
| public String getUserName() {
| return userName;
| }
|
| public void setUserName(String userName) {
| this.userName = userName;
| }
|
| public Avatar getCurrentAvatar() {
| return currentAvatar;
| }
|
| public void setCurrentAvatar(Avatar currentAvatar) {
| this.currentAvatar = currentAvatar;
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4057168#4057168
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4057168
More information about the jboss-user
mailing list