Skip to content

Instantly share code, notes, and snippets.

@mhautman

mhautman/java Secret

Last active April 27, 2016 12:29
Show Gist options
  • Save mhautman/d144d9bf107a27efe83fe97ca188a460 to your computer and use it in GitHub Desktop.
Save mhautman/d144d9bf107a27efe83fe97ca188a460 to your computer and use it in GitHub Desktop.
public class SearchStreet {
private static final Logger LOGGER = LoggerFactory.getLogger(SearchStreet.class);
@Inject
private AddressService addressService;
@Persist
@Property
private String streetName;
@Persist
@Property
private String zipCode;
@Persist
@Property
private String municipalityCode;
@Property
private Street street;
@Persist
private Set<Street> streets;
private Set<Street> originalStreets;
@Inject
private Messages messages;
@Inject
private AjaxResponseRenderer ajax;
@InjectComponent
private Zone zoneGrid;
@Inject
private Request request;
private BeanModel model;
@Inject
private BeanModelSource beanModelSource;
@Inject
private ComponentResources resources;
@Inject
private JavaScriptSupport js;
@Inject
private AssetSource as;
public BeanModel getModel() {
model = beanModelSource.createDisplayModel(Street.class,
resources.getMessages());
return model;
}
public JSONObject getOptions(){
JSONObject json = new JSONObject("bJQueryUI", "true", "sDom", "TC<\"clear\">Rlfrtip");
/*
* If you want the Export mechanism, please add these lines
* JSONObject dataTable = new JSONObject();
* dataTable.put("sSwfPath",
* as.getContextAsset("dataTables/TableTools/media/swf/copy_csv_xls_pdf.swf", null).toClientURL());
* json.put("oTableTools", dataTable);
*/
return json;
}
void onSuccess() {
LOGGER.debug(String.format("Called SearchStreet with following parameters: %s %s %s", streetName, zipCode, municipalityCode));
Set<Street> streets = new HashSet<Street>();
if (zipCode != null && !zipCode.equals("")) {
List<Street> streetsByZip = addressService.getStreetsByZip(zipCode);
if (streetsByZip != null || !streetsByZip.isEmpty()) {
streets.addAll(streetsByZip);
}
}
if (municipalityCode != null && !municipalityCode.equals("")) {
List<Street> streetsByMunicipality = addressService.getStreetsByMunicipality(municipalityCode);
if (streetsByMunicipality != null || !streetsByMunicipality.isEmpty()) {
streets.addAll(streetsByMunicipality);
}
}
setStreets(streets);
originalStreets = streets;
ajax.addRender(zoneGrid);
}
public Set<Street> getStreets() {
return streets;
}
public void setStreets(Set<Street> streets) {
this.streets = streets;
}
}
<html t:type="layout" title="Portal - Upload codes"
t:sidebarTitle="Framework Version"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd"
xmlns:p="tapestry:parameter"
xmlns:tapcom="tapestry-library:tapcom"
xmlns:code="tapestry-library:code"
xmlns:stitch="tapestry-library:stitch"
>
<!--xmlns:atmos="tapestry-library:atmos"-->
<!-- Most of the page content, including <head>, <body>, etc. tags, comes from Layout.tml -->
<p:headerMenu>
<t:zone t:id="navbarZone" id="navbarZone" t:update="show">
<ul class="nav navbar-nav">
<li class="active"><t:pagelink page="address/SearchStreet">${message:menu_search_street}</t:pagelink></li>
<li><t:pagelink page="address/SearchMunicipality">${message:menu_search_municipality}</t:pagelink></li>
<li><t:pagelink page="address/ManageException">${message:menu_manage_exception}</t:pagelink></li>
<li><t:pagelink page="address/UploadStreets">${message:menu_upload_streets}</t:pagelink></li>
</ul>
</t:zone>
</p:headerMenu>
<t:form t:zone="zoneGrid">
<t:label for="streetName"/>:
<t:textfield t:id="streetName" t:event="streetNameChanged"/>
<br/>
<t:label for="zipCode"/>:
<t:textfield t:id="zipCode" validate="regexp"/>
<br/>
<t:label for="municipalityCode"/>:
<t:textfield t:id="municipalityCode" validate="regexp"/>
<br/>
<t:submit t:id="search" value="Search"/>
<hr/>
</t:form>
<t:zone t:id="zoneGrid">
<div/>
<t:jquery.datatable t:type="grid" t:source="streets" t:row="street" t:model="model" t:options="options" t:pagerPosition="top" >[Grid here]</t:jquery.datatable>
</t:zone>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment