[prev in list] [next in list] [prev in thread] [next in thread] 

List:       tapestry-user
Subject:    Re: T5 Select Menu with Other Option
From:       George Christman <gchristman () cardaddy ! com>
Date:       2011-06-30 16:00:39
Message-ID: 1309449639032-4539330.post () n5 ! nabble ! com
[Download RAW message or body]

After playing with the value encoder, I found this method to be slightly
better since it will handle newly created session objects / existing objects
and other. 

    @SuppressWarnings("unchecked")
    public ValueEncoder getSelectEncoder() {
        return new ValueEncoder<Funding>() {
            public String toClient(Funding value) {
                if (value == NEW_FUNDING) {
                    return NEW_FUNDING_ID;
                } else {
                    Long key = value.getTempId();
                    return key.toString();
                }
            }

            public Funding toValue(String clientValue) {
                if (NEW_FUNDING_ID.equals(clientValue))  {
                    return NEW_FUNDING;
                } else {
                    for (Funding _funding :
getPurchaseRequest().getFundings()) {
                        if (_funding.getTempId() ==
Long.parseLong(clientValue)) {
                            return _funding;
                        }
                    }
                }
                return null;
            }
        };
    }

--
View this message in context: \
http://tapestry.1045711.n5.nabble.com/T5-Select-Menu-with-Other-Option-tp4520881p4539330.html
 Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic