Hello, I'm trying to add an "other" option to my select menu and have the
other option trigger a zone reload when selected. You can find a UI example
here " http://drupal.org/node/330740 ". I'm currently using T5.2.5 with
hibernate. My user interface uses two AjaxFormLoops, one nested inside the
other and finally the select menu within the nested AjaxFormLoop. 

<t:AjaxFormLoop t:id="lineItem" source="purchaseRequest.lineItems"
value="lineItem" encoder="encoderLineItem">
<t:AjaxFormLoop t:id="lineItemFunding" context="lineItem.tempId"
source="lineItem.lineItemFundings" value="lineItemFunding"
encoder="encoderLineItemFunding">
<t:Select t:id="newFunding" value="lineItemFunding.funding"
model="fundingModel" zone="fundingZone" blankOption="always"
blankLabel="Funding Source"/>
</t:AjaxFormLoop>
</t:AjaxFormLoop>

I want to manually add the "other" option to the select menu and not save it
to the database.  I'm doing this with the following code within the
onPrepare method. 

    @Persist
    @Property
    private List<Funding> _fundings;

    @Property
    @Persist
    private PurchaseRequest purchaseRequest;

void onPrepareFromPR() {

purchaseRequest = new PurchaseRequest();

        _fundings =
session.createCriteria(Funding.class).add(Restrictions.eq("purchaseRequest.id",
purchaseRequest.getId())).list();

        funding = new Funding();
        funding.setName("other");
        funding.setId(-1);
        _fundings.add(funding);

        fundingModel = selectModelFactory.create(_fundings, "label");
}

and lastly, I'm using the onValueChanged method to hand the AJAX request

    public Object onValueChanged(Funding funding) {
        if(funding != null && funding.getName().equals("other")) {
            return fundingZone.getBody();
        }
        return null;
    }

I get the following error [ERROR]entities.Funding Unable to convert client
value '-1' into an entity instance.

I would like to add I'm building a purchaseRequest object with a one to many
Funding Object as well as a one to many lineItem object. Both the Funding
Object and the LineItem object have a one to many with a LineItemFunding
Object. When I use the ValueEncoder with a UUID and the Funding object, the
onValueChanged method returns the funding label, however the object doesn't
get commited with the purchaseRequest.lineItem.lineItemFunding. 

See both examples below of the two ValueEncoders. 

Attempt 1

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

            public Funding toValue(String keyAsString) {
                Long key = new Long(keyAsString);
                for (Funding holder : purchaseRequest.getFundings()) {

                    if (holder.getTempId() == key) {
                        return holder;
                    }
                }
                return null;
            }
        };
    }

Attempt 2

    @Persist
    @Property
    private List<Funding> _fundings;

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

            public Funding toValue(String keyAsString) {
                Long key = new Long(keyAsString);
                for (Funding holder : _fundings) {

                    if (holder.getTempId() == key) {
                        return holder;
                    }
                }
                return null;
            }
        };
    }


I almost feel the Select component should have an other parameter option
with the ability to provide it with any custom text that can be picked up by
the onValueChanged in order to easily return a zone and further enrich our
interfaces. 

Any help with this issue would be greatly appreciated. 

Cheers,
George

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

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

Reply via email to