Hi Luis,

in my component there is an icon enabling the user to add a new input row on the fly. Each rendered input row has got an id which is incremented for each new row. Because my filter criteria object is a field in the row object it is instantiated together with it and so I'm able to write the id of the new input row into each criteria object.

Later when triggering events by the criteria object it is a big advantage that each of them owns the id of "its own" finder row as property.

You can believe that it took sweat and tears to develope this component and get it into production.

Currently I'am still facing the problem that I do ajax calls on each onChange event triggered by a filter criteria object, but that values entered in an input field belonging to a search criterion object are lost after the call. I think this depends on the fact that there is no state given for input components in such a context.

Greetings, Erich




Am 28.07.2014 20:40, schrieb Luis Salas:

Hi Erich, I'm doing the same you have done, I'm creating a Filter component that will have as many input rows as users needs. Each row use a filterCriteria object in which I will store the users input. I need to do something like you did but I'm having some troubles defining the client ids to use with the encoder. I had created a FilterRow component which contains all the inputs needed.
Can you let me see how you find the input line id?

Tnx for your help.

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






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

Reply via email to