aspose file tools*
The moose likes JSF and the fly likes Parameter passing problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Parameter passing problem" Watch "Parameter passing problem" New topic
Author

Parameter passing problem

Rus Corina
Ranch Hand

Joined: Jul 08, 2011
Posts: 90
Hello. I am currently learning how to use jsf and i have a big problem that I don't know how to solve. I might not even be able to explain very accurate what the problem is but I will try.
Here it goes:
I have a page, admin.jsp, where you can perform CRUD operations on a table. The problem i have is with the Read action. In order to read users from the db, you insert the username and then press Read button. The users whose username is similar to the one inserted by the user are displayed in a datatable, on another page (data.jsp). The problem is, how do I transfer the username from one page to another? I have a bean, called "login_bean" where the username is kept, as long as I perform some operation from the bean on the admin.jsp page. But once I go to another page, username dissappears. I will post some code, hopefully it will become clearer.
PS: I simplifid the code and left only info concerning username, hoping that it will become easier to understand

admin.jsp:


data.jsp



login_bean.java


[/code]


I must mention that everything I did here was taken from internet examples. I don't know jsf/jsp, I needed to make a project for the university in 2 weeks, and I did not have much time to repare.

Thank you
Rus Corina
Ranch Hand

Joined: Jul 08, 2011
Posts: 90
I need to know how I can make the username in java_bean remain the same as it is in admin.jsp when the user presses "read" button and transfers him to data.jsp page
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

It is better to use on jsf page mainly jsf components. Instead of <table> use <h:dataTable>
If you want to pass some parameter from one page to another look at this simple sample:
This is command button that can execute some method of bean and navigate to next page by 'action' attribute:

Of course it is only part of that page. <f:viewparam> element takes id passed from previous page and stores id in bean.selectedEventId.
It is important to have attribute 'name' of f:param and <f:paramview> with identical value on both pages. Also action attribute must include- includeViewParams=true


True person is moral, false is right!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16014
    
  20

It's even better not to put parameters on pages at all. They add to network traffic, they offend the MVC architecture by blurring the separation between Model and View, and they can be exploited by hackers.

JSF is designed to keep most of its data on the server side, therefore you usually shouldn't send data out to the View and back in again as parameters, you should simply transfer the data from backing bean to backing bean.

I could do an entirely different rant on user-coded logins and why they are even more insecure than parameters on the View, but I'll probably do that somewhere else today anyway.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Parameter passing problem