Permalink
Browse files

Handle a successful form submission of the new value form, and send t…

…he correct response to the client

Provide a placeholder for the client-side code that receives the response
  • Loading branch information...
hlship committed Mar 25, 2011
1 parent 7e4ef1e commit 74a0137b10123f9bc0ec7cdc97383cb595a24ddc
@@ -23,6 +23,8 @@
import org.apache.tapestry5.ComponentAction;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.Field;
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.Renderable;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.InjectComponent;
@@ -55,7 +57,8 @@
* the values sorted in alphabetical order by {@linkplain MultipleSelectModel#toLabel(Object) label}.
* <p>
* The UI includes an "Add" button to add a new value of the type appropriate to the set. This sets up a modal dialog on
- * the client side, and a uses a server-side {@link BeanEditor} to render the form.
+ * the client side, and a uses a server-side {@link BeanEditor} to render the form. Informal blocks bound do this
+ * component will, in turn, be provided to the BeanEditor component for use as property overrides.
* <p>
* TODO: Rename this to SetEditor and delete the current SetEditor.
*/
@@ -138,7 +141,7 @@
private Zone newValueEditor;
@Inject
- private Block editor;
+ private Block editor, success;
@Inject
private BeanModelSource beanModelSource;
@@ -348,8 +351,24 @@ void onPrepareFromNewValue()
newValue = model.createEmptyInstance();
}
- void onSuccessFromNewValue()
+ Object onSuccessFromNewValue()
{
+ // Save the new value to the database (or whatever it takes to assign a propery id to it).
+
+ model.persistNewInstance(newValue);
+
+ // Return a block that will render the content. The content will be empty,
+ // but it gives us a chance to write the necessary JS at the correct time.
+
+ return success;
+ }
+
+ void onWriteSuccessJavaScript()
+ {
+ JSONObject spec = new JSONObject("clientId", clientId, "clientValue", model.toClient(newValue), "label",
+ model.toLabel(newValue));
+
+ jss.addInitializerCall("tapxMultipleSelectNewValue", spec);
}
Object onFailureFromNewValue()
@@ -41,7 +41,11 @@
</div>
</t:form>
</t:zone>
+ </t:block>
+ <t:block id="success">
+ <t:trigger event="writeSuccessJavaScript"/>
</t:block>
+
</div>
@@ -168,7 +168,12 @@ Tapx.extendInitializer(function() {
});
}
+ function newValue(spec) {
+ Modalbox.hide();
+ }
+
return {
- tapxMultipleSelect : initializer
+ tapxMultipleSelect : initializer,
+ tapxMultipleSelectNewValue : newValue
};
});

0 comments on commit 74a0137

Please sign in to comment.