You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by SeldonCrisis <nm...@gmail.com> on 2017/01/25 19:35:01 UTC
Ajax request stopped because of precondition check on CheckGroup
Hi,
I'm trying to implement some *Ajax* on a *CheckGroup* containing two check
boxes. The purpose of this Ajax Event is to enable/disable a form button
depending on whether or not the checkboxes in the CheckGroup are true/false
(their models).
Unfortunately, I can't get anything in the onUpdate() to run, and when I
toggle a breakpoint on onUpdate() I don't actually reach it. Instead, I get
a message in the Ajax Debug Window:
INFO: focus set on cg1-cb1
INFO: Ajax request stopped because of precondition check, url:
./submit?3-5.IBehaviorListener.0-form-fileClaimContainer-cg1
INFO: focus removed from cg1-cb1
*Here's the relevant Java: *
fileClaimContainer = new WebMarkupContainer("fileClaimContainer");
fileClaimContainer.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true).setVisible(true);
final Button fileClaimButton;
final CheckBox cb1 = new CheckBox("cg1-cb1", new Model<Boolean>(false));
final CheckBox cb2 = new CheckBox("cg1-cb2", new Model<Boolean>(false));
fileClaimButton = new Button("fileClaimButton");
fileClaimButton.setOutputMarkupId(true);
fileClaimButton.setOutputMarkupPlaceholderTag(true);
CheckGroup cg1 = new CheckGroup("cg1", new Model());
cg1.setOutputMarkupId(true);
cg1.setOutputMarkupPlaceholderTag(true);
cg1.add(cb1, cb2);
cg1.add(new AjaxFormChoiceComponentUpdatingBehavior() {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
if (!cb1.getModelObject() || !cb2.getModelObject())
fileClaimButton.setEnabled(false);
else
fileClaimButton.setEnabled(true);
target.add(fileClaimButton);
}
});
fileClaimContainer.add(fileClaimButton);
fileClaimContainer.add(cg1);
*And heres the HTML: *
<div wicket:id = "fileClaimContainer">
<ul wicket:id="cg1" class="checkboxgroup" id="cg1" role="checkboxgroup">
<li>
<input type="checkbox" wicket:id="cg1-cb1" id="cg1-cb1" name="cg1-cb1"
value="true" aria-labelledby="cb1_label" aria-required="true">
<label id="cb1_label" for="cg1-cb1">Label 1</label>
</li>
<li>
<input type="checkbox" wicket:id="cg1-cb2" id="cg1-cb2" name="cg1-cb2"
value="true" aria-labelledby="cb2_label" aria-required="true">
<label id="cb2_label" for="cg1-cb2">Label 2</label>
</li>
</ul>
<small>Warning</small><br></br>
<div class="frm-contbtns">
<input class="btn-sbmt" wicket:id="fileClaimButton" type="submit"
value="File This Petition" />
</div>
</div>
I found that many questions similar to this have been asked here before, and
I've looked through those past forum posts for a solution, but I'm quite new
to Wicket and I'm having trouble applying those solutions to my problem. I
would really appreciate any help I could get here. Thanks!
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Ajax-request-stopped-because-of-precondition-check-on-CheckGroup-tp4676865.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Ajax request stopped because of precondition check on CheckGroup
Posted by Sven Meier <sv...@meiers.net>.
Hi Martin,
he did use AjaxFormChoiceComponentUpdatingBehavior (as seen in the first
code snippet).
Too bad we won't know what went wrong here:
You can use multiple AjaxCheckBoxes instead, but it requires much more work.
Have fun
Sven
On 26.01.2017 20:49, Martin Grigorov wrote:
> Hi,
>
> On Thu, Jan 26, 2017 at 6:56 PM, SeldonCrisis <nm...@gmail.com> wrote:
>
>> I just wanted to update this in case anyone else references it in the
>> future.
>> While the *Check* fix was a solution to the *"precondition check"* error, I
>> was still unable to execute the ajax instructions inside the overridden
>> *"protected void onUpdate(AjaxRequestTarget target){}"* method.
>>
> When you use a CheckGroup you have to
> use org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior to
> receive Ajax notifications when the checkboxes are toggled.
>
>
>> For this reason, I decided to instead use *AjaxCheckBox*, alternatively
>> implementing all the logic in both overridden *"onUpdate"* methods. I used
>> an array of Boolean values to represent the values of the Model Objects
>> since I wouldn't be able to refer to the Model Object of the second
>> AjaxCheckBox in the onUpdate of the first as it has yet to be instantiated.
>>
>> *Here's my Java code:*
>> final Button fileClaimButton;
>> final CheckBox cb1, cb2;
>> final boolean[] bArray = {false, false};
>>
>> fileClaimButton = new AjaxButton("fileClaimButton"){
>> private static final long serialVersionUID = 1L;
>> @Override
>> protected void onSubmit(AjaxRequestTarget target, Form<?> form){
>> System.out.print("File Claim Executed");
>> }
>> };
>> fileClaimButton.setEnabled(false);
>> fileClaimButton.setOutputMarkupId(true);
>> fileClaimButton.setOutputMarkupPlaceholderTag(true);
>>
>> cb1 = new AjaxCheckBox("cg1-cb1", new Model<Boolean>(false)){
>> @Override
>> protected void onUpdate(AjaxRequestTarget target) {
>> bArray[0] = getModelObject();
>> if (bArray[0] == true && bArray[1] == true)
>> fileClaimButton.setEnabled(true);
>> else
>> fileClaimButton.setEnabled(false);
>>
>> target.add(fileClaimButton);
>> }};
>>
>> cb2 = new AjaxCheckBox("cg1-cb2", new Model<Boolean>(false)){
>> @Override
>> protected void onUpdate(AjaxRequestTarget target) {
>> bArray[1] = getModelObject();
>> if (bArray[0] == true && bArray[1] == true)
>> fileClaimButton.setEnabled(true);
>> else
>> fileClaimButton.setEnabled(false);
>>
>> target.add(fileClaimButton);
>> }};
>>
>> --
>> View this message in context: http://apache-wicket.1842946.
>> n4.nabble.com/Ajax-request-stopped-because-of-precondition-check-on-
>> CheckGroup-tp4676865p4676880.html
>> Sent from the Users forum mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Ajax request stopped because of precondition check on CheckGroup
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
On Thu, Jan 26, 2017 at 6:56 PM, SeldonCrisis <nm...@gmail.com> wrote:
> I just wanted to update this in case anyone else references it in the
> future.
> While the *Check* fix was a solution to the *"precondition check"* error, I
> was still unable to execute the ajax instructions inside the overridden
> *"protected void onUpdate(AjaxRequestTarget target){}"* method.
>
When you use a CheckGroup you have to
use org.apache.wicket.ajax.form.AjaxFormChoiceComponentUpdatingBehavior to
receive Ajax notifications when the checkboxes are toggled.
>
> For this reason, I decided to instead use *AjaxCheckBox*, alternatively
> implementing all the logic in both overridden *"onUpdate"* methods. I used
> an array of Boolean values to represent the values of the Model Objects
> since I wouldn't be able to refer to the Model Object of the second
> AjaxCheckBox in the onUpdate of the first as it has yet to be instantiated.
>
> *Here's my Java code:*
> final Button fileClaimButton;
> final CheckBox cb1, cb2;
> final boolean[] bArray = {false, false};
>
> fileClaimButton = new AjaxButton("fileClaimButton"){
> private static final long serialVersionUID = 1L;
> @Override
> protected void onSubmit(AjaxRequestTarget target, Form<?> form){
> System.out.print("File Claim Executed");
> }
> };
> fileClaimButton.setEnabled(false);
> fileClaimButton.setOutputMarkupId(true);
> fileClaimButton.setOutputMarkupPlaceholderTag(true);
>
> cb1 = new AjaxCheckBox("cg1-cb1", new Model<Boolean>(false)){
> @Override
> protected void onUpdate(AjaxRequestTarget target) {
> bArray[0] = getModelObject();
> if (bArray[0] == true && bArray[1] == true)
> fileClaimButton.setEnabled(true);
> else
> fileClaimButton.setEnabled(false);
>
> target.add(fileClaimButton);
> }};
>
> cb2 = new AjaxCheckBox("cg1-cb2", new Model<Boolean>(false)){
> @Override
> protected void onUpdate(AjaxRequestTarget target) {
> bArray[1] = getModelObject();
> if (bArray[0] == true && bArray[1] == true)
> fileClaimButton.setEnabled(true);
> else
> fileClaimButton.setEnabled(false);
>
> target.add(fileClaimButton);
> }};
>
> --
> View this message in context: http://apache-wicket.1842946.
> n4.nabble.com/Ajax-request-stopped-because-of-precondition-check-on-
> CheckGroup-tp4676865p4676880.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Ajax request stopped because of precondition check on
CheckGroup
Posted by SeldonCrisis <nm...@gmail.com>.
I just wanted to update this in case anyone else references it in the future.
While the *Check* fix was a solution to the *"precondition check"* error, I
was still unable to execute the ajax instructions inside the overridden
*"protected void onUpdate(AjaxRequestTarget target){}"* method.
For this reason, I decided to instead use *AjaxCheckBox*, alternatively
implementing all the logic in both overridden *"onUpdate"* methods. I used
an array of Boolean values to represent the values of the Model Objects
since I wouldn't be able to refer to the Model Object of the second
AjaxCheckBox in the onUpdate of the first as it has yet to be instantiated.
*Here's my Java code:*
final Button fileClaimButton;
final CheckBox cb1, cb2;
final boolean[] bArray = {false, false};
fileClaimButton = new AjaxButton("fileClaimButton"){
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form){
System.out.print("File Claim Executed");
}
};
fileClaimButton.setEnabled(false);
fileClaimButton.setOutputMarkupId(true);
fileClaimButton.setOutputMarkupPlaceholderTag(true);
cb1 = new AjaxCheckBox("cg1-cb1", new Model<Boolean>(false)){
@Override
protected void onUpdate(AjaxRequestTarget target) {
bArray[0] = getModelObject();
if (bArray[0] == true && bArray[1] == true)
fileClaimButton.setEnabled(true);
else
fileClaimButton.setEnabled(false);
target.add(fileClaimButton);
}};
cb2 = new AjaxCheckBox("cg1-cb2", new Model<Boolean>(false)){
@Override
protected void onUpdate(AjaxRequestTarget target) {
bArray[1] = getModelObject();
if (bArray[0] == true && bArray[1] == true)
fileClaimButton.setEnabled(true);
else
fileClaimButton.setEnabled(false);
target.add(fileClaimButton);
}};
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Ajax-request-stopped-because-of-precondition-check-on-CheckGroup-tp4676865p4676880.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Ajax request stopped because of precondition check on
CheckGroup
Posted by SeldonCrisis <nm...@gmail.com>.
Ahhh that worked perfectly and was such a simple fix. So now I understand
that Check is to be used in a CheckGroup and CheckBox is only useful if used
alone. Thank you very much!
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Ajax-request-stopped-because-of-precondition-check-on-CheckGroup-tp4676865p4676869.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Ajax request stopped because of precondition check on CheckGroup
Posted by Sven Meier <sv...@meiers.net>.
Hi,
you have to use org.apache.wicket.markup.html.form.*Check* inside your
CheckGroup, not Checkboxes.
Have fun
Sven
On 25.01.2017 20:35, SeldonCrisis wrote:
> Hi,
>
> I'm trying to implement some *Ajax* on a *CheckGroup* containing two check
> boxes. The purpose of this Ajax Event is to enable/disable a form button
> depending on whether or not the checkboxes in the CheckGroup are true/false
> (their models).
>
> Unfortunately, I can't get anything in the onUpdate() to run, and when I
> toggle a breakpoint on onUpdate() I don't actually reach it. Instead, I get
> a message in the Ajax Debug Window:
> INFO: focus set on cg1-cb1
> INFO: Ajax request stopped because of precondition check, url:
> ./submit?3-5.IBehaviorListener.0-form-fileClaimContainer-cg1
> INFO: focus removed from cg1-cb1
>
> *Here's the relevant Java: *
> fileClaimContainer = new WebMarkupContainer("fileClaimContainer");
> fileClaimContainer.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true).setVisible(true);
>
> final Button fileClaimButton;
> final CheckBox cb1 = new CheckBox("cg1-cb1", new Model<Boolean>(false));
> final CheckBox cb2 = new CheckBox("cg1-cb2", new Model<Boolean>(false));
>
> fileClaimButton = new Button("fileClaimButton");
> fileClaimButton.setOutputMarkupId(true);
> fileClaimButton.setOutputMarkupPlaceholderTag(true);
>
> CheckGroup cg1 = new CheckGroup("cg1", new Model());
> cg1.setOutputMarkupId(true);
> cg1.setOutputMarkupPlaceholderTag(true);
> cg1.add(cb1, cb2);
> cg1.add(new AjaxFormChoiceComponentUpdatingBehavior() {
> private static final long serialVersionUID = 1L;
> @Override
> protected void onUpdate(AjaxRequestTarget target) {
> if (!cb1.getModelObject() || !cb2.getModelObject())
> fileClaimButton.setEnabled(false);
> else
> fileClaimButton.setEnabled(true);
> target.add(fileClaimButton);
> }
> });
>
> fileClaimContainer.add(fileClaimButton);
> fileClaimContainer.add(cg1);
>
> *And heres the HTML: *
> <div wicket:id = "fileClaimContainer">
> <ul wicket:id="cg1" class="checkboxgroup" id="cg1" role="checkboxgroup">
> <li>
> <input type="checkbox" wicket:id="cg1-cb1" id="cg1-cb1" name="cg1-cb1"
> value="true" aria-labelledby="cb1_label" aria-required="true">
> <label id="cb1_label" for="cg1-cb1">Label 1</label>
> </li>
> <li>
> <input type="checkbox" wicket:id="cg1-cb2" id="cg1-cb2" name="cg1-cb2"
> value="true" aria-labelledby="cb2_label" aria-required="true">
> <label id="cb2_label" for="cg1-cb2">Label 2</label>
> </li>
> </ul>
>
> <small>Warning</small><br></br>
>
>
> <div class="frm-contbtns">
> <input class="btn-sbmt" wicket:id="fileClaimButton" type="submit"
> value="File This Petition" />
> </div>
> </div>
>
> I found that many questions similar to this have been asked here before, and
> I've looked through those past forum posts for a solution, but I'm quite new
> to Wicket and I'm having trouble applying those solutions to my problem. I
> would really appreciate any help I could get here. Thanks!
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Ajax-request-stopped-because-of-precondition-check-on-CheckGroup-tp4676865.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Ajax request stopped because of precondition check on
CheckGroup
Posted by SeldonCrisis <nm...@gmail.com>.
I suspect it has something to do with the Model object of the CheckGroup cg1?
I know it is supposed to be of type Collection. Maybe that's what's causing
the precondition check to fail?
--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Ajax-request-stopped-because-of-precondition-check-on-CheckGroup-tp4676865p4676866.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org