Win a copy of Getting started with Java programming language this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF JSP in java  RSS feed

 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning,

I want to show a value from the database in the input text using JSF JSP in java, so when I add new filed there are start date, end date and form these days I will calculate the days between these dates so the result automatic displayed in the input text

Now this value (result) saved automatic in the DB but, I want it to appear in the input text direct when the user enters the two dates (start and end).

I hope you understand me.
Thank you in advance.
 
Roel De Nijs
Sheriff
Posts: 10900
155
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wadha alketbi wrote:Now this value (result) saved automatic in the DB but, I want it to appear in the input text direct when the user enters the two dates (start and end).

And which code do you already have so far?
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And which code do you already have so far?


I have the method that calculate the number of days between 2 dates (in the back bean or manged bean of the page that have the UI):


Also, I have method that do add for the values to DB:

 
Roel De Nijs
Sheriff
Posts: 10900
155
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what about your JSP file? Because that's where the calculated value should be displayed if I understand correctly. The method to calculate the number of required days has no added value for the question you have asked, but the JSP file does matter.
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so, I want the result of the calculation to be stored in the DB and to be in the input text at the same time.
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what about your JSP file? Because that's where the calculated value should be displayed if I understand correctly. The method to calculate the number of required days has no added value for the question you have asked, but the JSP file does matter.


My JSP file is available and it has the required fields, so as you can see I have the 2 dates, I want that when the user enters the start and end dates is automatic displayed in the required days input text as will as store this value in the DB.

In addition to the JSP file I have  MangedBean class, Delegate class that works between the DB class and the mangedBean Class and the DB class that is dealing direct with DB.

hope you understand me .





 
Roel De Nijs
Sheriff
Posts: 10900
155
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wadha alketbi wrote:so, I want the result of the calculation to be stored in the DB and to be in the input text at the same time.

Why would you want to store a calculated value in your database?

And do you submit your form to calculate the number of required days?
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want to store a calculated value in your database?


Because one of the required field is time spent in days which is (required days).

And do you submit your form to calculate the number of required days?


To calculate and to add the values to the DB at the same time.

 
Roel De Nijs
Sheriff
Posts: 10900
155
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wadha alketbi wrote:Because one of the required field is time spent in days which is (required days).

So the number of required dates will be updated as well when either start or end date is changed (either through the webapp or directly in the database)?

wadha alketbi wrote:To calculate and to add the values to the DB at the same time.

And which page is shown after the insert into the database completes successfully?
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the number of required dates will be updated as well when either start or end date is changed (either through the webapp or directly in the database)?


yes, so the number of required dates depends on the start date and end date, when the user enter the start and end dates the result will show in the input text and it will be saved to the DB
also, there is another mode when the user update the dates the result will be updated.


And which page is shown after the insert into the database completes successfully?


message(all values has been inserted successfully)
 
Roel De Nijs
Sheriff
Posts: 10900
155
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wadha alketbi wrote:message(all values has been inserted successfully)

So how can you show the number of days in the input field if you just show a message
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So how can you show the number of days in the input field if you just show a message


While the user enters 2 dates the result should directly displayed in the input text before the user submit the form
after the user submit the form (Save button), all the values will be saved to the DB
 
Roel De Nijs
Sheriff
Posts: 10900
155
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wadha alketbi wrote:While the user enters 2 dates the result should directly displayed in the input text before the user submit the form
after the user submit the form (Save button), all the values will be saved to the DB

Then you need to perform an ajax request once both values are entered to retrieve the required days field. Or you could have some javascript to perform the calculation of the number of days client-side. But it makes no sense to send all three values with the form, because a user could change the required days field and provide another (incorrect) value. So you will have to (re)calculate the value before saving it into the database. That's one of the reasons why it doesn't make sense to store calculated values (unless you want to improve the performance).

But I am pretty sure each RDBMS will have several functions to calculate the number of days as well between two dates...
 
Tim Holloway
Bartender
Posts: 18514
61
Android Eclipse IDE Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You guys seem to be doing fine without me, but I am obliged to make one observation:

JSPs are not supported in JSF anymore.

JSF version 1 started out using JSPs to define their View Templates. Late in its lifespan, someone (I forget whom) developed an alternative XML-based templating system called Facelets.

The Facelets templates are not JSPs. They are a form of xhtml, defined by Oracle as View Definition Language (VDL) or View Template Language (VTL).

When JSF Version 2 was released, all support for JSPs was dropped. JSPs no longer work in JSF 2.0 and later, and since that was several years ago now, anyone using JSF version 1 - and JSPs should be seriously budgeting resources to upgrade, since support for JSF1 is going to be hard to find.

JSPs by definition are expected to convert to executable Java code (servlers). VDL is not - it compiles directly into a JSF component tree (data structure). So the processing is very different.

Fortunately, it's usually fairly simple to translate old JSPs into VDL, as long as you didn't do anything extreme, such as including scriptlets on the JSPs.

People often refer to JSF templates as "JSPs", even when they're actually referring to VDL, but I do feel obliged to point out the difference. Like I said, JSF version 1 is horribly obsolete now, and anyone using it should plan accordingly.
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then you need to perform an ajax request once both values are entered to retrieve the required days field. Or you could have some javascript to perform the calculation of the number of days client-side. But it makes no sense to send all three values with the form, because a user could change the required days field and provide another (incorrect) value. So you will have to (re)calculate the value before saving it into the database. That's one of the reasons why it doesn't make sense to store calculated values (unless you want to improve the performance).

But I am pretty sure each RDBMS will have several functions to calculate the number of days as well between two dates...


What you said is true, but I have two modes or we can say 2 forms, if the user will add new record to the DB, it will show for him/her the add form and then he/she will submit. Otherwise if the user wants to update a record from the DB, it will show for him/her the update form that is allow the user to change the values.

may be I have to read more about ajax request because I'm beginner. 
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway,
Thank you for your participation, it is new information
thank you again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!