• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Which Package to Import to Use FacesContext's getRequestMap()?

 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to use the FacesContext's getRequestMap() method. The compiler cannot recognize the getRequestMap() method.

I think that I have import a certain package in the begining of my Java class to resolve the problem. I have tried a number of packages and they did not work. Does anybody know the answer? Thank you.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

[ August 30, 2005: Message edited by: seb petterson ]
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply. I think my question boils down to "how to get the Java bean for a particular row in a JSF dataTable. My code is like:


The error message is that "getRequestMap is undefined for the FacesContext". Apparently, the getRequestMap() is not the correct method. Which one is the correct method? Thanks.
 
seb petterson
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Daniel Gee:
... the getRequestMap() is not the correct method. Which one is the correct method? Thanks.



See my previous post
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I went to read about what getRequestParameterMap() does. It does not seem to do what I intend to achieve (I can be terribly wrong.)

I intend to get the JavaBean that represents the current row I am hitting in a JSF dataTable.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For what you are trying to do, getRequestParameterMap is not the correct function.

What is? It depends on your context. I'll assume you are running this from an action method on a bean? For example...



The java code...



I think you could also write your action method on your PersonnelBean and work from there if you were linking in your table, but I'll leave that for somebody else. I think you're safely out of the request map function area.

BTW, I'm fairly new, so somebody please step in and clomp all over this if its inaccurate.
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe I should post my code for people to understand what I am really trying to do. I have a dataTable. For each row in that table, there is a checkbox. My backing bean will select the row or rows for which the checkbox is/are marked by an user.

The syntax error occurred at which I try to get the JavaBean of the "checked" row. E.g.

Here is the JSF showing in the browser:
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OKay, the problem has been resolved. I am missing getExternalContext() in the chain.
 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does that code work? I don't see how it would.

MailBean mailBean = (MailBean)FacesContext.getCurrentInstance().getRequestMap().get("mailBean");

Unless I'm way off, this will always return the same thing in your loop, and I highly doubt it'll be an instance of 'MailBean'. The request map is the collection of request parameters from the browser. Yes?

I think something like the following would work better:



The checkbox code would have to look like...

<h:selectboolean_checkbox id="selected" binding="#{mailBean.selected}"/>

I guess that's it. Were I implementing this, I don't think I'd try to use the binding and interface objects. Let JSF set the values on your MailBean objects directly and just use them.
 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I think it would be...

<h:selectboolean_checkbox id="selected" value="#{mailBean.selected}"/>
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I mean is I should change the code to:


note that I missed the getExternalContext() in my previous posting. What do you think?
 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, I know what you meant. I'm saying that I don't see how that would work. The experts will have to correct me if I'm off, but

FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("mailBean");

is essentially the same as...

request.getAttribute("mailBean")

Who's putting the value into the attribute? 'table.setRowIndex(index);'? That is beyond my understanding of JSF, but I'd bet that doesn't work. If it does, I still think its far more complex and strange than it needs to be.
 
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, thanks for your reply. I am trying to get all the data from the submitted table.

What is the type of

MailsForm.getMails(); ?

Because "mails" is a List.

I am having difficult time with "type casting" in this statement:


List is not consistent with DataModel. and the next statement:
 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DataModel is the wrapper for table data is JSF. If you get a chance, read up on it. In situations where you need to select a particular row, for example, DataModel comes in handy.

In your case you can pretty easliy use List directly...

 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now, looking at your last post, I have another concern:



Is 'getMails' a static method on the MailsForm class? That's trouble. You won't have any problem while developing because you won't have more than 1 user. With multiple users you'll have problems.
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Huh? Sorry, I am lost. In fact, I never understand


The managed-bean-class that feed the data to my original <h ataTable ..> is MailsForm.java and "mails" is the List that contains all the data to populate all the rows and columns of that table. I use mailsForm as the managed-bean-name. Maybe, I should show you the managed-bean-class to make sure that we are using the same terms:



Therefore, when I display my original table, I coded:


Now, the above table is submitted for processing. I am trying to retrieve all the selected records from that submitted table. I cannot compile code with the code below:


Another question is that "selected" is a boolean property on my MailBean that can be used to mark which messages have been selected. Therefore, to test whether the message gets selected, I should code:

get an instance of the MailBean and name it mailBean, and then


instead of


What are the mistakes that I have made. I really want to learn from this exercise.
 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you'll have to repost your code. I'm getting lost.

I looked up at your jsp code, and you need to set the value property on your checkbox rather than your binding property. Also, where are you putting your 'delete' method. It would make more sense on the mailsForm than the 'mybean' where I had put it.

Anyway, please post the code in more detail.
 
JiaPei Jen
Ranch Hand
Posts: 1309
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your attention and help first. In fact, the MailsForm and mails are the names I made up for asking questions on this forum. I am working on "personnel".

managed-bean-class: ListAction and managed-bean-name: listAction

I manually typed in some data in the ListPersonnel.java class. Eventually, I am going to get real data from receiving an iBatis object.

and the PersonnelBean.java looks like:

and my JSF dataTable gets created:


the action="SelectAction.updateDeparturePersonnel" will invoke the class shown below. And this is the class I have problems with:

Problem 1. Retrieve all submitted data in the table displayed above
Problem 2. The "testing" of whether checkbox of each row of the table is selected or not is not working properly.



And I have to use the List "departurePersonnel" to display another <h ataTable ...> in the browser.

Sorry for the pain that inflicts on you.
 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Now I see. Please don't take offense, but I think you should revisit some JSF concepts. You are going to be a little lost until you get that sorted out (I was in the same boat a couple weeks ago). However, I think I can get this cleared up. At least "working" and you'll have to fill it out from there.

In general, I think you're in Struts mode. You have 2 separate 'Action' classes. What you really need is one bean class for this operation. I've kind of merged the 2 and created 'PeopleManagementBean'.

Also, the action method was returning a List. To who? The signiture of action methods is no arg and returns a String.

Anyway...

*** PeopleManagementBean ***


As for the front end, that was a little closer to the mark. The important difference is the change I made to the checkbox. Also, your commandButton didn't have the #{} stuff, so it wouldn't have executed anything. I also changed that to point to listAction.



The important concept here is that the updates you make in the table (to the checkboxes) will be pushed directly to your PersonnelBean objects in the list 'peopleManagementBean.personnel'. Just go directly to that and use it.

I didn't do anything with the 'departurePersonnel' List. You'll have to deal with that in the class. It just builds the list and leaves it there.

Hope this clears things up.
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right. I did a couple of web applications using the Struts. Presently, I am working on two applications; one uses the Struts framework and I am learning JSF to code the other application.

I am not offended. I simply read a JSF book for about a week. I certainly have a lot to learn.

The front end xxx.jsp (coded in JSF) will navigate to yyy.jsp after the

is invoked. The yyy.jsp will use the List departurePersonnel to display another table in the browser window. That is to say,

I still have problems with

I declare �selected� as primitive boolean in my PersonnelBean and have a pair of get and set methods for that property. I typed and fed some data to populate the PersonnelBean:


The compiler complains about the in the <h:selectBooleanCheckbox �> tag and the in the PeopleManagementBean class.

I am on the east coast of the U.S. It is 8:40 pm now. I am going to test the code some more tomorrow morning.

In the "detailed" code that you saw, I put a "selected" boolean property on my "Personnel" bean that can be used to mark which persons have been selected for departure.

I initially did not have a boolean "selected" property on the "Personnel" bean. At that time, I tried to bind components into the backing bean. Therefore, I posted a question regarding

Sorry for the confusion that I caused.
 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing you need to add 'isSelected' instead of 'getSelected' for a primitive boolean.

I was thinking of changing that reference...

if ( personnelBean.selected ) { � }

but I figured I'd change as little as possible. You should call your accessor method, or change 'boolean selected;' in PersonnelBean to be public (hint: use the accessor method).
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The "checkbox" problem is resolved. I would like to post the code for others to know how to do it. Like you said, "isSelectedPersonnel" should be used instead the "getSelectedPersonnel". Please note the specification in bold.

Then in the xxx.jsp coded in JSF, we must add an attribute 'onClick' in the h:selectBooleanCheckbox tag; otherwise, the compiler does not like it:

I still have problem with the method "updateDeparturePersonnel()". The action button of the xxx.jsp


where departure is the name of the managed bean in my configuration file:

took me to that method; i.e. updateDeparturePersonnel();
However, I got run-time ClassCastException when hitting the updateDeparturePersonnel(); method in the DepartureManagementBean.java. And I am unable to see the coding problems.


java.lang.ClassCastException
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
javax.faces.component.UICommand.broadcast(UICommand.java:312)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)


Here is my DepartureManagementBean.java:
 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your updateDeparturePersonnel method is returning a List. I needs to return a String. The string is used for the navigation...

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSFIntro5.html#wp116912

See the last paragraph of that section. It starts with...

"The outcome can also come from the return value of an action method in a backing bean."

That's what you're doing. You need to return a string from your method. If you need access to your List, its in your managed bean which is in the session, so just grab it from somewhere else.

The ClassCastException is probably coming from JSF trying to cast your List to a String.

Now, just a question. I'm not sure it "matters", but why 2 managed beans of the same type?
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have made revisions of the DepartureManagementBean.java accordingly. The ClassCastException problem is gone. But, another runtime error occurred.

The action button of the first web page (successfully displayed) is

I clicked on the button, the runtime error is MethodNotFoundException:


javax.faces.FacesException: #{DepartureManagementBean.updateDeparturePersonnel}: javax.faces.el.MethodNotFoundException: updateDeparturePersonnel
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
javax.faces.component.UICommand.broadcast(UICommand.java:312)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)


Here is the up-to-date code:
 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right now your action param is...



Assuming your managed bean declarations are the same as before your action param should be...

 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried


and when I click on the DEPART button, nothing happens. I do not even see an error message. The first web page remains on the screen.

I have also tried

Again, nothing happens when I click on the DEPART button. No response at all.

You are right. In fact, I do not need two "managed-bean-name, managed-bean-class" specification in the faces-config.xml file. I also tried only one specification. The same thing happens - no response.

at least gives MethodNotFoundException.

It does not hurt to try again. But, the outcome may be the same.

Sorry for bothering you this much.

[ September 02, 2005: Message edited by: Daniel Gee ]
[ September 02, 2005: Message edited by: Daniel Gee ]
 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. I think this is again where you need to hit the books. You need to return a string from your function. That string needs to match up with a navigation rule 'outcome', which will then forward you to another page.

Lets say your list page is 'departureList.jsp' and you want to return to your home page, 'home.jsp'. In your action method, return "success" if everything works out ok. Add the following to your faces-config.xml.

<navigation-rule>
<from-view-id>/departureList.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/home.jsp</to-view-id>
</navigation-case>
</navigation-rule>

If you return a string but you don't have a navigation rule associated, it'll just show the page again.
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that I should fix my faces-config.xml file. However, the same story repeated. When I tried

I have no response. I still see the first web page on the screen after clicking on the DEPART button.

gives me the MethodNotFoundException.

Here is my up-to-date faces.config.xml file:
 
Kevin Galligan
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The url for the page you're on is '/pages/arrivedPersonnelList.jsp'? If so, returning 'success' from your action method should push you to '/pages/departurePersonnelList.jsp'. This is the correct sequence? It should work, so restart your server, doublecheck everything, etc.
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have shut down the server and tried a couple of times. I am pulling my hair.

I feel like posing all the code again including the faces-config.xml file.

My first page is welcome.jsp:

The second page is arrivedPersonnelList.jsp. Note that I am unable to post on this forum by inserting that attribute that toggles the marking of the checkboxs in the code, but that attribute is needed:

Hopefully, I will be able to see the third page soon, which is departurePersonnelList.jsp:

The management bean is DepartureManagementBean.java in the processAction folder:

The files that assist the creation of the List personnel are in the processDelegate folder:

and the PersonnelBean.java:

and my faces-config.xml file is:

The last one is my web.xml file:
 
Daniel Gee
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kevin, my first experiment of JSP has been tested successfully. Thank you for holding my hands to go through it. During the process, I had to adjust some concepts and tune myself to this new technology.

On Friday, I did not know the JSF code actually worked. That afternoon, I shut down and re-started the server many times. The DEPART button did not respond to my clickings at all. I was too frustrated to stay in office. I brought all the JSP, Java Class, and configuration files home.

At home, I simply copied all those files and re-ran the application. No problem!

I found that sometimes I must shut down my PC (shutting down the server only is not enough). Somehow, PC can cache something somewhere and the outdated specifications simply do not go away.

I truly appreciation your help. Thanks a lot again. I could not have completed my first exercise without you.

My complete code is posted. Maybe others who are new to JSF can take a look at the discussions and save some effort.
[ September 05, 2005: Message edited by: Daniel Gee ]
 
Don't touch me. And dont' touch this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic