Tapestry 5.4.1 Confirm mixin prevents onSuccessFrom... event from working

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Tapestry 5.4.1 Confirm mixin prevents onSuccessFrom... event from working

George Ludwig
Hi all,

I've got a pretty simple test project in Tap 5.4.1. Everything works as
expected, but when I add the built-in Confirm mixin to a component form,
the onSuccessFrom... event does not work. The confirm dialog works as
expected, but when I click ok, nothing happens (Other than the confirm
dialog going away). I also tried a confirm mixin from 5.3.8, but that
didn't work at all (no dialog box).

Anyone else experienced this? Thoughts?

EventEditor.tml:

<div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
xmlns:p="tapestry:parameter" class="EventEditor">


<form t:id="eventForm" >
<t:errors />
<div class="t-beaneditor">
<t:beaneditor t:id="eventEditor" t:object="event"
t:model="eventModel">
<p:name>
<t:label for="name" />
<t:textfield t:id="name" value="event.name" t:size="16"
t:mixins="TextboxHint" t:hintText="Event Name" t:hintColor="#d3d3d3" />
</p:name>
<p:defaultPhoneNumber>
<t:label for="defaultPhoneNumber" />
<t:textfield t:id="defaultPhoneNumber" value="event.defaultPhoneNumber"
t:size="16" t:mixins="TextboxHint" t:hintText="Default Phone Number"
t:hintColor="#d3d3d3" />
</p:defaultPhoneNumber>
<p:start>
<t:label for="startDate" />
<t:datefield t:id="startDate" value="event.startDate" />
</p:start>
<p:end>
<t:label for="endDate" />
<t:datefield t:id="endDate" value="event.endDate" />
</p:end>
</t:beaneditor>
</div>
<div id="buttons">
<span id="saveBtn" onClick="showMsg();">
<input fwtype="btn-primary" t:type="submit" value="Save" t:id="save" />
</span>
<span id="deleteBtn" onClick="showMsg();">
<input fwtype="btn-primary" t:type="submit" value="Delete"
t:id="delete"  t:mixins="Confirm" Confirm.message="Are you sure? This will
delete this event and any other data associated with it!"/>
</span>
</div>
</form>

</div>


EventEditor.java

package com.hightechknowledge.components;

import org.apache.tapestry5.annotations.Component;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.beaneditor.BeanModel;
import org.apache.tapestry5.corelib.components.Form;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.BeanModelSource;

import com.georgeludwigtech.CEUPDQ.data.Event;
import com.hightechknowledge.helpers.EventDisplayWrapper;
import com.hightechknowledge.services.EventDAO;

public class EventEditor {

@Inject
private EventDAO eventDAO;

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

@Property
@Parameter
private String eventId;
@Parameter
private Object returnPage;


@Inject
    private BeanModelSource beanModelSource;
@Inject
    private Messages messages;
@Property
    private BeanModel<EventDisplayWrapper>eventModel;
@Persist
private EventDisplayWrapper event; // the current event being viewed/edited
void setupRender() throws Exception {
eventModel = beanModelSource.createDisplayModel(EventDisplayWrapper.class,
messages);
eventModel.include("name", "defaultPhoneNumber", "startDate", "endDate");
if(eventId==null&&event==null) {
createNewEvent();
eventId=event.getEventId();
} else if(event==null) {
Event e=eventDAO.findById(eventId);
event=new EventDisplayWrapper(e);
}
}

public EventDisplayWrapper getEvent() {
if(event==null)
setEvent(new EventDisplayWrapper());
return event;
}

public void setEvent(EventDisplayWrapper event) {
this.event=event;
}

@Persist
private boolean save;

void onSelectedFromSave() {
save = true;
delete = false;
}

@Persist
private boolean delete;

void onSelectedFromDelete() {
delete = true;
save = false;
}
void onConfirm() {
return;
}

Object onSuccessFromEventForm() throws Exception {
if (save)
saveEvent();
else if (delete) {
deleteEvent();
return returnPage;
}
return null;
}

private void saveEvent() throws Exception {
//
Event e=new Event(event);
eventDAO.update(e);
}

private void deleteEvent() throws Exception {
//
eventDAO.delete(event);
event=null;
eventId=null;
}

private void createNewEvent() throws Exception {
//
Event e=eventDAO.createNew();
e.setName("A New Event");
e.setStart(System.currentTimeMillis());
e.setEnd(e.getStart()+86400000);
e.setDefaultPhoneNumber("123 555 1212");
eventDAO.update(e);
EventDisplayWrapper edw=new EventDisplayWrapper(e);
setEvent(edw);
}

}
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Tapestry 5.4.1 Confirm mixin prevents onSuccessFrom... event from working

George Ludwig
I did some experimenting and discovered that the confirm mixin works fine
for things like an actionlink, but it doesn't work on a form button. Is
this intended behavior? I was able to hack around it by styling an action
link to look like a button and putting it outside of my form. In this case
works ok given that the only time I need a confirm dialog is for the Delete
action.

But I can't help but wonder if it isn't supposed to work on a form button...

On Fri, Nov 11, 2016 at 11:44 AM, George Ludwig <[hidden email]>
wrote:

> Hi all,
>
> I've got a pretty simple test project in Tap 5.4.1. Everything works as
> expected, but when I add the built-in Confirm mixin to a component form,
> the onSuccessFrom... event does not work. The confirm dialog works as
> expected, but when I click ok, nothing happens (Other than the confirm
> dialog going away). I also tried a confirm mixin from 5.3.8, but that
> didn't work at all (no dialog box).
>
> Anyone else experienced this? Thoughts?
>
> EventEditor.tml:
>
> <div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
> xmlns:p="tapestry:parameter" class="EventEditor">
>
>
> <form t:id="eventForm" >
> <t:errors />
> <div class="t-beaneditor">
> <t:beaneditor t:id="eventEditor" t:object="event"
> t:model="eventModel">
> <p:name>
> <t:label for="name" />
> <t:textfield t:id="name" value="event.name" t:size="16"
> t:mixins="TextboxHint" t:hintText="Event Name" t:hintColor="#d3d3d3" />
> </p:name>
> <p:defaultPhoneNumber>
> <t:label for="defaultPhoneNumber" />
> <t:textfield t:id="defaultPhoneNumber" value="event.defaultPhoneNumber"
> t:size="16" t:mixins="TextboxHint" t:hintText="Default Phone Number"
> t:hintColor="#d3d3d3" />
> </p:defaultPhoneNumber>
> <p:start>
> <t:label for="startDate" />
> <t:datefield t:id="startDate" value="event.startDate" />
> </p:start>
> <p:end>
> <t:label for="endDate" />
> <t:datefield t:id="endDate" value="event.endDate" />
> </p:end>
> </t:beaneditor>
> </div>
> <div id="buttons">
> <span id="saveBtn" onClick="showMsg();">
> <input fwtype="btn-primary" t:type="submit" value="Save" t:id="save" />
> </span>
> <span id="deleteBtn" onClick="showMsg();">
> <input fwtype="btn-primary" t:type="submit" value="Delete"
> t:id="delete"  t:mixins="Confirm" Confirm.message="Are you sure? This will
> delete this event and any other data associated with it!"/>
> </span>
> </div>
> </form>
>
> </div>
>
>
> EventEditor.java
>
> package com.hightechknowledge.components;
>
> import org.apache.tapestry5.annotations.Component;
> import org.apache.tapestry5.annotations.Parameter;
> import org.apache.tapestry5.annotations.Persist;
> import org.apache.tapestry5.annotations.Property;
> import org.apache.tapestry5.beaneditor.BeanModel;
> import org.apache.tapestry5.corelib.components.Form;
> import org.apache.tapestry5.ioc.Messages;
> import org.apache.tapestry5.ioc.annotations.Inject;
> import org.apache.tapestry5.services.BeanModelSource;
>
> import com.georgeludwigtech.CEUPDQ.data.Event;
> import com.hightechknowledge.helpers.EventDisplayWrapper;
> import com.hightechknowledge.services.EventDAO;
>
> public class EventEditor {
>
> @Inject
> private EventDAO eventDAO;
>
> @Component(id = "eventForm")
> private Form eventForm;
>
> @Property
> @Parameter
> private String eventId;
> @Parameter
> private Object returnPage;
>
>
> @Inject
>     private BeanModelSource beanModelSource;
> @Inject
>     private Messages messages;
> @Property
>     private BeanModel<EventDisplayWrapper>eventModel;
> @Persist
> private EventDisplayWrapper event; // the current event being viewed/edited
> void setupRender() throws Exception {
> eventModel = beanModelSource.createDisplayModel(EventDisplayWrapper.class,
> messages);
> eventModel.include("name", "defaultPhoneNumber", "startDate", "endDate");
> if(eventId==null&&event==null) {
> createNewEvent();
> eventId=event.getEventId();
> } else if(event==null) {
> Event e=eventDAO.findById(eventId);
> event=new EventDisplayWrapper(e);
> }
> }
>
> public EventDisplayWrapper getEvent() {
> if(event==null)
> setEvent(new EventDisplayWrapper());
> return event;
> }
>
> public void setEvent(EventDisplayWrapper event) {
> this.event=event;
> }
>
> @Persist
> private boolean save;
>
> void onSelectedFromSave() {
> save = true;
> delete = false;
> }
>
> @Persist
> private boolean delete;
>
> void onSelectedFromDelete() {
> delete = true;
> save = false;
> }
> void onConfirm() {
> return;
> }
>
> Object onSuccessFromEventForm() throws Exception {
> if (save)
> saveEvent();
> else if (delete) {
> deleteEvent();
> return returnPage;
> }
> return null;
> }
>
> private void saveEvent() throws Exception {
> //
> Event e=new Event(event);
> eventDAO.update(e);
> }
>
> private void deleteEvent() throws Exception {
> //
> eventDAO.delete(event);
> event=null;
> eventId=null;
> }
>
> private void createNewEvent() throws Exception {
> //
> Event e=eventDAO.createNew();
> e.setName("A New Event");
> e.setStart(System.currentTimeMillis());
> e.setEnd(e.getStart()+86400000);
> e.setDefaultPhoneNumber("123 555 1212");
> eventDAO.update(e);
> EventDisplayWrapper edw=new EventDisplayWrapper(e);
> setEvent(edw);
> }
>
> }
>
>
>
>
Loading...