Hi Luis,

as an alternative I want to show you my solution given in the below listed
encoder class.
Each search criterion in my solution is represented by a type called
"TapestryClientCriterion". My generic search component renders any number
of "finder input lines" each having a list of possible search criteria
which can be selected in a drop down. 
My solution is based on the simple approach just to add a piece of
information identifying the input line a criterion belongs to in the client
id of each criterion. So a criterions client id consists of its own id and
a scond identifying the input line concatenated together with a certain
delimiter token. This all is done via an encoder (see below). 

/**
         * This encoder has the task to provide each client side element of the
         * component with id "<strong>criterionSelector</strong>" with a value
         * identifying this element by the id of the finder input line it is
         * rendered in and its own id. Both ids are concatenated using the "~"
token
         * as delimiter. The server side representation will be restored by
looking
         * up for the correct "<strong>{@linkplain TapestryClientCriterion}
         * </strong>" in the correct "<strong>{@linkplain
FinderInputLine}</strong>"
         * using the information coded in the above mentioned concatenated 
string.
         * The only sense of this encoder is to make each rendered finder
criterion
         * unique by the above id, because criteria are rendered multiple times 
in
         * the loop iterations.
         * 
         */
        private class ClientCriterionEncoder implements
                        ValueEncoder<TapestryClientCriterion> {

                /**
                 * @see 
org.apache.tapestry5.ValueEncoder#toClient(java.lang.Object)
                 * @param value
                 * @return The id of the looped finder input line.
                 */
                @Override
                public String toClient(TapestryClientCriterion value) {

                        String finderInputLineId = String.valueOf(value
                                        .getFinderInputLineId());
                        String criterionId = String.valueOf(value.getId());

                        return finderInputLineId + "~" + criterionId;
                }

                /**
                 * @see 
org.apache.tapestry5.ValueEncoder#toValue(java.lang.String)
                 * @param clientValue
                 * @return The finder input line for the given client id.
                 */
                @Override
                public TapestryClientCriterion toValue(String clientValue) {

                        TapestryClientCriterion clientCriterion = null;

                        try {

                                String[] idParts = clientValue.split("~");
                                String finderInputLineIdStr = idParts[0];
                                String criterionIdStr = idParts[1];
                                int finderInputLineId = 
Integer.parseInt(finderInputLineIdStr);
                                long criterionId = 
Long.parseLong(criterionIdStr);

                                // find the correct line
                                for (FinderInputLine finderInputLine : 
finderCallback
                                                .getFinderInputLinesToRender()) 
{

                                        if 
(finderInputLine.getFinderInputLineId() == finderInputLineId) {

                                                // find the correct criterion
                                                for (TapestryClientCriterion 
criterion : finderInputLine
                                                                
.getTapestryClientCriteria()) {

                                                        if (criterion.getId() 
== criterionId) {

                                                                clientCriterion 
= criterion;
                                                                break;
                                                        }
                                                } // inner for

                                                break;
                                        }
                                } // outer for
                        } catch (Exception e) {

                                LOG.info(e.getMessage(), e);
                        }

                        return clientCriterion;
                }
        }


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

Reply via email to