Hi !
So, I tried to use a checklist, and as you said, it worked ! For anyone
wanting the solution :
TestList.java :
public class TestList {
@Inject
private AlertManager alertManager;
@Persist
@Property
private List<CheckText> list;
@Persist
@Property
private List<ConsentText> selectedValues;
@Property
private CheckText currentText;
@InjectComponent
private Form form;
@OnEvent(value = EventConstants.ACTIVATE)
public void initOnActivate() {
if (list == null) {
list = new ArrayList<>();
CheckText newtext;
for (int i = 0; i < 5; i++) {
newtext = new CheckText();
newtext.setId(i);
newtext.setText("Test n°" + i);
newtext.setTicked(false);
list.add(newtext);
}
}
if(selectedValues == null) {
selectedValues = new ArrayList<>();
}
}
@OnEvent(value = EventConstants.SUCCESS)
public void submit() {
for (CheckText text : list) {
if (!selectedValues.contains(text)) {
form.recordError("Error on " + text.getText());
}
}
}
public Object onSuccessFromForm() {
alertManager.alert(Duration.SINGLE, Severity.INFO, "Yee haa");
return null;
}
public TextSelectModel getCheckTextModel() {
return new TextSelectModel(list);
}
public ValueEncoder<CheckText> getCheckTextEncoder() {
return new CheckTextEncoder(list);
}
}
TestList.tml:
<t:alerts/>
<t:form t:id="form">
<t:errors/>
<t:checklist t:id="textsToCheck" encoder="textEncoder"
model="checkTextModel" selected="selectedValues"/>
<t:submit t:id="submitCheck"/>
</t:form>
CheckTextEncoder.java:
public class CheckTextEncoder implements ValueEncoder<CheckText>,
ValueEncoderFactory<CheckText> {
private List<CheckText> texts;
public CheckTextEncoder() {
texts = new ArrayList<>();
}
public CheckTextEncoder(List<CheckText> texts) {
this.texts = texts;
}
@Override
public ValueEncoder<CheckText> create(Class<CheckText> type) {
return this;
}
@Override
public String toClient(CheckText value) {
return value.getText();
}
@Override
public CheckText toValue(String clientValue) {
for (CheckText text : texts) {
if (text.getText().equals(clientValue)) {
return text;
}
}
return null;
}
}
CheckTextModel
public class TextSelectModel extends AbstractSelectModel implements
SelectModel {
private List<CheckText> texts;
public TextSelectModel(List<CheckText> texts) {
this.texts = texts;
}
@Override
public List<OptionGroupModel> getOptionGroups() {
return null;
}
@Override
public List<OptionModel> getOptions() {
List<OptionModel> options = new ArrayList<>();
for (CheckText text : texts) {
options.add(new OptionModelImpl(text.getText(), text));
}
return options;
}
}
--------------------
The checked texts are stored in "selectedValues", and then I can verify
which one is not in.
Regards,
Adrien
2013/10/2 Thiago H de Paula Figueiredo <[email protected]>
> On Wed, 02 Oct 2013 04:32:36 -0300, Adrien Berthet <[email protected]>
> wrote:
>
> Oh sorry I didn't think of this page ! So there is three distinct
>> exceptions, all with the same message:
>>
>> Failure writing parameter 'value' of component TestList:textToCheck:
>> Property 'currentText' (within property expression 'currentText.ticked',
>> of
>> net.adrien.test.TestList@**27084440) is null.
>>
>
> This means that, during form submission, not rendering, textToCheck is
> null. Use the prepare event of Form to make sure textToCheck isn't null
> before the submission processing is done.
>
>
> 1 - org.apache.tapestry5.ioc.**internal.OperationException: happens at
>> the
>> beginning on the form, <t:form id="form">
>>
>> 2 - org.apache.tapestry5.runtime.**ComponentEventException: same location
>>
>> 3 - org.apache.tapestry5.ioc.**internal.util.**TapestryException:
>> happens at
>> the checkbox line, <t:checkbox t:id="textToCheck"
>> t:value="currentText.ticked" label="prop:currentText.text" />
>>
>
> It's actually all the same error in the same place. Tapestry shows
> something like a stack trace for template locations too.
>
>
> Thank for all, Thiago !
>>
>
> ;)
>
>
> --
> Thiago H. de Paula Figueiredo
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail:
> users-unsubscribe@tapestry.**apache.org<[email protected]>
> For additional commands, e-mail: [email protected]
>
>