sourcforge > sotacs
 

Rich Formatted Selection Box

In this example, the textfield looks up the telephone book for matching phone numbers

  1. The number is displayed together with the name but only the number is inserted on select
  2. If more than 6 results are found in the phonebook, there is one last unselectable (informal) row, informing about how much more matching results are found in the phonebook
  3. If there is only one result, there is a different presentation including the person's age

(TelephoneBook.java, TelephoneBookEntry and phonebook.txt are some helper classes / ressource, that are used in the examples to AjaxTextField)

Note
This is static documentation. You can see this example live

Screenshots

Formatted 1 Formatted 2

Formatted.html

			
<form jwcid="@Form" listener="listener:onSubmit">
	<input type="text" jwcid="@sotacs:AjaxTextField" value="ognl:''" 
		size="10" 
		items="items:phoneBookEntries" renderer="normal,more!,singleResult" />  	
</form>

<table jwcid="@Block" >   	
	<tr jwcid="normal@Any">
		<td>{0}</td><td>{1}&nbsp;{2}</td>
	</tr>
		   
	<tr jwcid="more@Any">
		<td colspan="2"><span style="color: green;">{0} more results...</span></td>
	</tr> 
		   
	<tr jwcid="singleResult@Any">
		<td><table>
			<tr><td colspan="2" style="background: white;font-size:18pt;" 
					align="center"><b>{0}</b></td></tr>
			<tr><td>First&nbsp;Name&nbsp;&nbsp;: </td><td><b>{1}</b></td></tr>
			<tr><td>Last&nbsp;Name&nbsp;&nbsp;: </td><td><b>{2}</b></td></tr>
			<tr><td>Age&nbsp;&nbsp;: </td><td><b>{3}</b></td></tr>
		</table></td>
	</tr> 
</table>   

	    

Formatted.java

			
public abstract class Formatted extends BasePage {
  
	public void phoneBookEntries(ItemWriter writer, String prefix) {
		prefix = prefix.trim(); 
		if(prefix.length() == 0) return;
		
		List<TelephoneBookEntry> results = 
			TelephoneBook.getInstance().getEntries(TelephoneEntryField.PHONE, prefix);
		if(results.size() == 1){
			//singleResult
			TelephoneBookEntry entry = results.get(0);
			writer.writeTypedItem("singleResult",
				entry.getTelephone(), entry.getFirstName(), 
				entry.getName(), ""+entry.getAge());
			return;
		} 
		int z = 0;
		for (TelephoneBookEntry entry : results) {
			if(z++ == 6){
				writer.writeTypedItem("more",String.valueOf(results.size() - 6));
			    return;
			}
			writer.writeTypedItem("normal",entry.getTelephone(), 
				entry.getFirstName(), entry.getName());
		}
	}

}