Accessing property of one managed bean to another in request scope
Right now my applications managed beans are in session scope.
I want to change them to request scope .But the problem is how to access the bean methods to another if they are in request scope
Use RequestMap instead of SessionMap.
Having multiple and independent managed beans in the request scope for 1 request and the need to access the other bean is somewhat odd design however. You may need to rethink about it. For example, add one of the beans as property of the other bean.
Similar Messages
-
Setting the property of a managed bean
Hello,
I have just started working on a project that I would like to use Java server Faces. I am very new to JSF so please forgive the question if it is too obvious.
We are doing a login form with a username, password and key. The key is an image that contains randomly generated characters that the user needs to type in what is in it to verify that it is a human and not an automated system trying to log in.
So my loginForm managed bean contains four properties (get/set) username, password, key, userkey (this is what the user types in and needs to equal key for the login to work).
The user will enter in (using <h:inputText />) the username, password and userkey but I need to know how to set the key to the randommly generated characters that I used to create the image with.
I know I can use <h:inputHidden /> to set the value but that would defeat the purpose because an automated system could read the page an know what the image contains (because the value would be in the HTML code sent to the browser).
The random characters and the image is generated in a servlet and the key is set in a session variable.
How can I take that session variable that contains the key (characters randommly generated) and put it in my managed bean so I can verify that the user entered the correct information?
I have been searching on Google all morning. I probably do not know what to put in for the search to get the correct information out.
Thanks in advance for any help you can provide.
JonSince your key is already in a session variable, you don't really need to make it a property of your managed bean, but just access it directly. For example, you could have a property called "keyCorrect" with a getter something like this:
public boolean isKeyCorrect()
String key = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("key");
return getUserKey().equals(key);
} -
One Managed Bean for a set of pages
Can I have one Managed Bean (request scope) for a set of pages using Creator? Or should I have one Managed Bean for each page?
Thanks in advance,
JuanHi,
Please take a look at the following threads:
http://swforum.sun.com/jive/thread.jspa?forumID=123&threadID=51481
http://swforum.sun.com/jive/thread.jspa?forumID=123&threadID=54165
http://swforum.sun.com/jive/thread.jspa?forumID=123&threadID=51912
Hope this hepls
Regards,
Rk. -
Af:table requires the managed bean to be in session scope?
I have let to figure out why af:table requires the managed bean to be in session scope if the af:table has the rows attribute set to anything else but zero.
I'm assuming that in order for the table to hold on and "page" through the range of records that it is a requirement...
Any details on how the under-pinnings really works, would be appreciated.
Thanks,
--ToddTodd,
If you create a table model that you reference from an EL on the table's row variable then this should work with request scope as well. However, I think the problem you would run into is
- performance because the values are getting fetched with every page load
- state, because you would have to persist any change immediately to ensure the next query brings up the change values
Frank -
How do I use a managed bean in another managed bean
I have two managed beans. One is backing bean for a form and the other is used to access a database table.
1st bean
public class TestDBAO
@PersistenceContext
private EntityManager em;
public void addEntry(PersonObj person)
em.persist(person);
public class formdata
private String id;
private String fname;
private String lname;
getter functions
setter functions
public String submit()
in here i want to call addEntry function from TestDBAO
How can I achieve this or is there another way to do this?Do I understand correctly that you have definied TestDBAO as a session scoped managed bean? Why?
You don't need that. Just create and call TestDBAO in the backing bean. Or if you want only one instance of TestDBAO during the session, then create a singleton constructor and eventually make the methods static. -
Access session values in Managed Bean
I want to acces session attribute values in my Managed Bean class.
This is my code in SecurityPhaseListener.java class,
HttpSession session = (HttpSession)facesContext.getCurrentInstance().getExternalContext().getSession(true);
String isAuthorized = "false";
session.setAttribute(isAuthorized, isAuthorized);
This is my configuration for My managed bean in faces-config.xml class
<managed-bean>
<managed-bean-name>setNewDayBean</managed-bean-name>
<managed-bean-class>com.hli.vipstar.uswm.setnewday.managedbean.SetNewDayBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Now i want to access the attribute "isAuthorized" in my managed bean SetNewDayBean.java.
How to do this?
Any one help me...........The same way, but then using getAttribute() instead of setAttribute().
Another -more clean- way is to use the ExternalContext#getSessionMap(). It will make your code independent from the session implementation used. You may find this article useful as well: http://balusc.blogspot.com/2006/06/communication-in-jsf.html -
Cannot get reference to a managed bean from another
After reading one of BlausC article:
http://balusc.blogspot.com/2006/06/communication-in-jsf.html#AccessingAnotherManagedBean
I always get null when I try to get a reference to a session scoped managed bean from a current bean:
Here is part of the faces context config file:
<faces-config>
<managed-bean>
<managed-bean-name>approvalManagementBean</managed-bean-name>
<managed-bean-class>com.waseel.waseele.presentation.approval.management.ApprovalManagementBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>configService</property-name>
<property-class>com.waseel.waseele.business.config.ConfigService</property-class>
<value>#{configService}</value>
</managed-property>
<managed-property>
<property-name>approvalService</property-name>
<property-class>com.waseel.waseele.business.approval.ApprovalService</property-class>
<value>#{approvalService}</value>
</managed-property>
<managed-property>
<property-name>claimManagementService</property-name>
<property-class>com.waseel.waseele.business.claim.management.ClaimManagementService</property-class>
<value>#{claimManagementService}</value>
</managed-property>
<managed-property>
<property-name>codedValuesLoaderServices</property-name>
<property-class>com.waseel.waseele.business.claim.extraction.loader.codedValuesLoader.CodedValuesLoaderServices</property-class>
<value>#{codedValue}</value>
</managed-property>
<managed-property>
<property-name>approvalSubmission</property-name>
<property-class>com.waseel.waseele.business.approval.submission.ApprovalSubmission</property-class>
<value>#{approvalSubmission}</value>
</managed-property>
<managed-property>
<property-name>payerTpaRelationService</property-name>
<property-class>com.waseel.waseele.business.payerTpaRelation.PayerTpaRelationService</property-class>
<value>#{payerTpaRelationService}</value>
</managed-property>
<managed-property>
<property-name>payerTpaFiller</property-name>
<property-class>com.waseel.waseele.business.payerTpaRelation.PayerTpaFiller</property-class>
<value>#{payerTpaFiller}</value>
</managed-property>
</managed-bean>and part of my code:
public String displayApprovalInEditMode()throws Exception{
//This is cross-managed been access; I need to get the current Approval in the approval management been
ApprovalManagementBean appMangBean=(ApprovalManagementBean) FacesContext.getCurrentInstance()
.getExternalContext().getSessionMap().get("approvalManagementBean");What possible problems may be?
Can any one tell when these session managed beans object get created? is it at start up? or when loading a JSF page that use a bean ?
becasue this code work in places while not in anotherYou must be doing something wrong. I cannot reproduce this problem with the following SSCCE on JSF 1.2_13 at Tomcat 6.0.20.
Bean1package mypackage;
public class Bean1 {
private Bean2 bean2;
public boolean isBean2Present() {
return bean2 != null;
public Bean2 getBean2() {
return bean2;
public void setBean2(Bean2 bean2) {
this.bean2 = bean2;
}Bean2package mypackage;
public class Bean2 {
}JSF<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<f:view>
<html>
<head>
<title>Test</title>
</head>
<body>
<h:outputText value="Is bean2 present? #{bean1.bean2Present ? 'yes' : 'no'}" />
</body>
</html>
</f:view>faces-config<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
version="1.2">
<managed-bean>
<managed-bean-name>bean1</managed-bean-name>
<managed-bean-class>mypackage.Bean1</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>bean2</property-name>
<value>#{bean2}</value>
</managed-property>
</managed-bean>
<managed-bean>
<managed-bean-name>bean2</managed-bean-name>
<managed-bean-class>mypackage.Bean2</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>It prints 'yes'. -
Error calling Method on Managed Bean from another Managed Bean
Hi
(Jdev 11.1.1.2.0)
Help please:
I have a managed bean (page flow scope) which is used by my main page for dynamic region flow navigation:
*public class RegionNavigationBean implements Serializable{*+
private String dynamicTaskFlowId = "/WEB-INF/home-task-flow-definition.xml#home-task-flow-definition";+
*public RegionNavigationBean() {*+
*public TaskFlowId getDynamicTaskFlowId() {*+
return TaskFlowId.parse(dynamicTaskFlowId);+
*public void setDynamicTaskFlowId(String taskFlowId) {*+
this.dynamicTaskFlowId = taskFlowId;+
taskFlowId property on main page def is set to +*${pageFlowScope.regionNavigationBean.dynamicTaskFlowId}*+
In a DB table (i.e. View Object on my model layer) I store a menu ID and a corresponding task_flow_id.
Then I have created an action listener class (RegionNavigationListener - page flow scope) which I link to my menu items on my main page (action listener property on menu item = +*#{pageFlowScope.regionNavigationAction.processAction}*+ )
In this action listener (processAction method), I retrieve the row set from the menu VO and find the record which matches my menu ID which caused the action event, thereby retrieving the task_flow_id which must be navigated to.
I then try to retrieve the instance of the RegionNavigationBean with the following statement: RegionNavigationBean regNav = (RegionNavigationBean)JSFUtils.getManagedBeanValue("regionNavigationBean");+
This seems to work fine, but as soon as I try and use this I get NullPointerException error, e.g.:
regNav.setDynamicTaskFlowId(menusRow.gettaskFlowId());+
or even:
System.out.println("%%% " + regNav.toString());+
This is all quite new to me... any help would be appreciated!
Thanks
MarioHi Mario,
I think JSFUtils.getManagedBeanValue(String) has difficult to evaluate the "regionNavigationBean" managed bean.
What JSFUtils.getManagedBeanValue(String) do is important. I remember that "JSF scoped" bean can be found by JSF style find method, such as requestScope, sessionScope, applicationScope. For a managed bean put in these scope, scope prefix is not needed, for example: using #{beanName} to locate a requestScope bean. The #{requestScope} prefix is not needed.
But pageFlowScope is different. If a bean is put in the pageFlowScope, you must use #{pageFlowScope.beanName} to locate it.
Say, ManagedBean is the java class of your manged bean.
FacesContext ctx = FacesContext.getCurrentInstance();
Application app = ctx.getApplication();
ManagedBean mb = (ManagedBean)app.evaluateExpressionGet(ctx, "#{pageFlowScope.managedBeanName}", ManagedBean.class);
Hope it helps.
Todd
Edited by: Todd Bao on Nov 26, 2009 9:58 PM -
Managed Bean "Name" Access with in the Managed Bean
Hi,
I have faces-config.xml in which I have registered a managed bean
and I have a base class for all the managed bean.
The JSP's invoke the action/method defined in the base bean and I want to remove the managed bean from session upon a particular event.
To remove the managed bean from session, as far as I know - we need to know the managed-bean-name in the faces config.
I wanted to know if there is any way to get the name of the managed bean in the faces-config.xml at run time?.
Thanks,Thanks for your recommendations. The issue that I get stuck on is how to call this method that retrives employee data. When I had the code in the constructor, it executed when I accessed the view.jsp page. Then I populated the fields from the Employee class fields. But once I create non-constructor method, how do I invoke it from my JSF page.
-
Accessing the ViewRowImpl in Managed Bean
Hi,
I am having the requiredment like setting the data to view object based on some conditions. Here after setting the data to a view object, i dont want to make my transaction as dirty, so am using the populateAttribute. since am setting the single attribute am planing to get the ViewRowImpl and want set the data in my managed bean instead of writing the service method in viewImpl.
is it the good approach to get the viewRowImpl in managed Bean.. Please suggest...
Reg,
Brahma B.Hi Frank Thanks for your reply...
Here i will create a record before loading the screen in add mode for accepting the user input. after creation of the record i will set some data programatically(the data may be usefull for dropdown which i attached to the a perticular column).
Reg,
Brahma B. -
Java.lang.IllegalStateException: bean not found in "request" scope
In jsp,I use javaBean,the statement is following:
<jsp:useBean id="collectionBean" scope="request" type="view.CollectionBean"/>
but ,in runtime,there exist following mistakes:
java.lang.IllegalStateException: bean "collectionBean" not found in "request" scope
at basicContentSearch.jspService(basicContentSearch.jsp:8)
[SRC:/basicContentSearch.jsp]
at com.orionserver[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:349)
at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509)
at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:778)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
at com.evermind[Oracle Application Server Containers for J2EE 10g (9.0.4.0.0)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
at java.lang.Thread.run(Thread.java:534)
why?
Please everyone tell me if you can,thanks a lot.I believe, if it is the first time you are referring to the bean, you must use the class attribute rather than type:
<jsp:useBean id="collectionBean" scope="request" class="view.CollectionBean"/>The type is used to change how the bean is referenced, for instance, in regular Java you might do this:
// The Type The Class
java.util.List myList = new java.util.ArrayList();In use bean you would do this:
<jsp:useBean id="myList" class="java.util.ArrayList" type="java.util.List"/> -
How do you move an access app from one sharepoint subsite to another?
Hi there!
I have created an access app for my 'Account management' subsite. This database stores lots of important information, however I'd like to move this to a new subsite which I've created called 'Campaigns'. How do I do this? I literally want to take a copy
of it with all it's contents and move it to a new subsite.
Thanks!
SarahHi Sarah,
You can go with backup & Restore option.
In Powershell:
use this below commands,
Backup-SPSite <site URL> -Path "Path Location" -Force
<site URL> --> http://server_name/sites/Account management (which site you want to take backup)
"Path Location" --> C:\Backup\site_name.bak(where you want to store the backup)
Restore-SPSite <site URL> -Path "Path Location" -Force
<site URL> --> http://server_name/sites/Campaigns (where you want to move the site)
"Path Location" --> C:\Backup\site_name.bak (where you have the backup file)
otherwise you can Go with remane the subsite.
Vote me, if its helps you. Regards, Tamilarasi. -
How do I access data from one user account to another?
I want to access data from a different user account. How do I make all the files available?
I have another post here in the forum that explains in detail about the rez problem. It was read by a lot of people with no responses. 1 thing that might be important is that I was using a Wacom drawing tablet when this problem started. I removed the Wacom software and no help.
My Apple 23" Cinema display has very large icons but the display prefs says it is at 1920 x 1200. It's not just a low screen rez but the dock and all icons will scroll on the screen when I move the mouse.
The resolution will not change to anything else. The rez is fine on other user names.
I have booted from the Apple DVD and run disk repair, repaired disk permissions. Booted and run Tech Tool.
Booted from the Disk Warrior cd and ran that.
I have zapped the PRAM. I have plugged the display into the other port on the video card.
When I change to the problem user name it is fine for about 1 second and then changes to the "problem". I have never seen this before and I have been using a Mac since 1990.
It's a G-5. Dual 2.0 ghz. 2.5 gb ram. OS 10.5.8. Apple keyboard. Logitech mouse and
Thanks. -
How to access ouput of one async process in another async process
Hi
I have two asynchronous processes.In the second process i would get all the data of a particular purchase order. how do i need to access this information in first process. when i do an invoke acitivity it's not generating any o/p variable .pls help me out on this
thanks
raviYou need to put a "Receive" activity where you want to receive you asynchronous answer and link it to your partner link. Then you'll be able to create an output variable.
Have fun! -
Accessing cookies from one portal page to another page
hai Oracle Expects,
I have 3 pages in Portal 3.0.8-Oracle 8.1.7.
I have some problem in the cookies.
I will be thankful if your help me to
solve my problem.
The first page get the username and password
through a procedure based portal form.
Then it will check the username and password
with the table and redirects to a corresponding page,if the value is correct. In the second and the third page i need the username and password. For that i used cookies to retrive. But some time it works and some times it wont works. I feel the coding which i used is with bugs.
If you tell me how to write the cookies
and to retirve the cookies in the forms i will try that and it will be the solution for my problem. I am expecting your reply .
Thanks & Regards
Ramesh.G
nullRamesh,
This is the forum for Portal Content Areas. Please post your question on the PDK forum.
However, you will likely find the information you're looking for in the white paper Portal Management of Provider Sessions.
Regards,
Jerry
Maybe you are looking for
-
I have a very big list of correspondents to whom I often send articles. I cannot copy them from Firefox and paste them onto Apple Mail because they look WEIRD and not at all like the original. Most formatting disappears. I do not encounter the same p
-
Hi all, I need a possibility to <b>convert Web Reports</b> designed in WAD <b>into PDF</b>. SAP help portal says: 'You access BEx Web applications and reports in the portal. You can then convert these into PDF files and print them.' (http://help.sap.
-
ADF Faces - Weblogic: Problems about rendering ADF pages
Hi! We have an application that we have generated 2 EAR for installation with 2 different contexts (consequently, it have 2 different address), and after the installation, the main page of an application is showing correctly and the other application
-
Low Volume Ipod Classic 2009 from USA?
Hi, I just purchased the new Ipod Classic in October in New York City at the Apple Store. Now, back at home in Switzerland, I loaded the Classic via Itunes. Now I have the feeling that the Classic has a much lower volume than my old 5.5G Ipod Video (
-
Would this hard drive be compatible with a Compaq Presario CQ50-115NR?
I'm wondering if this hard drive would fit in and be compatible with my laptop: http://www.wdc.com/en/products/products.asp?driveid=684 I'm not sure if this 12mm, 2.5 inch drive would fit in it or be compatible with it. I plan to purchase this one if