Skip to content

Commit

Permalink
Showcase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Aug 6, 2023
1 parent 1f67f47 commit 920ac1b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,28 @@
*/
package org.primefaces.showcase.rest;

import org.primefaces.model.rest.AutoCompleteSuggestion;
import org.primefaces.model.rest.AutoCompleteSuggestionResponse;
import org.primefaces.showcase.domain.Country;

import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import org.primefaces.model.rest.AutoCompleteSuggestion;
import org.primefaces.model.rest.AutoCompleteSuggestionResponse;
import org.primefaces.showcase.domain.Country;

import java.util.List;
import java.util.stream.Collectors;

@Named("countryRestService")
@Path("/country")
public class CountryService {
public class CountryRestService {

@Inject
org.primefaces.showcase.service.CountryService service;

@GET
@Path("/autocomplete")
@Produces({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON})
public AutoCompleteSuggestionResponse autocomplete(@QueryParam("query") String query) {
String queryLowerCase = query.toLowerCase();
List<Country> allCountrys = service.getCountries();
Expand All @@ -55,4 +53,4 @@ public AutoCompleteSuggestionResponse autocomplete(@QueryParam("query") String q
.map(t -> new AutoCompleteSuggestion(Integer.toString(t.getId()), t.getName()))
.collect(Collectors.toList()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,35 @@
*/
package org.primefaces.showcase.view.data.datatable;

import org.primefaces.PrimeFaces;
import org.primefaces.showcase.domain.Product;
import org.primefaces.showcase.service.ProductService;

import jakarta.annotation.PostConstruct;
import jakarta.faces.application.FacesMessage;
import jakarta.faces.context.FacesContext;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import org.primefaces.PrimeFaces;
import org.primefaces.showcase.domain.Product;
import org.primefaces.showcase.service.ProductService;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Named
@ViewScoped
public class CrudView implements Serializable {

@Inject
ProductService productService;
private List<Product> products;

private Product selectedProduct;

private List<Product> selectedProducts;

@Inject
ProductService productService;

@PostConstruct
public void init() {
this.products = this.productService.getClonedProducts(100);
this.selectedProducts = new ArrayList<>();
}

public List<Product> getProducts() {
Expand Down Expand Up @@ -84,8 +83,7 @@ public void saveProduct() {
this.selectedProduct.setCode(UUID.randomUUID().toString().replaceAll("-", "").substring(0, 9));
this.products.add(this.selectedProduct);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Product Added"));
}
else {
} else {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Product Updated"));
}

Expand Down
30 changes: 18 additions & 12 deletions src/main/resources/META-INF/resources/ui/input/autoComplete.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,45 @@
<div class="field col-12 md:col-4">
<p:outputLabel value="Simple" for="@next"/>
<p:autoComplete id="acSimple" value="#{autoCompleteView.txt1}"
completeMethod="#{autoCompleteView.completeText}" scrollHeight="250"/>
completeMethod="#{autoCompleteView.completeText}" scrollHeight="250"/>
</div>

<div class="field col-12 md:col-4">
<p:outputLabel value="Min Length (3)" for="@next"/>
<p:autoComplete id="acMinLength" minQueryLength="3" value="#{autoCompleteView.txt2}"
completeMethod="#{autoCompleteView.completeText}" effect="fade" scrollHeight="250"/>
completeMethod="#{autoCompleteView.completeText}" effect="fade"
scrollHeight="250"/>
</div>

<div class="field col-12 md:col-4">
<p:outputLabel value="Delay(1000)" for="@next"/>
<p:autoComplete id="acDelay" queryDelay="1000" value="#{autoCompleteView.txt3}"
completeMethod="#{autoCompleteView.completeText}" effect="blind" scrollHeight="250"/>
completeMethod="#{autoCompleteView.completeText}" effect="blind"
scrollHeight="250"/>
</div>

<div class="field col-12 md:col-4">
<p:outputLabel value="Max Results(5)" for="@next"/>
<p:autoComplete id="acMaxResults" maxResults="5" value="#{autoCompleteView.txt4}"
completeMethod="#{autoCompleteView.completeText}" scrollHeight="250"/>
completeMethod="#{autoCompleteView.completeText}" scrollHeight="250"/>
</div>

<div class="field col-12 md:col-4">
<p:outputLabel value="Force Selection" for="@next"/>
<p:autoComplete id="acForce" forceSelection="true" value="#{autoCompleteView.txt5}"
completeMethod="#{autoCompleteView.completeText}" scrollHeight="250"/>
completeMethod="#{autoCompleteView.completeText}" scrollHeight="250"/>
</div>

<div class="field col-12 md:col-4">
<p:outputLabel value="DropDown" for="@next"/>
<p:autoComplete id="dd" dropdown="true" value="#{autoCompleteView.txt6}"
completeMethod="#{autoCompleteView.completeText}" scrollHeight="250"/>
completeMethod="#{autoCompleteView.completeText}" scrollHeight="250"/>
</div>

<div class="field col-12 md:col-4">
<p:outputLabel value="Cache" for="@next"/>
<p:autoComplete id="cache" cache="true" cacheTimeout="30000" value="#{autoCompleteView.txt7}"
completeMethod="#{autoCompleteView.completeText}" scrollHeight="250"/>
completeMethod="#{autoCompleteView.completeText}" scrollHeight="250"/>
</div>

<div class="field col-12 md:col-4">
Expand Down Expand Up @@ -110,7 +112,8 @@
converter="#{countryConverter}" forceSelection="true" scrollHeight="250">
<p:column>
<span class="flag flag-#{country.code}" style="width: 30px; height: 20px"/>
<h:outputText style="vertical-align: middle; margin-left: .5rem" value="#{country.name}"/>
<h:outputText style="vertical-align: middle; margin-left: .5rem"
value="#{country.name}"/>
</p:column>
</p:autoComplete>
</div>
Expand Down Expand Up @@ -143,17 +146,18 @@
completeMethod="#{autoCompleteView.completeCountry}"
var="country" itemLabel="#{country.name}" itemValue="#{country}"
converter="#{countryConverter}" forceSelection="true"
groupBy="#{autoCompleteView.getCountryGroup(country)}" escape="false" scrollHeight="250"/>
groupBy="#{autoCompleteView.getCountryGroup(country)}" escape="false"
scrollHeight="250"/>
</div>
</div>

<h5>Multiple</h5>
<p:autoComplete id="countries" multiple="true" value="#{autoCompleteView.selectedCountries}"
completeMethod="#{autoCompleteView.completeCountry}"
var="country" itemLabel="#{country.name}" itemValue="#{country}"
converter="#{countryConverter}" forceSelection="true" scrollHeight="250">
<p:column>
<span class="flag flag-#{country.code}" style="width: 30px; height: 20px" />
<span class="flag flag-#{country.code}" style="width: 30px; height: 20px"/>
<h:outputText style="vertical-align: middle; margin-left: .5rem" value="#{country.name}"/>
</p:column>
</p:autoComplete>
Expand All @@ -162,6 +166,8 @@
</ui:define>

<ui:define name="more-source-tabs">
<p:tab title="/org/primefaces/showcase/domain/Customer.java"/>
<p:tab title="/org/primefaces/showcase/convert/CountryConverter.java"/>
<p:tab title="/org/primefaces/showcase/rest/CountryRestService.java"/>
</ui:define>
</ui:composition>
</ui:composition>

0 comments on commit 920ac1b

Please sign in to comment.