How to configure Tomcat to support primefaces-push (atmosphere) - primefaces

I'm working with liferay 6.2 (Tomcat 7) and Primefaces 5.0.
I tryed to execute the counter example but not worked. More precisely, I downloaded the showcase 5.0 war from primefaces site.
I read that I have to enable NIO Connector. So, according this reply, I added the connector:
<Connector connectionTimeout="20000" port="8081" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/>
But primefaces push still doesn't work.
What I have to enable in Tomcat in order to make work primefaces push?

I don't know if it is the undocumented specification or it is a bug, but the #PushEndpoint class needs #OnOpen and #OnClose function, even if they are empty.
Add these lines to the #PushEndpoint annotated class:
#OnOpen
public void onOpen( RemoteEndpoint r, EventBus e ) {
}
#OnClose
public void onClose( RemoteEndpoint r, EventBus e ) {
}
For me this was the solution.

It worked for me brother with Prifaces 5, Tomcat 7 and import atmosphere-runtime-2.2.3.jar
without any configuration in web.xml
<h:form>
<p:socket onMessage="bien" channel="/messageDetail" />
</h:form>
<script type="text/javascript">
function bien(data) {
alert("boneo");
//$('.display').html(data);
}
</script>

Related

Primefaces upgrade 8 getScriptsToExecute equivalent

Upgraded application from primefaces 5.3.6 to primefaces 8 version.What would be the equivalent of
getScriptsToExecute method from RequestContext in PrimeFaces.current() instance.
Code in bean class:
final List<String> scriptsToExecute = RequestContext.getCurrentInstance().getScriptsToExecute();
scriptsToExecute.add("script1();");
scriptsToExecute.add("script2();");
scriptsToExecute.add("script3();");
PrimeFaces.current().executeScript("script3();");
Please check the documentation next time: https://primefaces.github.io/primefaces/8_0/#/core/javaAPI and the migration guide: https://github.com/primefaces/primefaces/wiki/Migration-Guide

JSF create dynamic commandLinks

I'm working on a Maven project with Eclipse Mars.2, Java 1.8 update 102 for 64bits, JSF Mojarra 2.2.2, Primefaces 6.1, Spring 3.2.3, Hibernate 4.3 (MySQL 5.1.39) and Tomcat 7.0.53.
I have 2 xhtml pages with their respective #ViewScoped backing beans. In page A I have the following code:
<p:dataGrid var="theReg" value="#{pageA_BB.listOfReg}" columns="1" rows="5" paginator="true" paginatorPosition="bottom">
<p:commandLink value="#{theReg.title}" action="pageB?faces-redirect=true&idvalue=#{theReg.paramValue}" />
</p:dataGrid>
The above code is supposed to render some URLs with different param values. The theReg.title is a String and the theReg.paramValue is an Integer
In page B backing bean I have the following code to rescue and use the "idvalue" parameter:
#PostConstruct
public void init() {
if (FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("idvalue")!=null){
idvalue = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("idvalue"));
}else{
idvalue = 0;
}
}
The above code doesn't work because EL is not allowed inside commandLink action.
I have tried to use a f:param as described here but the use of f:params require the backing bean to be #Requestscope (other way a scope error triggers) and I need a #Viewscoped because some Primefaces components require it.
I have thought about using EL inside an onClick event like that:
<p:commandButton onclick="window.open('pageB.xhtml?faces-redirect=true&idvalue=#{theReg.paramValue}', '_blank')" value="#{theReg.title}"/>
But I would like to use params as I feel it would be the "cleanest" method.
Any suggestion?
Thanks a lot in advance!

MySql EntityFrameworkCore System.TypeLoadException

I am trying to connect my web API to MySql database with this code:
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
string conn_string = "server=server;database=database;uid=uid;pwd=pwd;";
MySqlConnection conn = new MySqlConnection(conn_string);
services.AddDbContext<TaskContext>(options =>
{
options.UseMySQL(conn);
});
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMvc();
}
}
But I always recieve a System.TypeLoadException with this description:
System.TypeLoadException : 'Method 'Clone' in type
'MySQL.Data.EntityFrameworkCore.Infraestructure.Internal.MySQLOptionsExtension'
from assembly 'MySql.Data.EntityFrameworkCore, Version=8.0.8.0,
Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an
implementation.'
I am using Microsoft Visual Studio Community 2017 Preview (2) and my projet is in .NET Core 2.0. I also use MySql.Data.EntityFrameworkCore.dll and Microsoft.AspNetCore.All (2.0.0-preview2-final). I have changed many times of librairy for MySql but without success.
Any idea why this always happen? What could be the cause?
Well, it turns out that you can't use MySql.Data.EntityFrameworkCore for .Net Core 2.0(for now). I had to go back to .Net Core 1.3 to make it work... We may be able to use it in a near futur tho!
Use Pomelo.EntityFrameworkCore.MySql 2.0.0.
Works fine for me with .NET Core 2.0
Add "Pomelo.EntityFrameworkCore.MySql" package.
in Stertup.cs & appsettings.json & DbContext :
services.AddDbContext<mvccoreContext>(options =>
options.UseMySql(Configuration.GetConnectionString("DefaultConnection")
));
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=mvccore;User=root;Password=;"
},
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*"
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseMySql("");
}
}
MySql.Data.EntityFrameworkCore supports (and is only compatible with) EF Core 2.1. Using mismatched EF Core and DB provider libraries will result in errors similar to the one you reported.
If you need a MySQL EF Core provider that's compatible with EF Core 3.0, your only option right now is the 3.0.0-rc1 version of https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql (see the compatibility table at https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#compatibility)! ).
Otherwise, if you want to stick with MySql.Data.EntityFrameworkCore you'll need to roll back to EF Core 2.1.

How to only use IOC container from MVVMCross

I'm working on a existing Windows Phone project and want to use the IOC container from MVVMCross, but not the other extra features (yet).
I installed MVVMCross.Core 4.x and try to use 'ConstructAndRegisterSingleton' from the App() constructor of the Windows app, but it throws an Null ref exception.
Tried to find any bootstrapper, setup or initialization for MVVMCross but can't find any in the new 4.x core.
Anyone any idea?
Found it.... and it seems to work.
Just get MVVMCross.Core from Nuget and create a setup like:
internal static class Setup
{
public static void InitializeIoc()
{
CreateIocProvider();
// Register all services
Mvx.ConstructAndRegisterSingleton<ILoudnessLimitsRegulator, LoudnessLimitsRegulator>();
}
private static void CreateIocProvider()
{
// Ioc options
var options = new MvxIocOptions();
// initialize the IoC registry, then add it to itself
var iocProvider = MvxSimpleIoCContainer.Initialize(options);
Mvx.RegisterSingleton(iocProvider);
}
}

Getting started with rhino service bus

I've read a lot of examples/tutorials (incl. Ayende's Alexandria on MSDN).
But just getting somewhat updated assemblies have proven to be an obstacle in itself. After getting the correct version of Castle.Windsor - it cannot find the correct section in the app.config file. The syntax in both Rhino Service Bus and the CastleBootstrapper has been changed as well - and I'm now totally confused. The 'documentation' on Hibernating Rhinos is really not helping me get started.
Could anyone please help me a working sample with Rhino Service Bus with either Castle Windsor v. 3.0 (beta) or 2.5.3, point me at something already online or just giving me a step-by-step pointers on what I need to get up and running?
after downloading the latest Rhino-ESB bits from github (https://github.com/hibernating-rhinos/rhino-esb) and building it, it's pretty straightforward to get started.
I have a asp.net MVC application which communicates with a backend through Rhino-ESB.
On the asp.net MVC side:
On global.asax.cs:
private IWindsorContainer _container;
protected void Application_Start()
{
_container = new WindsorContainer();
new RhinoServiceBusConfiguration().UseCastleWindsor(_container).Configure();
_container.Install(new YourCustomInstaller());
//Don't forget to start the bus
_container.Resolve<IStartableServiceBus>().Start();
ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(_container));
}
Note that YourCustomInstaller must implement IWindsorInstaller and you register your controllers with the container in the Installmethod:
public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
{
container.Register(Component
.For<HomeController>().LifeStyle.PerWebRequest.ImplementedBy<HomeController>());
Also note that the WindsorControllerFactory internally delegates controller creation to the container:
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
if (controllerType == null)
return null;
return (IController)this.container.Resolve(controllerType);
}
Last but not least, provide the configuration on your web.config
<configSections>
<section name="rhino.esb" type="Rhino.ServiceBus.Config.BusConfigurationSection, Rhino.ServiceBus"/>
</configSections>
<rhino.esb>
<bus threadCount="1"
numberOfRetries="5"
endpoint="rhino.queues://localhost:31316/Client"
queueIsolationLevel="ReadCommitted"
name="Client"/>
<messages>
<add name="YourMessagesNamespace"endpoint="rhino.queues://localhost:31315/Backend"/>
</messages>
</rhino.esb>
This configuration assumes that the backend runs a queue in localhost:31315 and the client runs its queue on localhost:31316.
On the backend side:
assuming we're running it as a console application,
static void Main(string[] args)
{
IWindsorContainer container;
container = new WindsorContainer();
new RhinoServiceBusConfiguration()
.UseCastleWindsor(container)
.Configure();
var host = new RemoteAppDomainHost(typeof(YourBootstrapper));
host.Start();
Console.WriteLine("Starting to process messages");
Console.ReadLine();
Notice that YourBootstrapperclass implements CastleBootstrapper
public class YourBootstrapper: Rhino.ServiceBus.Castle.CastleBootStrapper
{
protected override void ConfigureContainer()
{
Container.Register(Component.For<OneOfYourMessages>());
}
}
in which we're registering a consumer for OneOfYourMessages