IConfiguration does not contain a definition for 'GetOptions' - configuration

I have an error calling one of the methods of the configuration item 'IConfiguration' does not contain a definition for 'GetOptions' and no accessible extension method 'GetOptions' accepting a first argument of type 'IConfiguration' could be found (are you missing a using directive or an assembly reference?)
This is the part where the error is showing :
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
public static class Extensions
{
private static bool _initialized;
....
....
private static JaegerOptions GetJaegerOptions(IServiceCollection services)
{
using (var serviceProvider = services.BuildServiceProvider())
{
var configuration = serviceProvider.GetService<IConfiguration>();
services.Configure<JaegerOptions>(configuration.GetSection("jaeger"));
return configuration.GetOptions<JaegerOptions>("jaeger");
}
}
}
}
and the related class JaegerOptions.cs :
public class JaegerOptions
{
public bool Enabled { get; set; }
public string ServiceName { get; set; }
public string UdpHost { get; set; }
public int UdpPort { get; set; }
public int MaxPacketSize { get; set; }
public string Sampler { get; set; }
public double MaxTracesPerSecond { get; set; } = 5;
public double SamplingRate { get; set; } = 0.2;
}
I have already installed Microsoft.Extensions.Configuration.Binder but I am still getting same error. Both Microsoft.Extensions.Configuration and Microsoft.Extensions.Configuration.Binder are installed.
My project looks like this :
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Jaeger" Version="1.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="Nancy" Version="2.0.0" />
<PackageReference Include="OpenTracing.Contrib.NetCore" Version="0.5.0" />
<PackageReference Include="Oracle.EntityFrameworkCore" Version="5.21.1" />
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.1" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="5.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="System.Runtime.Serialization.Json" Version="4.3.0" />
</ItemGroup>
</Project>
What am I missing ?

Related

java EE Hibernate List many to many configure error

I am making a java ee web application. I have User and Permission classes and User class have List that types of Permission. When hibernate gets user object form database, i want to get permissions of user from user_permission table ,too. User and Permission has many-to-many relation. I am using Hibernate 5.4.1 . When SessionFactory configurating i get this error:
java.lang.NullPointerException
org.hibernate.boot.model.source.internal.hbm.ModelBinder$AbstractPluralAttributeSecondPass.bindCollectionElement(ModelBinder.java:3557)
org.hibernate.boot.model.source.internal.hbm.ModelBinder$AbstractPluralAttributeSecondPass.doSecondPass(ModelBinder.java:3136)
org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1684)
org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1652)
org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:286)
org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:473)
org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:84)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:689)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
my User class:
public class User
{
private int id;
private String name;
private String password;
private List<Permission> permissions;
public User(){}
public User(String name,String password)
{
this.name=name;
this.password=password;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name=name;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password=password;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id=id;
}
public void clearPermissions()
{
permissions.clear();
}
public boolean hasPermission(Permission permission)
{
return permissions.contains(permission);
}
public void addPermission(Permission permission)
{
permissions.add(permission);
}
public void deletePermission(Permission permission)
{
permissions.remove(permission);
}
public List<Permission> getPermissions()
{
return permissions;
}
public void setPermissions(List<Permission> permissions)
{
this.permissions = permissions;
}
}
user class mapping :
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping>
<class name="model.User" table="user">
<id name="id" type="int" column="id">
<generator class="identity"/>
</id>
<property name="name" column="name" type="string"/>
<property name="password" column="password" type="string"/>
<list name="permissions" table="user_permission" lazy="false">
<key column="user_id"/>
<index column="id"/>
<many-to-many class="Permission" column="permission_id"/>
</list>
</class>
</hibernate-mapping>
my Permission class:
public class Permission
{
private int id;
private String name;
public Permission() {}
public Permission(int id, String name)
{
this.id=id;
this.name=name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name=name;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id=id;
}
public boolean equals(Object obj)
{
return ((Permission)obj).id==id;
}
}
Permission class mapping :
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping>
<class name="model.Permission" table="permission">
<id name="id" type="int" column="id">
<generator class="identity"/>
</id>
<property name="name" column="name" type="string"/>
</class>
</hibernate-mapping>
There is a missing packageName in many to many mapping. Change it from Permission to model.Permission. It should solve the problem. Below is the sippet
<class name="model.User" table="user">
<id name="id" type="int" column="id">
<generator class="identity"/>
</id>
<property name="name" column="name" type="string"/>
<property name="password" column="password" type="string"/>
<list name="permissions" table="user_permission" lazy="false">
<key column="user_id"/>
<index column="id"/>
<many-to-many class="model.Permission" column="permission_id"/>
</list>
</class> </hibernate-mapping>

compositeComponent with primefaces datatable selection does not return object

I've made a composite component using primefaces 5.1. I want a dialog to show up, you can input a name and search the db. Then you can select one entry and the dialog closes again. My Problem ist that the selection in the dataTable always returns null...
this is the composite:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:rich="http://richfaces.org/rich"
xmlns:a4j="http://richfaces.org/a4j" xmlns:p="http://primefaces.org/ui"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface componentType="searchCustomer">
<composite:attribute name="customerCache" required="true"
type="com.hji.tis.ui.cache.customer.CustomerCache" />
<composite:attribute name="useExtendedCustomersOnly" default="false" />
</composite:interface>
<composite:implementation>
<p:commandLink styleClass="ui-icon ui-icon-search"
id="searchCustomerIcon" onclick="PF('searchCustomerDialog').show();" />
<p:tooltip for="searchCustomerIcon"
value="#{msgs['request.searchByCustomerNumber']}" />
<p:dialog header="#{msgs['general.searchCustomer']}" resizable="false"
draggable="false" width="500" height="450" modal="true"
appendTo="#(body)" widgetVar="searchCustomerDialog">
<p:panel id="searchCustomerDialogContent" style="width:100%">
<p:panelGrid style="width:480px">
<p:row>
<p:column style="width:60px">
<p:graphicImage value="/resources/images/userSearch.png"
width="50" height="50" />
</p:column>
<p:column style="width:100px">
<p:outputLabel value="#{msgs['general.customerName']}" />
</p:column>
<p:column style="width:160px">
<p:inputText value="#{cc.custSearch_name}"
id="input_searchCustomerName" />
</p:column>
<p:column>
<p:commandLink styleClass="ui-icon ui-icon-search"
action="#{cc.findCustomersByName}"
update="searchCustomerDialogContent"
process="#this, input_searchCustomerName" partialSubmit="true" />
</p:column>
</p:row>
<p:row>
<p:column colspan="4">
<p:dataTable value="#{cc.filteredCustomers}" var="customer"
scrollable="true" scrollHeight="300"
emptyMessage="#{msgs['general.noSelection']}"
selection="#{cc.selectedCustomer}" rowKey="#{customer.id}"
selectionMode="single">
<p:ajax event="rowSelect" process="#this" />
<p:column headerText="#{msgs['general.customerName']}"
styleClass="unmarkable">
<h:outputText value="#{customer.fullName}"
rendered="#{!customer.extendedCustomer}" />
<h:outputText value="#{customer.name}"
rendered="#{customer.extendedCustomer}" />
</p:column>
<p:column headerText="#{msgs['general.address']}"
styleClass="unmarkable">
<h:outputText
value="#{customer.homeAddress.address.country}, #{customer.homeAddress.address.zipCode} #{customer.homeAddress.address.city}, #{customer.homeAddress.address.street} #{customer.homeAddress.address.houseNr}" />
</p:column>
</p:dataTable>
</p:column>
</p:row>
<p:row>
<p:column colspan="4">
<p:commandButton icon="ui-icon-check" style="float:right"
action="#{cc.test}" process="#this, searchCustomerDialogContent"
partialSubmit="true" />
</p:column>
</p:row>
</p:panelGrid>
</p:panel>
</p:dialog>
</composite:implementation>
</html>
and this is the Faces Component:
package com.hji.tis.ui.util.customComponents;
import java.io.IOException;
import java.util.List;
import javax.faces.component.FacesComponent;
import javax.faces.component.UINamingContainer;
import javax.faces.context.FacesContext;
import lombok.Getter;
import lombok.Setter;
import org.primefaces.event.SelectEvent;
import com.hji.tis.domain.model.customer.Customer;
import com.hji.tis.ui.cache.customer.CustomerCache;
/**
* NamingContainer for the custom element searchCustomer.
*
* #author mayra
*
*/
#FacesComponent("searchCustomer")
public class SearchCustomer extends UINamingContainer {
private final String CUSTOMER_CACHE = "customerCache";
private final String USER_EXTENDED_CUSTOMERS_ONLY = "useExtendedCustomersOnly";
private final String FILTERED_CUSTOMERS = "filteredCustomers";
private final String SELECTED_CUSTOMER = "selectedCustomer";
#Getter
#Setter
private String custSearch_name;
#Getter
#Setter
private Customer custSearch_selectedCustomer;
#Override
public void encodeBegin(FacesContext facesContext) throws IOException {
initCustomerCache();
initUseExtendedCustomersOnly();
super.encodeBegin(facesContext);
}
public void onRowSelect(SelectEvent event) {
System.out.println(((Customer) (event.getObject())).getFullName());
}
/**
* finds the customer by the name set to the _Name field. Decides wether
* only private Customers should be returned or extended.
*/
public void findCustomersByName() {
this.custSearch_selectedCustomer = null;
if (useExtendedCustomersOnly()) {
setFilteredCustomers(getCustomerCache().findExtendedCustomerEntriesByName(custSearch_name));
} else {
setFilteredCustomers(getCustomerCache().findAllCustomerEntriesByName(custSearch_name));
}
}
private boolean useExtendedCustomersOnly() {
return getStateHelperValue(USER_EXTENDED_CUSTOMERS_ONLY);
}
private CustomerCache getCustomerCache() {
return getStateHelperValue(CUSTOMER_CACHE);
}
public Customer getSelectedCustomer() {
return (Customer) this.getStateHelper().get(SELECTED_CUSTOMER);
}
public void setSelectedCustomer(Customer customer) {
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!HERE THE CUSTOMER IS ALWAYS NULL
this.getStateHelper().put(SELECTED_CUSTOMER, customer);
}
public List<Customer> getFilteredCustomers() {
return (List<Customer>) this.getStateHelper().get(FILTERED_CUSTOMERS);
}
private void setFilteredCustomers(List<Customer> customers) {
this.getStateHelper().put(FILTERED_CUSTOMERS, customers);
}
/**
* stores the customerCache in the state helper.
*/
private void initCustomerCache() {
CustomerCache customerCache = getAttributeValue(CUSTOMER_CACHE);
this.getStateHelper().put(CUSTOMER_CACHE, customerCache);
}
private void initUseExtendedCustomersOnly() {
String value = getAttributeValue(USER_EXTENDED_CUSTOMERS_ONLY);
boolean boolValue = false;
if (value.equalsIgnoreCase("TRUE")) {
boolValue = true;
} else {
boolValue = false;
}
this.getStateHelper().put(USER_EXTENDED_CUSTOMERS_ONLY, boolValue);
}
/**
* Return specified attribute value or otherwise the specified default if
* it's null.
*/
#SuppressWarnings("unchecked")
private <T> T getAttributeValue(String key) {
return (T) this.getAttributes().get(key);
}
#SuppressWarnings("unchecked")
private <T> T getStateHelperValue(String key) {
return (T) this.getStateHelper().get(key);
}
}
Maybe someone knows the reason why?
Thanks!

Send data primefaces to another page

I´m newbie in primefaces, i have done a datatable and i show it in index.xhtml i have got a button when i push, it show the selection datatable (dialog) but i don´t know how to send the select datatable to another page. Sorry I´m learning english, thx.
index.xhtml
<p:dataTable id="singleDT" var="emp" value="#{empresaBean.getEmpresaList()}" selectionMode="single"
scrollable="true" scrollHeight="400" selection="#{empresaBean.selectedEmpresa}" rowKey="#{emp.CLAVE}">
<f:facet name="header">
Lista de Empresas
</f:facet>
<p:column headerText="Id">
<h:outputText value="#{emp.CLAVE}" />
</p:column>
<p:column headerText="Nombre Empresa">
<h:outputText value="#{emp.NOMBRE}" />
</p:column>
<p:column headerText="AÑO">
<h:outputText value="#{emp.EJERCICIO}" />
</p:column>
<f:facet name="footer">
<p:button outcome="/pages/menu/menuPrincipal.xhtml" value="Seleccionar" title="Ir Menu">
</p:button>
<p:commandButton value="View" image="ui-icon ui-icon-search"
oncomplete="empresaDialog.show()"/>
</f:facet>
</p:dataTable>
<p:dialog header="Car Detail" widgetVar="empresaDialog" resizable="false"
width="200" showEffect="clip" hideEffect="fold">
<h:panelGrid id="display" columns="2" cellpadding="4">
<h:outputText value="Clave:" />
<h:outputText value="#{empresaBean.selectedEmpresa.CLAVE}" />
<h:outputText value="Año:" />
<h:outputText value="#{empresaBean.selectedEmpresa.NOMBRE}" />
<h:outputText value="Año:" />
<h:outputText value="#{empresaBean.selectedEmpresa.EJERCICIO}" />
</h:panelGrid>
</p:dialog>
</h:form>
</h:body>
EmpresaBean
#ManagedBean(name="empresaBean")
#Scope
#Component
public class EmpresaBean {
#Autowired
private EmpresaService empresaService;
private Empresa empresa;
private Empresa selectedEmpresa;
private List<Empresa> empresasSmall;
public EmpresaService getEmpresaService() {
return empresaService;
}
public Empresa getSelectedEmpresa() {
return selectedEmpresa;
}
public void setSelectedEmpresa(Empresa selectedEmpresa) {
this.selectedEmpresa = selectedEmpresa;
}
public void setEmpresaService(EmpresaService empresaService) {
this.empresaService = empresaService;
}
public EmpresaBean(){
empresa = new Empresa();
// empresasSmall=new ArrayList<Empresa>();
// list.add(new Empresa(getEmpresaList());
}
/*
public void addEmpresa(){
empresaService.add(empresa);
empresa = new Empresa();
} */
public List<Empresa> getEmpresaList(){
return empresaService.getAll();
}
public Empresa getEmpresa() {
return empresa;
}
public void setEmpresa(Empresa empresa) {
this.empresa = empresa;
}
}
You can not send html to another page (dialog). You should push only data, which will be used on another page.
To push data from datatable (which is considered to be a List) you should use #ManagedProperty annotation.
Assuming you have index page:
#ManagedBean(name="index")
#SessionScoped
public class IndexPage implements Serializable {
private List<String> values;
//getter and setter
}
and you have another page, where you would like to use that list:
#ManagedBean(name="nextPage")
#SessionScoped
public class AnotherPage implements Serializable {
#ManagedProperty(value="#{index.values}")
private List<String> forwardedList; //list with values form index page
//getter and setter
}
http://www.mkyong.com/jsf2/injecting-managed-beans-in-jsf-2-0/
UPD: if you would like to forward a row, but not a list, you should just make minor change in AnotherPage class:
#ManagedBean(name="nextPage")
#SessionScoped
public class AnotherPage implements Serializable {
#ManagedProperty(value="{empresaBean.selectedEmpresa}")
private Empresa selectedValue; //value from selected row in your table
//getter and setter
}

Error executing JSON based Restful WCF Service

I am trying to write a json based restful WCF service. When i execute it using RestSharp i get a null response with the following Error in the ErrorException and the ErrorMessage.
Data at the root level is invalid. Line 1, position 1.
Status Code is BadRequest
The data object is created as
[DataContract]
public class User
{
[DataMember]
public string first_name { get; set; }
[DataMember]
public string last_name { get; set; }
[DataMember]
public string email_address { get; set; }
[DataMember]
public List<UserAddress> Address; //do not serialize this in the data contract
}
[DataContract]
public class UserAddress
{
[DataMember]
public string line_1_address { get; set; }
[DataMember]
public string state { get; set; }
[DataMember]
public string PostalArea { get; set; }
}
The service code is
[ServiceContract]
public interface IUserService
{
[OperationContract]
User AddUser(User user);
}
public class UserService : IUserService
{
[WebInvoke(Method = "PUT",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "User/")]
public User AddUser(User user)
{
return new User();
}
}
The service is hosted in a Web App.
I have a c# client based on RestSharp
static void Main(string[] args)
{
User u = new User();
u.first_name = "testFirst";
u.last_name = "testLast";
UserAddress ua = new UserAddress();
ua.line_1_address = "line 1";
ua.PostalArea = "08648";
ua.state = "NJ";
u.Address = new List<UserAddress>();
u.Address.Add(ua);
RestSharp.RestClient client = new RestSharp.RestClient("http://localhost/TestWCHHost/User.svc");
var request = new RestRequest(String.Format("User/"), Method.PUT);
request.RequestFormat = DataFormat.Json;
request.AddObject(u);
var response = client.Execute<User>(request);
}
The web config changes are as
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<!-- User Service -->
<service name="TestService.UserService" behaviorConfiguration="serviceBehavior">
<endpoint address="" binding="webHttpBinding" contract="TestService.IUserService" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Unable to figure whats going on. Any clues.

How to redirect primefaces wizard to first tab after submit on last tab

I am using primefaces 3.2. I have prepared wizard which insert user information on same page in datatable. Wizard get information tab by tab and submitted on confirmation tab. Also it will reflected on same page on datatable. It is working fine. Now I need to update multiple users. For that I have to navigate wizard from submit button to first tab.
Any help will be appreciated.
My code is as below
wizard.xhtml
<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>Wizard Example</title>
<script type="text/javascript" >
function resetWizard() {
wiz.loadStep(wiz.cfg.steps[0], true);
}
</script>
</h:head>
<h:body>
<h:form id="form">
<!-- <p:growl id="growl" sticky="true" showDetail="true"/> -->
<p:growl redisplay="false" life="3000" id="mymessage" autoUpdate="true"/>
<p:wizard widgetVar="wiz"
flowListener="#{userWizard.onFlowProcess}" showNavBar="true" >
<p:tab id="personal" title="Personal" >
<p:panel header="Personal Details">
<h:messages errorClass="error"/>
<h:panelGrid columns="2" columnClasses="label, value" styleClass="grid">
<h:outputText value="Firstname: *" />
<p:inputText required="true" label="Firstname"
value="#{userWizard.user.firstname}" />
<h:outputText value="Lastname: *" />
<p:inputText required="true" label="Lastname"
value="#{userWizard.user.lastname}" />
<h:outputText value="Age: " />
<p:inputText value="#{userWizard.user.age}" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="address" title="Address" >
<p:panel header="Adress Details">
<h:messages errorClass="error"/>
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="Street: " />
<p:inputText value="#{userWizard.user.street}" />
<h:outputText value="Postal Code: " />
<p:inputText value="#{userWizard.user.postalCode}" />
<h:outputText value="City: " />
<p:inputText value="#{userWizard.user.city}" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="contact" title="Contact" >
<p:panel header="Contact Information">
<h:messages errorClass="error"/>
<h:panelGrid columns="2" columnClasses="label, value">
<h:outputText value="Email: *" />
<p:inputText required="true" label="Email"
value="#{userWizard.user.email}" />
<h:outputText value="Phone: " />
<p:inputText value="#{userWizard.user.phone}"/>
<h:outputText value="Additional Info: " />
<p:inputText value="#{userWizard.user.info}"/>
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="confirm" title="Confirmation" >
<p:panel header="Confirmation">
<h:panelGrid id="confirmation" columns="6">
<h:outputText value="Firstname: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.firstname}" />
<h:outputText value="Lastname: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.lastname}"/>
<h:outputText value="Age: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.age}" />
<h:outputText value="Street: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.street}" />
<h:outputText value="Postal Code: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.postalCode}" />
<h:outputText value="City: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.city}" />
<h:outputText value="Email: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.email}" />
<h:outputText value="Phone " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.phone}"/>
<h:outputText value="Info: " />
<h:outputText styleClass="outputLabel"
value="#{userWizard.user.info}" />
</h:panelGrid>
<p:commandButton immediate="true" value="Submit" update="wiz"
actionListener="#{userWizard.save}" ajax="false"/>
</p:panel>
</p:tab>
</p:wizard>
<p:dataTable var="user" value="#{userWizard.userAll}" id="userList" editable="true" rowKey="#{user.firstname}" paginator="true"
rows="4" rowsPerPageTemplate="4,6" >
<p:column headerText="FirstName" style="width:125px" filterBy="#{user.firstname}" sortBy="#{user.firstname}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.firstname}" />
</f:facet>
<f:facet name="input">
<h:outputText value="#{user.firstname}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="LastName" style="width:125px" filterBy="#{user.lastname}" sortBy="#{user.lastname}" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.lastname}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.lastname}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Age" style="width:125px" filterBy="#{user.age}" sortBy="#{user.age}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{user.age}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{user.age}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:50px">
<p:rowEditor />
</p:column>
<p:ajax event="rowEdit" listener="#{userWizard.editRowListner}" update=":form:mymessage"/>
</p:dataTable>
</h:form>
</h:body>
UserWizard.java
package com.test;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.faces.bean.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.primefaces.event.FlowEvent;
import org.primefaces.event.RowEditEvent;
#ManagedBean
#SessionScoped
public class UserWizard {
private User user = new User();
private boolean skip;
private List<User> userAll = new ArrayList<User>();
private static Logger logger = Logger.getLogger(UserWizard.class.getName());
/*public UserWizard() {
userAll = new ArrayList<User>();
}*/
public List<User> getUserAll() {
return userAll;
}
public void setUserAll(List<User> userAll) {
this.userAll = userAll;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public void save(ActionEvent actionEvent) {
//Persist user
System.out.println("First name : " + user.getFirstname());
System.out.println("Last name : " + user.getLastname());
System.out.println("Age name : " + user.getAge());
userAll.add(user);
user = new User();
FacesMessage msg = new FacesMessage("Successful", "Welcome :" + user.getFirstname());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public boolean isSkip() {
return skip;
}
public void setSkip(boolean skip) {
this.skip = skip;
}
public String onFlowProcess(FlowEvent event) {
logger.info("Current wizard step:" + event.getOldStep());
logger.info("Next step:" + event.getNewStep());
System.out.println("First name : " + user.getFirstname());
System.out.println("Last name : " + user.getLastname());
System.out.println("Age name : " + user.getAge());
if (skip) {
skip = false; //reset in case user goes back
return "confirm";
} else {
return event.getNewStep();
}
}
public void editRowListner(RowEditEvent rowEditEvent) {
try {
User updatedUser = (User) rowEditEvent.getObject();
System.out.println("User First Name: " + updatedUser.getFirstname());
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Update called", "updated by user"));
} catch (Exception ex) {
ex.getMessage();
}
}
}
User.java
public class User {
private String firstname;
private String lastname;
private Integer age;
private String street;
private String city;
private String postalCode;
private String info;
private String email;
private String phone;
public User(String firstname, String lastname, Integer age, String street, String city, String postalCode, String info, String email, String phone) {
this.firstname = firstname;
this.lastname = lastname;
this.age = age;
this.street = street;
this.city = city;
this.postalCode = postalCode;
this.info = info;
this.email = email;
this.phone = phone;
}
public User() {
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getInfo() {
return info;
}
public void setInfo(String info) {
this.info = info;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
In the wizard.xhtml page change your submit button to :
<p:commandButton immediate="true" value="Submit" update="#parent,:form:userList" actionListener="#{userWizard.save}" oncomplete="wiz.loadStep (wiz.cfg.steps [0], true)"/>
you can also do it from Java code as follow:
Wizard wizard = (Wizard) FacesContext.getCurrentInstance().getViewRoot().findComponent("importForm:wizardId");
wizard.setStep(STEP1);
RequestContext.getCurrentInstance().update("importForm");
In primefaces 5 you can't call widgetVar directly, you need to call it like PF('widgetVar') so you can do it like this :
<p:commandButton value="Submit" actionListener="#{userWizard.save}" oncomplete="PF('wiz').loadStep('tabId',false)" />