Just want to share my solution. I don't like to do
"onchange='this.form.submit()'" on t:select input, because that can trigger
early validation errors before the user is actually ready to submit the
form. Also, by default the first element in t:select is selected, onchange
only triggers when the user actually changes the selection. If the user is
fine with the default selection, onchange event would never trigger, but I
still need to use it as a criteria. I finally reach the following solution
that I'm happy with.
NewUser.java
==========
public class NewUser {
...
@Persist
private String serverRegionField;
private String serverNameField;
void onActionFromServerRegionFieldLink(String context) {
setServerRegionField(context);
}
String[] onProvideCompletionsFromServerNameField(String input) {
Dao dao = Dao.getRequestInstance(requestGlobals);
Query query =
dao.createNamedQuery("findServerNameLikeForRegion");
query.setParameter("name", input + "%");
query.setParameter("region", serverRegionField);
List<String> serverNameList = (List<String>)
query.getResultList();
return serverNameList.toArray(new
String[serverNameList.size()]);
}
...
}
NewUser.tml
=========
<div id="newUserView" class="mainpost">
<t:form t:id="newUserForm">
<t:errors />
<div class="t-beaneditor">
<div class="t-beaneditor">
<div class="t-beaneditor-row">
<t:label for="emailField" />
<t:textfield
t:id="emailField" t:validate="required,regexp" size="30"/>
</div>
<div class="t-beaneditor-row">
<t:actionlink
t:id="serverRegionFieldLink"/>
<t:label
for="serverRegionField" />
<t:select
t:id="serverRegionField" t:model="literal:US,EU"
t:validate="required" />
</div>
<div class="t-beaneditor-row">
<t:label for="serverNameField"
/>
<t:textfield
t:id="serverNameField" t:mixins="autocomplete"
t:validate="required" size="30"
onfocus="javascript:new
Ajax.Request(document.getElementById('serverRegionFieldLink').href + '/' +
document.getElementById('serverRegionField').value)"/>
</div>
<div class="t-beaneditor-row">
<t:submit t:id="registerButton"
value="Register"/>
</div>
</div>
</div>
</t:form>
</div>
--
View this message in context:
http://www.nabble.com/Autocomplete-Using-Selection-as-Criteria-tp15821577p15841150.html
Sent from the Tapestry - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]