• Post Reply Bookmark Topic Watch Topic
  • New Topic

call function inside other function  RSS feed

 
Riccardo Marfisi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I would use the return value of a function how parameter of other function

In java is:


In my web page I need to do something like this:

obtain:
javax.servlet.ServletException JBWEB006007: Failed to parse the expression








is possible to do this?



I'm sorry for my bad english and thanks in advance.

Riccardo
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not call one java function in the backing bean which calls the two functions?
 
Tim Holloway
Bartender
Posts: 18549
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Ricardo!

Primero: JSF backing beans are not Controllers. They are Models. The action methods are business methods not defined as part of MVC and specific to JSF. A Controller is something that synchronizes the Model and the View, and in JSF the Controllers are not user-supplied. They are prewritten function in the FacesServlet and in the View Definition tags.

Segundo: EL is not a programming language. It is an expression language. In the case of "value=" expressions, what it's expecting are property references, not function calls.

A proper EL expression would look more like this:



Or like this:



The second form is what you'd use if "property" was a Map.

 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Holloway wrote:
Segundo: EL is not a programming language. It is an expression language. In the case of "value=" expressions, what it's expecting are property references, not function calls.


For action methods on commands you would use . In EL 2.2 you can even pass parameters to those methods with
 
Riccardo Marfisi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I post my real code, where I use CDI & JSF Navigation Rule:







faces-config.xml


then I would use:


navigationController.loginToHome(true) if the user and password (of same form) are correct.


my question is, in general, if can I use the output of function in parameter of other function (at press of button)?


thanks
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Riccardo Marfisi wrote:
my question is, in general, if can I use the output of function in parameter of other function (at press of button)?

thanks

And I said don't do that and instead call one method on the backing bean and make that method call as many methods as you want passing whatever parameters are required.
e.g use and you will have access to the canAccess property inside the loginToHome method so no need to pass it from the page.

If you want to persist with that approach then the correct syntax would be which will only work if you have at least EL 2.2.
 
Riccardo Marfisi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

I used


end modify my class


it work fine.

thanks
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't do that. Don't make database calls in getters. You only ever want that called once not as many times as the JSF lifecycle decides to. Better do that in the bean constructor. Also, it is discouraged to make your own security module. Better use JAAS related mechanisms which are provided by your container.
 
Tim Holloway
Bartender
Posts: 18549
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To qualify Mr. Armitage's answers, somewhat.

In JSF version 2, you do get a lot more flexibility in the EL. But PLEASE use it sparingly! When you put logic in the View Template, it pollutes the MVC paradigm. Whether you want to be ideologically pure or not is one thing, but in practical terms, when logic is split between backing beans and View Templates, it becomes a maintenance nightmare. It means that changes to either Model or View definition must be accompanied by a "treasure hunt" where you locate the other half of the equation and make sure it doesn't get broken by the changes on the first half. MVC was created because it implements Separation of Concerns where the Model and View are mostly ignorant of each other and the benefits of that low degree of cross-coupling have proven themselves over and over.

Also, EL is a to debug. It's a lot easier to keep the EL simple and debug the Model-side Java code.

I want to reinforce what he said about not doing database functions in getters. Or setters. You don't know how many times they will be invoked on a single request/response cycle so the potential slowdown can be enormous, And, if the operations are not idempotent (meaning that there are cumulative side-effects), then the results can be completely unpredictable.

What I generally do if I need database data on a property get is check a local cache for the value, and if the cache isn't set, do the database operation once and cache the results. So that the subsequent operations don't have the overhead.

Also, the login and role-checking functions in the J2EE standard are properly called "Container-managed security". That's what it is - the container (webapp server) screens incoming URLs and determines if the user needs to be logged in, and if so, it runs the login process using container code (NOT webapp code). A logged-in user's URL requests are checked by the container to determine if the request is valid for the security role(s) assigned to that user.

By using container-based security, your app becomes simpler, since there's less security code to write, more secure, because the app cannot be attacked unless the attack request was passed through from the container, which is providing your first-line defense, and the security becomes more reliable, since it's had about 15 years to be well-debugged. Plus, it's well-documented so people can buy a book and know how to use it properly, unlike the Do-It-Yourself custom security systems, which nobody ever has time to document properly.

DIY logins are also infamously insecure. Most of them can be bypassed by non-technical people in 15 minutes or less.

Container security and JAAS are 2 different things. JAAS is a general-purpose security manager. J2EE container security operates using plug-in security components called Realms. There is a JAAS Realm for most popular webapp servers, but there are also JDBC and LDAP Realms as well. I've written Realm modules that invoked web services and there are many other Realm components available, both vendor-supplied and custom.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!