This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!

Vasilis Souvatzis

Ranch Hand
+ Follow
since Mar 23, 2014
Vasilis likes ...
Chrome Java Netbeans IDE
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
6
Received in last 30 days
0
Total given
9
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vasilis Souvatzis

I know I started on the wrong foot with JSF three years ago, I had to write my thesis project and needed to have results as soon as possible. So I heavily relied on online code to make things work because I was on a deadline. Having no help from my supervisor didn't help also. So yes, I was exposed to a lot of old/old fashioned code. Most probably my misuse of EL comes from parameterized method calling, I used it weirdly in my thesis and probably stuck to me.

Lately I've been trying to shake off this misunderstanding and misuse, I like JSF and am quite productive with it although server-rendered frontends have moved aside last few years.

So far my approach to transactions seems to be working and the stock quantity is handled correctly. I will probably have to revisit it once I add online payments though, maybe keep the albums in a "reserved" state and remove them from stock or return them if the payment succeeds or not.
4 months ago
JSF
Well... I knew I was doing something wrong but didn't expect to be so far out. I had completely mistaken how to use EL properly, I've seen code online to directly call beans and logic so I assumed it's OK to do so. That's why Al asked why I was calling the DB from the view.

And in fact I was uncertain if my approach was good because for each item in the datatable I would query the DB to get the stock, for many albums and/or users I would strain the app-DB communication. Besides, now that I think of it I haven't seen online stores live updating the remaining quantities. It most likely occurs at some page update or something.


Actually I think I can just use the Stock entities. Since the Stock is referencing the Album with a OneToOne association, instead of getting the albums and then asking for the stock of each album, I can retrieve just the stocks and they contain the albums anyway. This way I'm getting the data and the view is just referencing them in the datatable. If this doesn't work (out of the top of my head I don't see why it shouldn't) I can make a POJO with the album and its quantity for the datatable alone.

You mention transactions to ensure data integrity. I'm assuming a Stateless bean is enough right? Their methods initiate separate transactions if I'm not mistaken, so the purchases will not have problems. It's highly unlikely that two or more people will start their transactions at the exact same millisecond, therefore it's not easy for someone to over-purchase. And if the stock decreases before a user places an order, then yes I can use the messages to notify them.
4 months ago
JSF
Well, my reasoning is that if I query the DB for the stock, every user will always have the remaining quantity.

If user A buys the last item before user B completes the purchases, user B cannot proceed since there is no more stock available, A was faster and bought the last item.

Otherwise I'll probably have to check on purchase if there is stock and proceed with the purchase or cancel it.

Is there some other way I should be doing it?

----------------------

I realized this though; the getStock() method is called 4 times for each album when I enter the store view! I have two calls in the view (what I posted above), but it sysouts 4 times for each album.

Regarding the debugger, I tried it but I cannot bypass the correct calls to the Stock Service, in order to go the other page and see why it crashes.
4 months ago
JSF
I don't get why it doesn't give a result the second time though.

When I have the following, it works without an issue


When I put

Why would it produce a result perfectly fine in the Stock column, but not in the validator? Both calls are in the same view.
4 months ago
JSF
Good afternoon! I'm building an e-shop record store for a friend, he'll be selling his used vinyls. For some of the records he has multiple copies of, so there is a Stock quantity and naturally people cannot buy more copies than the available stock.

In the Cart bean, I have a column that shows the quantity people want, and the available stock from the database: (disregard for a minute the maximum=3 in the validator)

This works and I can see the available stock in the next column. The getStock() method takes the album id and returns an int.

Considering I want people to enter quantities up to the available stock, the following seems logical to me:


It's the exact same EL expression I'm using in the next column to display the available stock, only this time I want to retrieve the maximum value from the DB.

The application crashes though with the following stack:

I guess it passes a null value to the getStock() method, because the EJB that fetches the Stock entity from the DB, returns no result.

The StockService.findByID is:


What can I do to fix this? Considering that in one occasion it works and in the other it doesn't. Does the validator run before the other expressions so it rightfully passes a null value?
4 months ago
JSF
Fantastic! This is great help thank you very much! I've read about REST design but it's much more understandable with my own code

OK so I'll have two final Controllers, one serving the /persons path and one serving the /appointmentsByDay. Much better organized!

I've known about subresources but wasn't sure how they worked. Your outline is invaluable! Current project is in Spring Boot 2.0 and it definitely has subresources.

In fact I think I'll refactor straight to subresources because (if I'm not mistaken) I'm more or less reusing the same controllers I have now.

Thanks for the hands-on help
7 months ago
Good evening! I'm finally building a REST application and could use some help regarding the API design, or rather lack there of.

What I have so far works and makes sense for me, but I doubt it's a "good" design and should ask for proper help anyway. At least start now before adding error handling etc

class Person : person entity holding info
class Measurement : @ManyToOne to Person, a person can have many measurements, in the person's profile i can see all their measurements
class Appointment: @OneToOne to Person, a person can have (or not) an appointment

Measurement and Appointment are the owner entities and it's a unidirectional association

Requirements:
I want to see all the persons in the database, then navigate to each profile
In the person's profile I can see their measurements, I can add or remove measurements
In the person's profile I can see if they have an appointment, if yes navigate to it
I want to see all appointments in a page, regardless of persons
Each appointment will show the person's info and nothing more

PersonController:
HTTPEndpointMethod
GET/personsfindAll
PST/personscreatePerson
GET/persons/{id}findByID
DEL/persons/{id}deletePerson

MeasurementController:
HTTPEndpointMethod
GET/persons/{id}/measurementsfindMeasurements
PST/persons/{id}/measurementsaddMeasurement
DEL/persons/{id}/measurements/{mid}removeMeasurement

AppointmentController:
HTTPEndpointMethod
GET/appointmentsfindAllAppointments
GET/appointments/{id}findAppointmentByID
DEL/appointments/{id}removeAppointment
GET/appointments/todaygetTodaysAppointments
GET/appointments/tomorrowgetTomorrowsAppointments
GET/persons/{pid}/appointmentfindByPersonID
PST/persons/{pid}/appointmentcreateAppointment


With the above "design", the UI in my mind works. I've read though that all resources should be under the same path, and here I have /persons endpoints in other controllers. Should this be redesigned or it's OK according to the requirements? Perhaps move the /persons/{id}/appointment endpoints in the PersonController and just leave the /appointments/... endpoint in the AppointmentController?
7 months ago
I just tried to pass null and it worked... It hadn't even occur to me to pass a null entity, it's quite obvious now that I see it clearly.

Thanks Rob
11 months ago
I'm a bit confused about passing info into a service with query parameters...

I have this service:

and if I send the following with Postman it works

I built it this way because I'm creating two objects (Customer and Coffee) and POSTing separately to their own services.

I made a simple JSF UI to take the input from the form and POST the service using the Client API. I think this time I'm confused because I don't really need the Response of the service, the POST will happen and the view will be refreshed to show the additions.

I thought something like this but I don't know what entity to put in the post method argument:

Should I create an object and pass that as a post entity argument?
11 months ago
You're absolutely right, I kind of figured what you explained about dates and timezones after I posted. After all, this is why all enterprise systems are extra careful with handling date and time. I understand.
1 year ago
JSF
When I don't want time of day or time zones though? I understand I should use timestamp with timezone to save timezone as well, I chose date as data type because I wanted to store just the date 01-08-2017.

I have no use of timestamps with or without time zones in my app. That's what confused me, I inserted dates but it behaved like dates+timezones.
1 year ago
JSF
I've done some more digging, and it was indeed a time zone issue. The answer is here (why I didn't find it before asking here I don't know). Those folks had the exact same issue with me.

Apparently, the JSF date conversion defaults to UTC. The date type I'm using in Postgresql is its own, perhaps some timezone in the US because otherwise it'd have worked. So I guess the database type takes precedence and is minus one day in the app. Changing the deployment descriptor sets the JSF's converters to my system's timezone.

And with all that, it's evident that my post's title is wrong and will not show up in people's searches. Could it be changed to "JSF convertDateTime shows different date than database" or similar?
1 year ago
JSF
Don't know what's wrong with me lately, I fail to do the simplest things. I even kept a pdf guide last time I wanted to secure an app, to avoid these exact same things... I'm either missing something tiny, or I've mangled this project so much it doesn't know what to do...

Form-based file realm authentication with Glassfish; I've entered my group names in the admin console of Glassfish.

From index.xhtml I'm calling:
<p:button outcome="protected/dashboard.xhtml" value="Chris"/>
<p:button outcome="user/profile.xhtml" value="User Area"/>


web.xml main contents

Security constraints:

And authentication method:

And the security role mapping in glassfish-web.xml


I really can't see where my problem is. Yesterday it was working, but I've changed so many things I can't track down what I did. And I feel really stupid for asking trivial questions, things I've already done. This project is really simple but it will be the death of me...
1 year ago
Here's something fun which was partially answered in the Primefaces forum but doesn't help me fix it.

In my JSF view, I use Calendar to select a date and persist it to the DB, let's say 31/7/2017. It's saved in the DB as "2017-07-31T00:00:00Z". When I retrieve the date to show on the datatable, it shows the day before 30/7/2017. This happens for all dates, maybe the conversion fails somehow? No matter what date I have in the DB, the date shown in the datatable is the previous day.

This is what I do:

Someone said it's probably a timezone issue and asked where is the client and server located. I'm developing on my machine and haven't deployed online yet. I really don't know how to proceed, how can I check the timezones?
1 year ago
JSF
Hey Jeanne, sorry for the late response.

My "product" is simple, just an app I'm building and decided to use the default security mechanisms because they're more than enough, nothing fancy really. I haven't worked with servlets yet but I'll try to make it work, there are many examples online although many are outdated or extremely complicated.

I know that "security" is a highly subjective topic and depends on the application, that's why I'll stick to the provided mechanisms for now and if I need to use something else, I'll try that. If I'm not mistaken (JACC?) provides security for JSF and HTTP requests as well, so I'll be able to secure an HTML client as well.
1 year ago