Re: WebSocket Filter to open a Hibernate Session

2015-09-16 Thread Marco Springer
Hi Martin,

That's something I figured out as well, the bypassing of the Filters by 
WebSocket requests.

I did as you said and implemented a custom IRquestCycleListener to 
respond on the onBeginRequest & onEndRequest in case there is a 
WebSocketRequest.
This is working correctly now! Thanks for the pointer.

One other question though, since this seems awfully similar to how OSIV 
works.
If I do not filter on WebSocketRequest and allow the Session opening for 
each incoming request, in theory I should not need to apply the 
"OpenSessionInViewFilter" anymore correct?

But then another thing I noticed...
I set a debug point inside the onBeginRequest & onEndRequest to see 
what's is passing through those functions.
Apparently for a single page request the onBeginRequest & onEndRequest 
are called multiple times while I have no Lazy Loading components on that 
page.
My guess would be that those multiple requests are for the resources that 
needed to be loaded, e.g. images/js/css/whatever.
In that respect, it would absolutely not be wise to use that to open & close 
hibernate sessions ;-)

Upon a WebSocket event, the onBeginRequest & onEndRequest are called 
only once, so that's correct.

Again thanks.

Best Regards,
Marco Springer

On Tuesday 15 September 2015 18:06:51 Martin Grigorov wrote:
> Hi,
> 
> Servlet Filters are not used when sending messages in web socket
> connection. This is how Servlets work at the moment.
> 
> You can use Wicket's IRequestCycleListener's 
onBeginRequest/onEndRequest.
> 
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
> 
> On Tue, Sep 15, 2015 at 4:32 PM, Marco Springer  
wrote:
> > Hi,
> > 
> > Using normal requests and long-polling ajax timers to update an 
interface
> > works fine with hibernate sessions.
> > Now I'm trying to implement WebSockets to update small parts of a 
web
> > application that come from server side events. I want to get rid of the
> > long
> > polling.
> > 
> > For now I'm only using a @Scheduled annotation to broadcast an 
event to
> > all attached clients. As a simple scenario.
> > 
> > The web application should, in response, update with loading new 
data
> > from a database using Hibernate.
> > 
> > This is where it fails, giving the message:
> > /Caused by: org.hibernate.HibernateException: No Hibernate Session
> > bound to thread, and configuration does not allow creation of non-
> > transactional one here/
> > 
> > I know this fails due to the fact that WebSocket events don't go 
through
> > the normal filters, e.g. OpenSessionInViewFilter that I'm using.
> > 
> > 
> > *My question:*
> > Where can I create a hook where I can start the Hibernate Session 
the
> > same way the OpenSessionInViewFilter does?
> > 
> > If I'm totally off with my thoughts, I'd like to hear that too :)
> > 
> > Used libraries:
> > wicket 6.19.0
> > wicket-sprint 6.19.0
> > wicket-native-websocket-jetty9 6.19.0
> > hibernate 3.6.10-Final
> > springframework 3.2.13-RELEASE
> > (Why the old Hibernate/Spring versions: haven't had time to migrate 
yet,
> > too much to do!)
> > 
> > Thank you very much in advance.
> > 
> > Best regards,
> > Marco Springer


Re: BeanValidation --> wrong maxlength value in TextField

2015-09-16 Thread Francois Meillet
Hi Martin,

Sorry for the  .
I miss it.

Thanks for your insights.

In the ConstraintIterator's constructor, the set returned by the Hibernate 
validation implementation (Set constraints)
is unordered.

Either by calling
Set constraints = propDesc.findConstraints()
.unorderedAndMatchingGroups(groups)
.getConstraintDescriptors();

or  
BeanDescriptor beanDescriptor = 
validator.getConstraintsForClass(IdentityRegistrationModel.class);
PropertyDescriptor propertyDescriptor = 
beanDescriptor.getConstraintsForProperty(property);
Set constraintDescriptors = 
propertyDescriptor.getConstraintDescriptors();

As there are 2 annotations with the same type (Size) per property, 
@Size.List({
@Size(min=4, message = "{firstName.sizeToSmall}"),
@Size(max=50, message = "{firstName.sizeToBig}")
})
the last call to SizeTagModifier # tag.put() wins and maxlength may be wrong 
(Integer.MAX_VALUE).

The validation itself, when form is submitted, is OK.
Only the maxlenght may be wrong.   
   

One way to fix this problem :

In the ConstraintIterator's constructor, before populating the stack,
an iteration could be made over the 'Set constraints' 
to find ConstraintDescriptor with Annotation's type = Size,
and if there is more than one, the biggest (=Integer.MAX_VALUE) max value 
should be removed.

The other way is to add an AttributeModifier to the textfield, new 
AttributeModifier("maxlength", new Model<>(50))). 
Which I do.

François








Le 15 sept. 2015 à 21:47, Martin Grigorov  a écrit :

> Hi Francois,
> 
> A miracle happened after adding  &  HTML elements to
> PageWithForm.html ;-)
> Without  Wicket logs an ERROR.
> 
> About Integer.MAX_VALUE - a breakpoint
> at org.apache.wicket.bean.validation.SizeTagModifier#modify shows that this
> method is called twice per property. Once with annotation.max() returning
> MAX_VALUE and second time with the set value(50). Maybe there is a bug at
> Hibernate-Validator
> or org.apache.wicket.bean.validation.ConstraintIterator#ConstraintIterator.
> 
> Enjoy!
> 
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
> 
> On Tue, Sep 15, 2015 at 11:00 AM, Francois Meillet <
> francois.meil...@gmail.com> wrote:
> 
>> Hi,
>> 
>> I have a very strange problem !!!
>> 
>> 
>> A form is created using a model object containing validation annotation
>> constraints.
>> 
>> The model object contains 3 properties (a, firstName, lastName) with
>> annotations like this
>> 
>> @Size.List({
>> @Size(min=2, message = "{xxx.sizeToSmall}"),
>> @Size(max=50, message = "{xxx.sizeToBig}")
>> })
>> 
>> xxx.sizeToSmall and xxx.sizeToBig key/value are present in the
>> WicketApplication.utf8.properties file
>> 
>> When the form is rendered, the maxlength value may be wrong.
>> 
>> 
>> Actually the maxlength value is only wrong with the property 'firstName'
>> 
>> with the following html
>> 
>> 
>> 
>> but with
>> 
>> the value will be ok
>> 
>> This only happens with this 'firstName' property !!!
>> 
>> 
>> Environment:
>> ---
>> Wicket 7.0.0
>> validation implementation : hibernate-validator
>> OSX & jdk 1.8
>> 
>> 
>> here is the quickstart
>> 
>> Thanks for yours suggestions
>> 
>> François
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 



JQuery onclick events broken on component reloading

2015-09-16 Thread Marco Di Sabatino Di Diodoro

Hi All,

I've some trouble working to integrate AdminLTE template onto my wicket 
application (wicket-bootstrap based).
An AdminLTE SimpleThemeProvider  has been implemented and configured 
successfully.
Currently, I'm working to create a sidebar panel based on AdminLTE 
components: this component is created dynamically based on items 
retrieved via REST querying my server.


The AdminLTE sidebar is a  side menu managed by specifying particular 
behaviours (defined by JQuery functions) for specific click events.
This events are given by the AdminLTE.js javascript file itself included 
among page header items and executed at every page loading.


Till this point, everything works fine.
The problem occurs when I need to reload the sidebar panel ( via 
target.add(sidebar) ): in fact this operation seems to break each link 
between click events and behaviours previously defined on panel side bar 
components (via AdminLTE.js, as said before).


 To fix the problem AdminLTE.js re-execution is required. I implemented 
this operation by providing a renderHead function into the side bar 
panel that I'm going to reload.


@Override
public void renderHead(final IHeaderResponse response) {
super.renderHead(response);

final PackageTextTemplate ptt = new 
PackageTextTemplate(AdminLTE.class, "js/AdminLTE-app.min.js");

response.render(OnLoadHeaderItem.forScript(ptt.asString()));
}

In this way some malfunctions have been introduced: it seems that at the 
first page loading the same event is attached twice.
By including a boolean into the panel to check for the first loading, it 
seems that I solve the problem  at least for the sidebar panel 
itself. Unfortunately, other components seem to be affected by this 
multi-execution.


What is the best-practice to manage this kind of scenario? Can someone 
help me with this issue?


Regards
Marco

--
Dott. Marco Di Sabatino Di Diodoro
Tel. +39 3939065570

Tirasa S.r.l.
Viale D'Annunzio 267 - 65127 Pescara
Tel +39 0859116307 / FAX +39 085973
http://www.tirasa.net

Apache Syncope PMC Member
http://people.apache.org/~mdisabatino/