Re: [payara-forum] @Viewscoped beans are not replicated in cluster environment

106 views
Skip to first unread message
Message has been deleted

Ondro Mihályi

unread,
May 18, 2018, 5:26:25 AM5/18/18
to NamNVH, Payara Forum
Hi, does it work differently if you reload the page and the request goes to the same instance?

AFAIK, what you described is expected - a viewscoped bean lives only within a single view (for multiple requests on the same HTML page). When you reload a page you get another view and the old beans are lost.

What's the problem then?

Ondro 

2018-05-18 5:44 GMT+02:00 NamNVH <hoangna...@gmail.com>:
1. Cluster structure
Load balancer -> web server -> 2 payara instances (so called Node 1 and Node 2)
2. Problem
When I opened A.xhtml, first request went to Node 1. @Viewscoped bean was created. 
I turned off Node 1, then click a button on A.xhtml to reload the view, request went to Node 2.
However, @Viewscoped bean datas were lost on Node 2.
Note that all my @Sessionscoped beans were correctly replicated and their datas were kept.
Is this normal behavior?

*Additional Information
3. Technology
- Payara Server 4.1.1.163
- JSF 2.2 (Mojarra implementation)
- Using Hazelcast for session replication
4. Detailed configuration
4.1. glassfish-web-xml
 
 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
   
<parameter-encoding default-charset="UTF-8" />
   
<context-root>/</context-root>
   
<session-config>
       
<session-manager persistence-type="hazelcast">
       
<!--<session-manager persistence-type="replicated">-->
         
<manager-properties>
           
<property name="persistenceFrequency" value="web-method"/>
           
<property name="relaxCacheVersionSemantics" value="true"/>
         
</manager-properties>
         
<store-properties>
           
<property name="persistenceScope" value="session"/>
         
</store-properties>
       
</session-manager>
       
<cookie-properties>
         
<property name="cookieSecure" value="false"/>
       
</cookie-properties>
   
</session-config>
</glassfish-web-app>

4.2. web.xml (some parts were left out)

<web-app xmlns:xsi="w3.org/2001/XMLSchema-instance"
 
xmlns="xmlns.jcp.org/xml/ns/javaee"
 
xsi:schemaLocation="xmlns.jcp.org/xml/ns/javaee xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
 
version="3.1">
 
<distributable/>
 
<env-entry>
   
<env-entry-name>jsf/ClientSideSecretKey</env-entry-name>
   
<env-entry-type>java.lang.String</env-entry-type>
   
<env-entry-value>xxxxxxxxxxxxxxxxxxx</env-entry-value>
 
</env-entry>
 
<!-- setting save viewstate by hidden field by client -->
 
<context-param>
   
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
   
<param-value>client</param-value>
 
</context-param>
 
<filter>
 
<filter-name>LoginFilter</filter-name>
 
<filter-class>com.c1s.common.filter.LoginFilter</filter-class>
 
</filter>
 
<filter-mapping>
 
<filter-name>LoginFilter</filter-name>
 
<url-pattern>*.xhtml</url-pattern>
 
<dispatcher>FORWARD</dispatcher>
 
<dispatcher>REQUEST</dispatcher>
 
<dispatcher>INCLUDE</dispatcher>
 
<dispatcher>ASYNC</dispatcher>
 
<dispatcher>ERROR</dispatcher>
 
</filter-mapping>
 
<servlet>
   
<servlet-name>Faces Servlet</servlet-name>
   
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
   
<load-on-startup>1</load-on-startup>
 
</servlet>
 
<servlet-mapping>
   
<servlet-name>Faces Servlet</servlet-name>
   
<url-pattern>*.xhtml</url-pattern>
 
</servlet-mapping>
 
<session-config>
   
<session-timeout>30</session-timeout>
   
<tracking-mode>COOKIE</tracking-mode>
 
</session-config>
</web-app>

--
You received this message because you are subscribed to the Google Groups "Payara Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to payara-forum+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/payara-forum/e6af5891-b567-4588-aac7-b014dc40436f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

NamNVH

unread,
May 18, 2018, 6:18:55 AM5/18/18
to Payara Forum
Hi Ondro,
Sorry for my unclear statement.
I simply sent a POST request to reload the page (which means I'm still at the same view), so I expect the datas in @Viewscoped bean would still be kept.
After I click the button, if the request goes to the same instance, the datas will be kept as expected.
If the request goes to the other instance, the datas will be lost.

Any ideas about this problem?
Thanks in advance.

Steve Millidge

unread,
May 18, 2018, 7:35:12 AM5/18/18
to Payara Forum
For anything stored in a session you must ensure that the bean and everything it references is Serializable. Check all your beans to ensure everything is Serializable.

NamNVH

unread,
May 18, 2018, 10:05:47 AM5/18/18
to Payara Forum
Yes, I have thoroughly checked this, 
In our project, we have @Requestscoped, @Viewscoped, @SessionScoped, @ApplicationScoped and @EJB. 
We have ensured all these beans and everything they reference are seriliazable (I know that making @Requestscoped.seriliazable is redundant, but I''m just making sure).

Do you have any other suggestions, especially for the case of @Viewscoped bean?
Thanks in advance.

Ondro Mihályi

unread,
May 19, 2018, 2:15:47 AM5/19/18
to NamNVH, Payara Forum
Does replication work if you use @SessionScoped instead of @ViewScoped? If not, then there's a problem somewhere in your configuration.

Can you try?

Dňa pi 18. 5. 2018, 16:05 NamNVH <hoangna...@gmail.com> napísal(a):
--
You received this message because you are subscribed to the Google Groups "Payara Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to payara-forum...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/payara-forum/876f44ba-b22c-4966-9e17-7c274ffb4580%40googlegroups.com.

NamNVH

unread,
May 19, 2018, 6:19:41 AM5/19/18
to Payara Forum
Hi Ondro,

I used @SessionScoped instead of @ViewScoped, everything worked as expected.
Datas were still kept when the request went to Node 2.
Could you think of anything which may cause my problem?

Ondro Mihályi

unread,
May 20, 2018, 3:04:30 PM5/20/18
to NamNVH, Payara Forum
Possibly a bug. Please, create an issue on Payara github with a reproducible example application.

Ondro

--
You received this message because you are subscribed to the Google Groups "Payara Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to payara-forum+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/payara-forum/a42bb428-1687-4c03-91c4-14a5f7b7180a%40googlegroups.com.

NamNVH

unread,
May 21, 2018, 2:30:50 AM5/21/18
to Payara Forum
Hi Ondro,

I created an issue on github with the sample:
Could you please take a look.

On Monday, May 21, 2018 at 2:04:30 AM UTC+7, Ondro Mihályi wrote:
Possibly a bug. Please, create an issue on Payara github with a reproducible example application.

Ondro
2018-05-19 12:19 GMT+02:00 NamNVH <hoangna...@gmail.com>:
Hi Ondro,

I used @SessionScoped instead of @ViewScoped, everything worked as expected.
Datas were still kept when the request went to Node 2.
Could you think of anything which may cause my problem?

On Saturday, May 19, 2018 at 1:15:47 PM UTC+7, Ondro Mihályi wrote:
Does replication work if you use @SessionScoped instead of @ViewScoped? If not, then there's a problem somewhere in your configuration.

Can you try?

--
You received this message because you are subscribed to the Google Groups "Payara Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to payara-forum...@googlegroups.com.

Ondro Mihályi

unread,
May 22, 2018, 11:59:25 AM5/22/18
to NamNVH, Payara Forum
Thanks for raising this.

From the discussion in the issue you've raised it's clear that this is a bug. It's fixed in Payara 5.x but not in Payara 4.x. So you should either upgrade to Payara 5 or refactor your application to use an alternative view scope, e.g. from OmniFaces (http://showcase.omnifaces.org/cdi/ViewScoped). Or get a support contract to get a backported fix to Payara 4.

Ondro

2018-05-21 8:30 GMT+02:00 NamNVH <hoangna...@gmail.com>:
Hi Ondro,

I created an issue on github with the sample:
Could you please take a look.

On Monday, May 21, 2018 at 2:04:30 AM UTC+7, Ondro Mihályi wrote:
Possibly a bug. Please, create an issue on Payara github with a reproducible example application.

Ondro

2018-05-19 12:19 GMT+02:00 NamNVH <hoangna...@gmail.com>:
Hi Ondro,

I used @SessionScoped instead of @ViewScoped, everything worked as expected.
Datas were still kept when the request went to Node 2.
Could you think of anything which may cause my problem?

On Saturday, May 19, 2018 at 1:15:47 PM UTC+7, Ondro Mihályi wrote:
Does replication work if you use @SessionScoped instead of @ViewScoped? If not, then there's a problem somewhere in your configuration.

Can you try?

--
You received this message because you are subscribed to the Google Groups "Payara Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to payara-forum...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/payara-forum/a42bb428-1687-4c03-91c4-14a5f7b7180a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Payara Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to payara-forum+unsubscribe@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/payara-forum/e7121561-ce09-47a1-9f1c-cdec14ec78d2%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages