Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

[JSTL] Calling methods, constructor, using params  RSS feed

 
Michael Houlo
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

I'm now using some JSTL and i would like your help to understand it.
I could replace this :

By this :

Is it a good way to code ?

Also, i'm wondering how could i translate the following code by some JSTL code

getDateEntret() returns a GregorianCalendar instance.
How do i pass parameters to this object?

Instead of it, i made a new method getDateEntretMin in the Bean but then, i'll have much methods in that bean...

Could you please help me out?

Thanks !
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A conversion to JSTL is more than just replacing inappropriate Java that's on a JSP page with a JSTL equivalent. The JSTL and EL are designed to make it hard to put stuff that doesn't belong on a JSP page on the page -- so frequently, there isn't a direct translation. Processing data, including Calendars, is something that is more appropriately done in the controller rather than on the page.

If you are going to convert a page full of scriptlets to JSTL and EL chances are you are going to have to refactor it pretty heavily.
 
Michael Houlo
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:A conversion to JSTL is more than just replacing inappropriate Java that's on a JSP page with a JSTL equivalent. The JSTL and EL are designed to make it hard to put stuff that doesn't belong on a JSP page on the page -- so frequently, there isn't a direct translation. Processing data, including Calendars, is something that is more appropriately done in the controller rather than on the page.

If you are going to convert a page full of scriptlets to JSTL and EL chances are you are going to have to refactor it pretty heavily.


How would you insert a clock or a calendar with the correct info in it then ?
Would you let the bean do it ?
I'am afraid my bean will have an huge amount of methods.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So? Is it better to have a bean with a lot of methods, or a JSP choked with poor-practice Java code?

Even a bean may not be necessary, why can you not just handle any processing in the controller?
 
Michael Houlo
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because I don't want my Controller to write HTML code
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's correct, but who said anything about that? Generally, you'll handle all data processing in the controller, store the results to be displayed as scoped variables *usually on the request) and forward to the JSP for rendering the view.

 
Michael Houlo
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose that for each user, we store a lot of information : name,address,tel but also report of meetings and for each meetings, a list of offered products, customer reaction, ...
Would you then store each information in the request object ?
I think beans are totally useful in my case.

But then in the jsp, to navigate trought customer information, i have some radiobutton, checkbox, ... And i need to access to bean to check information & verify if i need to check the button or not.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You seem to be arguing in circles. Again generally, all data gathering and processing is done in the controller, and the information, possibly as a collection of beans or any other constructs that best represent the data, is passed to the JSP as scoped variables in the request.
 
Michael Houlo
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You seem to be arguing in circles. Again generally, all data gathering and processing is done in the controller, and the information, possibly as a collection of beans or any other constructs that best represent the data, is passed to the JSP as scoped variables in the request.


Actually, that's what i'm doing.
Sometimes it's stored in the session though.
But when you use your bean in the jsp, you still need to access methods..

For example, if one of them has an array of X items.. I can't use "getMyItem(3)" , right ?
I need to do getMyItems() and get the collection even if i only want one of 'em?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Leahcim wrote:For example, if one of them has an array of X items.. I can't use "getMyItem(3)" , right ?

If your class has such a method, it's not a bean.

I need to do getMyItems() and get the collection even if i only want one of 'em?

Exactly. Why is that an issue? It's the "bean way". And in the EL it simply becomes ${bean.myItems[3]}

I'd also argue that if you only need the 3rd item of a collection, I'd question the design of the bean. At minimum I'd make an abstracted property to access it.
 
Michael Houlo
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see.

Thanks a lot for all those answers !
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!