This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Grokking Bitcoin and have Kalle Rosenbaum on-line!
See this thread for details.
Win a copy of Grokking Bitcoin this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Frits Walraven
Bartenders:
  • Carey Brown
  • salvin francis
  • Claude Moore

Parameter passing problem  RSS feed

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 20640
122
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
Create Edit Print & Convert PDF Using Free API with Java
https://coderanch.com/wiki/703735/Create-Convert-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!