Yup, I'm using 5.4 in all my apps with the exception of one older one, so
no problem there.

Okay, for anybody else that may run into this situation, here is my demo
code. This is a main form with two separate ajax warnings chained together
with validation. The main form is injected as a block but set to display
none with css. Works perfectly an is stateless :)

Thanks Everyone.


Warning.java

public class Warning {

    @Component(id = "form")
    private Form form;

    @Component(id = "formWarning")
    private Form formWarning;

    @PageActivationContext
    @Property
    private Computer computer;

    @InjectComponent
    private Zone formZone, formWarningZone;

    @Inject
    private PageRenderLinkSource linkSource;

    @Inject
    private Session session;

    @Inject
    private AjaxResponseRenderer ajaxResponseRenderer;

    @Inject
    private Block warningBlock, notificationBlock;

    @Property
    private Block activeWarningBlock;

    @Property
    private boolean triggerWarning, triggerNotification, triggerValidation;

    @Property
    private boolean hasWarnings, hasValidationErrors;

    private boolean notificationEvent, warningEvent;

    void onActivate() {
        if (computer == null) {
            computer = new Computer();
        }
    }

    void onValidateFromForm() throws IllegalAccessException,
InvocationTargetException {
        //Handle validation main form.
        if(computer.getName() == null) {
            form.recordError("computer can not be null");
        } else if(form.getHasErrors()) {
            hasValidationErrors = true;
            ajaxResponseRenderer.addRender("formZone", formZone);
        }

        if(triggerWarning && form.isValid()) {
            form.recordError("trigger warning block");
            hasWarnings = true;
            activeWarningBlock = warningBlock;
            ajaxResponseRenderer.addRender("formWarningZone",
formWarningZone);
        }

    }

    void onValidateFromFormWarning() throws IllegalAccessException,
InvocationTargetException {
        //Generate Serverside Validation Errors
        if(triggerValidation && warningEvent) {
            formWarning.recordError("warning validation test");
        } else if(triggerValidation && notificationEvent) {
            formWarning.recordError("notification validation test");
        }

        //Return proper warning block
        if(formWarning.getHasErrors()) {
            hasValidationErrors = true;
            activeWarningBlock = warningEvent ? warningBlock :
notificationBlock;
        }

        //Produce Notification Warning
        if(formWarning.isValid() && triggerNotification) {
            formWarning.recordError("tigger notification block");
            activeWarningBlock = notificationBlock;
        }

        //Render formWarning zone if validation or warnings exist
        if(formWarning.getHasErrors()) {
            hasWarnings = true;
            ajaxResponseRenderer.addRender("formWarningZone",
formWarningZone);
        }

    }

    @CommitAfter
    Object onSuccess() throws IllegalAccessException,
InvocationTargetException {
        session.saveOrUpdate(computer);
        return linkSource.createPageRenderLinkWithContext(Warning.class,
computer.getId());
    }

    public void onWarningEvent() {
        this.warningEvent = true;
    }

    public void onNotificationEvent() {
        this.notificationEvent = true;
    }

}

Computer.class

public class Computer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private String name;

    getters/setters
}

Warning.tml

<html t:type="layout" title="Warning Demo" xmlns:t="
http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
xmlns:p="tapestry:parameter">
    <div t:type="zone" t:id="formZone" id="formZone">
        <t:form t:id="form" zone="formZone">
            <t:if test="hasValidationErrors"><t:errors/></t:if>
            <t:checkbox value="triggerWarning"/> Trigger Warning<br/>
            <t:delegate to="block:formBlock"/>
            <t:submit t:id="save" value="save"/>
        </t:form>
    </div>

    <div t:type="zone" t:id="formWarningZone" id="formWarningZone">
        <t:if test="hasWarnings">
            <t:form t:id="formWarning" zone="formWarningZone">
                <t:if test="hasValidationErrors"><t:errors/></t:if>
                <t:delegate to="activeWarningBlock"/>
            </t:form>
        </t:if>
    </div>

    <t:block t:id="warningBlock">
        Review Warnings<br/>
        <t:checkbox value="triggerValidation"/> Trigger Validation<br/>
        <t:checkbox value="triggerNotification"/> Trigger Notification<br/>
        <div style="display:none">
            <t:delegate to="block:formBlock"/>
        </div>
        <t:submit t:id="warningAccect" value="Accept Warning"
t:event="warningEvent"/>
    </t:block>

    <t:block t:id="notificationBlock">
        Review Notifications<br/>
        <t:checkbox value="triggerValidation"/> Trigger Validation<br/>
        <div style="display:none">
            <t:delegate to="block:formBlock"/>
        </div>
        <t:submit t:id="notificationAccept" value="Accept Notification"
t:event="notificationEvent"/>
    </t:block>

    <t:block t:id="formBlock">
        <div class="form-group">
            <t:Label class="control-label" for="computer"/>
            <t:TextField t:id="computer" value="computer.name"/>
        </div>
    </t:block>

</html>




On Mon, Mar 17, 2014 at 4:46 PM, Lance Java <lance.j...@googlemail.com>wrote:

> > I believe Lance's #2 is only true for 5.4
> Yes, good point. George has mentioned previously that he's using 5.4 so
> should be OK.
>



-- 
George Christman
www.CarDaddy.com
P.O. Box 735
Johnstown, New York

Reply via email to