Skip to content

Commit

Permalink
Add new parameters to control singular label vs. normal (plural) label.
Browse files Browse the repository at this point in the history
Add demonstration of proper ability to override field labels and even editor blocks.
  • Loading branch information
hlship committed Mar 25, 2011
1 parent 56c3d23 commit 7e4ef1e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand Down Expand Up @@ -96,6 +100,14 @@ public class MultipleSelect implements Field
@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;

Expand All @@ -113,7 +125,13 @@ public class MultipleSelect implements Field

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
Expand Down Expand Up @@ -307,20 +325,24 @@ private List<String> toStrings(JSONArray values)
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();
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
submit-label=Add New Value
submit-label=Add
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
3 changes: 3 additions & 0 deletions tapx-core/src/test/java/core/demo/pages/MultiSelectDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public class MultiSelectDemo
@Persist
private Set<Person> selectedValues;

@Property
private Person newPerson;

void setupRender()
{
if (selectedValues == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
email-label=E-Mail Address
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>

Expand Down

0 comments on commit 7e4ef1e

Please sign in to comment.