Skip to content
Browse files

Add new parameters to control singular label vs. normal (plural) label.

Add demonstration of proper ability to override field labels and even editor blocks.
  • Loading branch information...
1 parent 56c3d23 commit 7e4ef1e0c6f23ad41f13bb524db1a3c822ab430a @hlship committed
View
28 tapx-core/src/main/java/com/howardlewisship/tapx/core/components/MultipleSelect.java
@@ -30,6 +30,7 @@
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SupportsInformalParameters;
import org.apache.tapestry5.beaneditor.BeanModel;
+import org.apache.tapestry5.corelib.components.BeanEditor;
import org.apache.tapestry5.corelib.components.Palette;
import org.apache.tapestry5.corelib.components.Zone;
import org.apache.tapestry5.func.F;
@@ -53,6 +54,9 @@
* limited to editing a <em>Set</em> of values: element order is immaterial, and the UI keeps
* 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.
+ * <p>
* TODO: Rename this to SetEditor and delete the current SetEditor.
*/
@Import(stack = "tapx-core")
@@ -96,6 +100,14 @@
@Parameter(defaultPrefix = BindingConstants.LITERAL)
private String label;
+ /**
+ * Alternate label used to represent a "single" instance of the value; this is used as part of
+ * button labels, and in the title of the modal dialog.
+ */
+ @Property
+ @Parameter(defaultPrefix = BindingConstants.LITERAL, value = "prop:label")
+ private String singularLabel;
+
@Environmental
private JavaScriptSupport jss;
@@ -113,7 +125,13 @@
private String clientId, controlName;
+ /**
+ * Parameter used to communicate a newValue instance created from the model up to the containing
+ * component. This is used when creating UI blocks as overrides to the BeanEditor's default
+ * UI blocks for the properties of the new instance.
+ */
@Property
+ @Parameter
private Object newValue;
@InjectComponent
@@ -307,20 +325,24 @@ protected void processSubmission(String name)
return result;
}
- Object onNewValue(String clientId) throws Exception
+ /**
+ * Event handler triggered from the client side. The result of this event is a partial page update response
+ * that will be used to fill in the content of the modal dialog.
+ */
+ Object onNewValue(String clientId)
{
- // Thread.sleep(5000);
-
this.clientId = clientId;
return editor;
}
+ /** Event handler triggered when the modal dialog is submitted. */
void onPrepareForSubmitFromNewValue(String clientId)
{
this.clientId = clientId;
}
+ /** Event handler when preparing to render or submit the new value form; creates a new empty instance. */
void onPrepareFromNewValue()
{
newValue = model.createEmptyInstance();
View
2 ...ore/src/main/resources/com/howardlewisship/tapx/core/components/MultipleSelect.properties
@@ -1 +1 @@
-submit-label=Add New Value
+submit-label=Add
View
2 tapx-core/src/main/resources/com/howardlewisship/tapx/core/components/MultipleSelect.tml
@@ -15,7 +15,7 @@
</div>
</div>
<div class="tx-input">
- <button>Add New ${label}</button>
+ <button>Add New ${singularLabel}</button>
</div>
<t:block id="editor">
View
3 tapx-core/src/test/java/core/demo/pages/MultiSelectDemo.java
@@ -22,6 +22,9 @@
@Persist
private Set<Person> selectedValues;
+ @Property
+ private Person newPerson;
+
void setupRender()
{
if (selectedValues == null)
View
1 tapx-core/src/test/resources/core/demo/pages/MultiSelectDemo.properties
@@ -0,0 +1 @@
+email-label=E-Mail Address
View
8 tapx-core/src/test/resources/core/demo/pages/MultiSelectDemo.tml
@@ -4,7 +4,13 @@
<t:label for="people"/>
- <tx:multipleselect t:id="people" values="selectedValues" model="model"/>
+ <tx:multipleselect t:id="people" newValue="newPerson" values="selectedValues" model="model"
+ singularLabel="Person">
+ <p:lastName>
+ <label for="lastName">Last Name (Sur Name)</label>
+ <t:textfield t:id="lastName" value="newPerson.lastName"/>
+ </p:lastName>
+ </tx:multipleselect>
<br clear="both"/>

0 comments on commit 7e4ef1e

Please sign in to comment.
Something went wrong with that request. Please try again.