Dialog Framework Primefaces - não consigo ter resposta de lista
20/04/2020
0
Olá, pessoal.
Estou a precisar de utilizar o Dialog Framework do Primefaces para ter uma lista e em seguida selecionar um artigo. Vi no Show case do Primefaces o exemplo e tentei fazer, mas não consigo ter resposta da seleção. Faz a lista mas não obtenho nenhuma resposta. Alguém me consegue ajudar? Aqui tem o meu código:
Esta é o meu faces-config:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<action-listener>
org.primefaces.application.DialogActionListener
</action-listener>
<navigation-handler>
org.primefaces.application.DialogNavigationHandler
</navigation-handler>
<view-handler>
org.primefaces.application.DialogViewHandler
</view-handler>
</application>
</faces-config>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:o="http://omnifaces.org/ui">
<h:head>
<title>Host</title>
</h:head>
<h:body>
<h:form>
<p:commandButton value="View" icon="pi pi-home" action="#{hostBean.view}" >
<p:ajax event="dialogReturn" listener="#{hostBean.handleReturn}"/>
</p:commandButton>
<p:commandButton value="Options" icon="pi pi-home" action="#{hostBean.viewCarsCustomized}" />
</h:form>
</h:body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Cars</title>
<f:metadata>
<f:event listener="#{dfCarsView.init()}"
type="preRenderView" />
</f:metadata>
</h:head>
<h:body>
<p:dataTable var="car" value="#{dfCarsView.cars}">
<p:column headerText="Id">
<h:outputText value="#{car.randomId}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.randomYear}" />
</p:column>
<p:column headerText="Brand">
<h:outputText value="#{car.randomBrand}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.randomColor}" />
</p:column>
<p:column headerText="Select">
<p:commandButton icon="ui-icon-search" action="#{dfCarsView.selectCarFromDialog(car)}" />
</p:column>
</p:dataTable>
</h:body>
</html>
Estou a precisar de utilizar o Dialog Framework do Primefaces para ter uma lista e em seguida selecionar um artigo. Vi no Show case do Primefaces o exemplo e tentei fazer, mas não consigo ter resposta da seleção. Faz a lista mas não obtenho nenhuma resposta. Alguém me consegue ajudar? Aqui tem o meu código:
Esta é o meu faces-config:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<action-listener>
org.primefaces.application.DialogActionListener
</action-listener>
<navigation-handler>
org.primefaces.application.DialogNavigationHandler
</navigation-handler>
<view-handler>
org.primefaces.application.DialogViewHandler
</view-handler>
</application>
</faces-config>
import java.io.Serializable; import java.util.List; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import org.primefaces.PrimeFaces; @Named("dfCarsView") @ViewScoped public class DFCarsView implements Serializable { private static final long serialVersionUID = 1L; private List<Car> cars; @Inject private CarService service; public void init() { cars = service.createCars(9); } public List<Car> getCars() { return cars; } public void setService(CarService service) { this.service = service; } public void selectCarFromDialog(Car car) { PrimeFaces.current().dialog().closeDynamic(car); } }
package com.melshi.controller; import javax.faces.application.FacesMessage; import javax.faces.bean.RequestScoped; import javax.faces.context.FacesContext; import javax.faces.view.ViewScoped; import javax.inject.Named; import org.primefaces.PrimeFaces; import org.primefaces.event.SelectEvent; import java.io.Serializable; import java.util.HashMap; import java.util.Map; @Named @ViewScoped public class HostBean implements Serializable { private static final long serialVersionUID = 1L; public void view() { Map<String, Object> options = new HashMap<String, Object>(); options.put( "resizable", true ); options.put( "modal", true ); options.put( "draggable", true ); options.put( "headerElement", "customheader" ); PrimeFaces.current().dialog().openDynamic( "cars", options, null ); } public void viewCarsCustomized() { } public void handleReturn(SelectEvent event) { Car car=(Car) event.getObject(); FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Car Selected", "Id:" + car.getRandomId()); FacesContext.getCurrentInstance().addMessage(null, message); } public void showMessage() { FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "What we do in life", "Echoes in eternity."); PrimeFaces.current().dialog().showMessageDynamic(message); } }
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:o="http://omnifaces.org/ui">
<h:head>
<title>Host</title>
</h:head>
<h:body>
<h:form>
<p:commandButton value="View" icon="pi pi-home" action="#{hostBean.view}" >
<p:ajax event="dialogReturn" listener="#{hostBean.handleReturn}"/>
</p:commandButton>
<p:commandButton value="Options" icon="pi pi-home" action="#{hostBean.viewCarsCustomized}" />
</h:form>
</h:body>
</html>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Cars</title>
<f:metadata>
<f:event listener="#{dfCarsView.init()}"
type="preRenderView" />
</f:metadata>
</h:head>
<h:body>
<p:dataTable var="car" value="#{dfCarsView.cars}">
<p:column headerText="Id">
<h:outputText value="#{car.randomId}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.randomYear}" />
</p:column>
<p:column headerText="Brand">
<h:outputText value="#{car.randomBrand}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.randomColor}" />
</p:column>
<p:column headerText="Select">
<p:commandButton icon="ui-icon-search" action="#{dfCarsView.selectCarFromDialog(car)}" />
</p:column>
</p:dataTable>
</h:body>
</html>
António Rosário
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)