You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Eugen <eu...@gmail.com> on 2013/09/27 22:24:36 UTC

many checklist's with one selected list

Hi,
it is possible to bind the same list of enums to many checklist
components inside one form?
My scenario is follow:
1 given are an enum:
        enum A{ BA, BB, CA, CB, DA, DB}
2. the second enum split the enum A in more groups
        private List<A> enums;
        enum Group(A[]) {
               B({BA, BB}},
               C({CA,CB}),
               D({DA,DB})};
3. Form:
         <t:checklist encoder="enumAEncoder" model="GroupBModel"
selected="listOfA"/>
         <t:checklist encoder="enumAEncoder" model="GroupCModel"
selected="listOfA"/>
         <t:checklist encoder="enumAEncoder" model="GroupDModel"
selected="listOfA"/>

Actually on form submit all selected values froun GroupB and C are
ignored and the listOfA contains only values from GroupD.

Thanks
Eugen

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


Re: many checklist's with one selected list

Posted by Eugen <eu...@gmail.com>.
Hi Thiago,
thanks for Your help!!!
the checklists works fine now, each checklist has its own list of
enums and in processSubmission() of the parent component all list are
merged and copied back  to desired list.


Best regards
Eugen

2013/9/28 Thiago H de Paula Figueiredo <th...@gmail.com>:
> On Fri, 27 Sep 2013 18:39:46 -0300, Eugen <eu...@gmail.com> wrote:
>
>> The mean of the grouping is only for display: each group becomes a
>> caption and is placed in a separate column, but the selected list to
>> persist should be unique
>> All would be nice if the checklist would append to the list and not empty
>> it...
>
>
> Then you're asking for a component (Checklist) to do what it was never
> supposed to do.
>
>
>> One option would be to to have separate lists for each group and to
>> merge they all in one list by form submition, but I would like to make
>> a component from the checklists and inject it in a form, in this case
>> the componet should be parametrized with more lists parameters that is
>> redundant...
>
>
> It wouldn't be redundant. You need one parameter for the list to be set and
> another for the options. Inside your component, you'll have three different
> lists edited by different Checklist component instances.
>
>
>> what would be an alternative to do that?
>
>
> I don't think so. You have a very specific requirement.
>
>
> --
> Thiago H. de Paula Figueiredo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

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


Re: many checklist's with one selected list

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 27 Sep 2013 18:39:46 -0300, Eugen <eu...@gmail.com> wrote:

> The mean of the grouping is only for display: each group becomes a
> caption and is placed in a separate column, but the selected list to
> persist should be unique
> All would be nice if the checklist would append to the list and not  
> empty it...

Then you're asking for a component (Checklist) to do what it was never  
supposed to do.

> One option would be to to have separate lists for each group and to
> merge they all in one list by form submition, but I would like to make
> a component from the checklists and inject it in a form, in this case
> the componet should be parametrized with more lists parameters that is
> redundant...

It wouldn't be redundant. You need one parameter for the list to be set  
and another for the options. Inside your component, you'll have three  
different lists edited by different Checklist component instances.

> what would be an alternative to do that?

I don't think so. You have a very specific requirement.

-- 
Thiago H. de Paula Figueiredo

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


Re: many checklist's with one selected list

Posted by Eugen <eu...@gmail.com>.
The mean of the grouping is only for display: each group becomes a
caption and is placed in a separate column, but the selected list to
persist should be unique
All would be nice if the checklist would append to the list and not empty it...

One option would be to to have separate lists for each group and to
merge they all in one list by form submition, but I would like to make
a component from the checklists and inject it in a form, in this case
the componet should be parametrized with more lists parameters that is
redundant...

what would be an alternative to do that?

the complete example:

public enum RiskType {
    NONE, AGE, SEX, SMOKING, LIPID_METHABOLISM, GENETIC, ADIPOSIS,
GLUCOSE_INTOLERANCE, HYPERTROPHY, SCLEROSIS, HIGH_CREATININ,
ALBUMINURIA, CREATININCLEARANCE, HIGH_PULSWAVE, HIGH_ABI_INDEX,
DIABETES, CEREBROVASCULAR_DISEASE, CARDIAC_DISEASE, KIDNEY_DISEASE,
VASCULAR_DISEASE, RETINOPATHY}

public enum RiskGroup {
    CARDIOVASCULAR_NO_RISK(new RiskType[] { RiskType.NONE }),
    CARDIOVASCULAR_SIMPLE_RISK(new RiskType[] { RiskType.AGE,
RiskType.SEX, RiskType.SMOKING, RiskType.LIPID_METHABOLISM,
RiskType.GENETIC, RiskType.ADIPOSIS, RiskType.GLUCOSE_INTOLERANCE }),
    CARDIOVASCULAR_TARGET_ORGAN(new RiskType[] { RiskType.HYPERTROPHY,
RiskType.SCLEROSIS, RiskType.HIGH_CREATININ ,RiskType.ALBUMINURIA
,RiskType.CREATININCLEARANCE, RiskType.HIGH_PULSWAVE,
RiskType.HIGH_ABI_INDEX}),
    CARDIOVASCULAR_DIABETES(new RiskType[] { RiskType.DIABETES}),
    CARDIOVASCULAR_ACC(new RiskType[]
{RiskType.CEREBROVASCULAR_DISEASE, RiskType.CARDIAC_DISEASE,
RiskType.KIDNEY_DISEASE, RiskType.VASCULAR_DISEASE,
RiskType.RETINOPATHY});

    private final List<RiskType>    risks;

    RiskGroup(RiskType[] risks) {
        this.risks = Arrays.asList(risks);
    }
    public RiskType[] getRisks() {
        return this.risks.toArray(new RiskType[] {});
    }
}

RiskSelect.tml

    <div class="col-xs-12">
        <t:label for="norisk"
class="sr-only">${message:no-risk-group-label}</t:label>
        <t:checklist t:id="norisk" encoder="encoder"
model="getRiskModel('CARDIOVASCULAR_NO_RISK')"
t:selected="patient.risks"/>
    </div>

    <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
        <t:label for="simplerisk">${message:simple-risk-group-label}</t:label>
        <t:checklist t:id="simplerisk" encoder="encoder"
model="getRiskModel('CARDIOVASCULAR_SIMPLE_RISK')"
t:selected="patient.risks" />
    </div>

    <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
        <t:label for="targetorgan">${message:target-organ-group-label}</t:label>
        <t:checklist t:id="targetorgan" encoder="encoder"
model="getRiskModel('CARDIOVASCULAR_TARGET_ORGAN')"
t:selected="patient.risks" />
    </div>

    <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
        <t:label for="diabetes">${message:diabetes-group-label}</t:label>
        <t:checklist t:id="diabetes" encoder="encoder"
model="getRiskModel('CARDIOVASCULAR_DIABETES')"
t:selected="patient.risks" />
    </div>

    <div class="col-lg-3 col-md-4 col-sm-6 col-xs-12">
        <t:label for="acc">${message:acc-group-label}</t:label>
        <t:checklist t:id="acc" encoder="encoder"
model="getRiskModel('CARDIOVASCULAR_ACC')" selected="patient.risks" />
    </div>

RiskSelect.java
    @Property
    @Parameter
    Patient                patient;

    @Inject
    TypeCoercer            typeCoercer;

    @Inject
    Messages            messages;

    @Environmental
    private FormSupport    formSupport;

    public ValueEncoder<RiskType> getEncoder() {
        return new EnumValueEncoder<RiskType>(typeCoercer, RiskType.class);
    }

    public SelectModel getRiskModel(String riskGroup) {
        List<OptionModel> optionModel = new ArrayList<OptionModel>();
        for (RiskType riskType : RiskGroup.valueOf(riskGroup).getRisks()) {
            optionModel.add(new
OptionModelImpl(messages.get(riskType.name() + "-label"), riskType));
        }
        return new SelectModelImpl(null, optionModel);
    }

And the page tml:
<t:form>
    ...
    <t:riskselect patient="patient"/>
    <t:submit />
</t:form>

The next step would be render the checklists in a loop based on
groups, so any changes in the Enums would be displayed automatically

2013/9/27 Thiago H de Paula Figueiredo <th...@gmail.com>:
> On Fri, 27 Sep 2013 17:24:36 -0300, Eugen <eu...@gmail.com> wrote:
>
>> Hi,
>
>
> Hi!
>
>
>> it is possible to bind the same list of enums to many checklist
>> components inside one form?
>
>
> Why do you want to do that? I'm not sure how editing three times the same
> list in the same form makes sense. Why don't you have three different list
> instances to edit, all them having the same
>
>
>> Actually on form submit all selected values froun GroupB and C are
>> ignored and the listOfA contains only values from GroupD.
>
>
> That's the expected behavior. The first Checklist instance sets the list,
> then the second sets the same list, then the third does the same. It's the
> same as this:
>
> List<A> selected = ...;
> List<A> list = ...;
> list = selected;
> list = selected;
> list = selected;
>
> --
> Thiago H. de Paula Figueiredo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

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


Re: many checklist's with one selected list

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Fri, 27 Sep 2013 17:24:36 -0300, Eugen <eu...@gmail.com> wrote:

> Hi,

Hi!

> it is possible to bind the same list of enums to many checklist
> components inside one form?

Why do you want to do that? I'm not sure how editing three times the same  
list in the same form makes sense. Why don't you have three different list  
instances to edit, all them having the same

> Actually on form submit all selected values froun GroupB and C are
> ignored and the listOfA contains only values from GroupD.

That's the expected behavior. The first Checklist instance sets the list,  
then the second sets the same list, then the third does the same. It's the  
same as this:

List<A> selected = ...;
List<A> list = ...;
list = selected;
list = selected;
list = selected;

-- 
Thiago H. de Paula Figueiredo

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