Set value of bean objects inthe other beans
Hi
i have a session scope bean "mySessionScopeBean" . in this bean i have a String value .
Now How can i set its value from other beans .
I searched and find this stufff code for get value :
Map<String, Object> viewScope =AdfFacesContext.getCurrentInstance().getViewScope();
String username = (String)viewScope.get("userName");
is this code true ?
is this code true ?
Well did you tried it?
Session scope is obviously different than view scope so you can't use this code.
Instead you can try with:
MySessionScopeBean yourBean = (MySessionScopeBean)ADFContext.getCurrent().getSessionScope().get("mySessionScopeBean");
String username = yourBean.getUsername(); // of course, if you have getter for username attribute.
Dario
Similar Messages
-
How to set value from one view to other view's context node attr b4 save
HI all,
My requirement is as below:
There are two views in component BP_CONT.
BP_CONT/ContactDetails IMPL class
BP_CONT/SalesEmployee SALESEMPLOYEE STRUCT.SALESEMPLOYEE
I want to set value from first view to second view's context node's attribute.
i get Sales Employee BP number in ContactDetails view, from here i want to set that value in to STRUCT.SALESEMPLOYEE
of second view in the same component.
please send me code snippet for doing the same.
Thanks in advance.
seemaHi Seema
You can access the fields from different views by either using custom controllers or by using component controllers, in your case you can access the Sales employee BP number from the Component controller.
first access the component controller as below in BP_CONT/SalesEmployee (in do_prepare_output method) or in (specific setter method)
lv_compcontroller type ref to CL_BP_CONT_BSPWDCOMPONENT_IMPL,
lv_partner type ref to cl_crm_bol_entity,
lv_role type string,
lv_partner_no type string.
lv_employee TYPE REF TO if_bol_bo_property_access,
lv_compcontroller = me->COMP_CONTROLLER.
lv_partner ?= lv_compcontroller ->typed_context->-partner->collection_wrapper->get_current( ).
lv_role = lv_partner->get_property( iv_attr_name = 'BP_ROLE' )
IF LV_ROLE = 'SALESEMPLOYEE'
lv_partner_no ?= lv_current->get_property( iv_attr_name = 'BP_NUMBER' ).
endif.
now set the value
lv_employee ?= me->typed_context->salesemployee->collection_wrapper->get_current( )
CHECK lv_employee IS BOUND.
lv_employee->set_property( iv_attr_name = 'SALESEMPLOYEE' iv_value = lv_partner_no )
Thanks & Regards
Raj -
Jsp:usebean How to get value of an object from a bean
I am new to JSP and am struggling from past few days to solve a problem. Consider the below scenario
Class Book{
private String author;
public void setAuthor(String author)
public String getAuthor(){
return author; }
Class Rack{
private Book []books;
public []Book getbooks()
return books;
public void setbooks([]Book val){....}
Suppose Books gets populated only using Rack and I have Rack populate in my session, using jsp:usebean or any other tag how can I get value of author? Does using tag handle null value check of books, if books are not set by any chance?
Regards,
DhyanI got a way out to access the attribute, i feel it is
<jsp:usebean id="myRack" class="settings.Rack"/>
<c:foreach var="book" item="myRack.books">
</c:foreach>
I am not able to check if this is correct or not because myRack.books is not having any value set by me in the request scope. How do i get instance of Rack class set by another page in the current request? I can get the value if i use scriptlet but i dont want to use scriptlet.
I am continiously trying, if I get an answer, I shall post, else pls somebody guide. -
UIX Problems Trying To Get and Set Values To messageTextInput Objects
I have created an input UIX form in the Struts Page Flow Diagram using the Page Forward Action and dropped two views from the Data Control Applet as Input Forms. I am trying to �get� the value from one bound messageTextInput object in view1 to set the value of another bound messageTextInput object in view2. I do not know how to reference the bound messageTextInput objects on the UIX page.
Any suggestions?
Thank you,Hi Alain,
Initially it is little bit confusing.
To get the value:
wdContext.node<nodename>().get<nodename>ElementAt(i).get<Attribname>();
To set the value:
wdContext.node<nodename>().get<nodename>ElementAt(i).set<Attribname>("value");
First check the cardinality of the node.If the cardinality is 0..1 or 0..n then you need to create an element and add it to the node.
IPrivate<viewname>.I<node>Element ele = wdContext.create<node>Element();
ele.set<attribname1>("value");
ele.set<attribname2>("value");
wdContext.node<nodename>().addElement(ele);
If the cardinality is 1..1 or 1..n then 1 element is created by framework. You can use that element. If you want to add more elements just use the above code.
2.IWDAttributeInfo attInfo= wdContext.node<Node>().getNodeInfo().getAttribute(<Attribname>)();
check this link
https://www.sdn.sap.com/irj/sdn/nw-wdjava?rid=/webcontent/uuid/503f22f6-b978-2a10-bf97-ddc21267e752 [original link is broken]
regards,
Siva -
Getting and setting values of an object
Hi,
I currently have a method which calculates some ints, then stores them as attributes of an object. However I am having trouble when retrieving these values. My problem is that I am putting correct values in, but the values coming out are different.
The code to put the numbers in is:
for(int u = 0; u<level; u++){
Y = divV + Y;
divH = 720/(levWidth[u]+1);
for(int k = 0; k <levWidth; k++){
X = X +divH;
nodes[k].setXY(X,Y);
X = 0;
The line nodes[k].setXY(X,Y); calls the following method in another class which has been initialised and stored in the array nodes[].
import java.io.*;
import java.io.DataInputStream;
import java.io.PrintStream;
import java.net.*;
import java.util.*;
public class Person{
String Forename;
String Surname;
String Num ;
int Father ;
int Mother ;
int Partner ;
int x;
int y;
public Person(){
Forename = "";
Surname = "";
Num = "";
Father = 0;
Mother = 0;
Partner = -1;
x = 0;
y = 0;
public Person(String Num2, String Forename2, String Surname2){
Forename = Forename2;
Surname = Surname2;
Num = Num2;
Partner = -1;
public void setXY(int x2, int y2){
x = x2;
y = y2;
public int getX(){
return x;
public int getY(){
return y;
The values of X and Y before they are passed in are correct, however when when the getX and getY methods are called the ints returned are totally different and include a lot of zeros at the end. The code used to test this is:
for(int n = 0; n<length; n++){
int getx = nodes[n].getX();
int gety = nodes[n].getY();
System.out.println(getx + " " + gety);
I don't understand what is wrong here and why the ints are changing so drastically.
Help please!!!??Hi,
I currently have a method which calculates some ints, then stores them as attributes of an object. However I am having trouble when retrieving these values. My problem is that I am putting correct values in, but the values coming out are different.
The code to put the numbers in is:
for(int u = 0; u<level; u++){
Y = divV + Y;
divH = 720/(levWidth+1);
for(int k = 0; k <levWidth; k++){
X = X +divH;
nodes[k].setXY(X,Y);
X = 0;
The line nodes[k].setXY(X,Y); calls the following method in another class which has been initialised and stored in the array nodes[].
import java.io.*;
import java.io.DataInputStream;
import java.io.PrintStream;
import java.net.*;
import java.util.*;
public class Person{
String Forename;
String Surname;
String Num ;
int Father ;
int Mother ;
int Partner ;
int x;
int y;
public Person(){
Forename = "";
Surname = "";
Num = "";
Father = 0;
Mother = 0;
Partner = -1;
x = 0;
y = 0;
public Person(String Num2, String Forename2, String Surname2){
Forename = Forename2;
Surname = Surname2;
Num = Num2;
Partner = -1;
public void setXY(int x2, int y2){
x = x2;
y = y2;
public int getX(){
return x;
public int getY(){
return y;
The values of X and Y before they are passed in are correct, however when when the getX and getY methods are called the ints returned are totally different and include a lot of zeros at the end. The code used to test this is:
for(int n = 0; n<length; n++){
int getx = nodes[n].getX();
int gety = nodes[n].getY();
System.out.println(getx + " " + gety);
I don't understand what is wrong here and why the ints are changing so drastically.
Help please!!!?? -
Set value to attribute created in other enh. point by SAP
Hi all,
I'm modifying a standard component, I've created an enhancement point and a post-exit in some methods. Within this methods I want to read/modify the value of one attribute that is created in other enhancement point by SAP.
I've tried to read this value using the code wizard but when I try to use it the following message is displayed:
"This element cannot be selected in enhancement mode ZZZ..."
I've written the code by hand but when I try to activate it there is a syntax error, because don't find the type of this element...
I don't know if exits any way to do it.
Thanks in advance.
Regards,
Ricardo.Hi JhonSnow,
Thanks for posting in MSDN forum.
This issue would be better post to
windwos desktop debugging forum, I will move this issue to there for better support. Thanks for your understanding.
Best regards,
Shu Hu
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Setting the series color of a bi beans graph based on the data values
How do I conditionally set the series color of a bi beans graph based on the data values?
I am using the following code to get the data values and set the series color:
Graph gr=(Graph)CmdrDashboardP1_pres1.getView();
DataAccess da=gr.getGraphModel().getDataAccess();
DataDirector dd=gr.getDataDirector();
DataMap dm=dd.getDataMap();
int re=dd.ROW_EDGE;
int ce=dd.COLUMN_EDGE;
Object val=da.getValue(re,ce,dm.DATA_TYPE);
int seriesCount=da.getEdgeCurrentSlice(DataDirector.ROW_EDGE);
if (val <=45.0)
gr.getSeries().setColor(new Color(255,0,0),seriesCount);
I get a NullPointerException from the line of code "Object val=da.getValue(re,ce,dm.DATA_TYPE)." I have tried the code with DATA_UNFORMATTED as well, but get the same exception. When I print the DataMap value of dm the results are [dataUnformatted, dataViewFormat, value, dataIsTotal, dataType].
Also, I get the error "method <= (java.lang.Object,double) not found in class _CmdrDashboardP1" from the "if (val <=45.0)" code.
Thanks for any assistanceHow do I conditionally set the series color of a bi beans graph based on the data values?
I am using the following code to get the data values and set the series color:
Graph gr=(Graph)CmdrDashboardP1_pres1.getView();
DataAccess da=gr.getGraphModel().getDataAccess();
DataDirector dd=gr.getDataDirector();
DataMap dm=dd.getDataMap();
int re=dd.ROW_EDGE;
int ce=dd.COLUMN_EDGE;
Object val=da.getValue(re,ce,dm.DATA_TYPE);
int seriesCount=da.getEdgeCurrentSlice(DataDirector.ROW_EDGE);
if (val <=45.0)
gr.getSeries().setColor(new Color(255,0,0),seriesCount);
I get a NullPointerException from the line of code "Object val=da.getValue(re,ce,dm.DATA_TYPE)." I have tried the code with DATA_UNFORMATTED as well, but get the same exception. When I print the DataMap value of dm the results are [dataUnformatted, dataViewFormat, value, dataIsTotal, dataType].
Also, I get the error "method <= (java.lang.Object,double) not found in class _CmdrDashboardP1" from the "if (val <=45.0)" code.
Thanks for any assistance -
Set value of variable in one bean from another bean
Using JDeveloper 11.1.1.4, I thought this would be simple to do, but I haven't been able to figure out the correct syntax and am just learning java. In my view controller I have one bean set as pageflow scope, and another bean set as a request scope. How do I set the value of a variable in the first bean from the second bean? The first bean has setters and getters, but when I try to reference them in the second bean, it says it isn't allowed. The first bean looks like:
public class ViewAmtsParameters {
String asOfDateParam = null;
public void setAsOfDateParam(String asOfDateParam) {
this.asOfDateParam = asOfDateParam;
public String getAsOfDateParam() {
return asOfDateParam;
}Thanks in advance,
Troyfor ur reference: go through entire docs.
http://balusc.blogspot.com/2006/06/communication-in-jsf.html
Edited by: Erp on Oct 7, 2011 9:12 PM -
How to rebind a bean object programmatically in EJB 3.0
hi,
There is a bean object (EJB 3.0) which i want to rebind. How can I do it through another application running under same netweaver server.
For eg,
one session bean object is bound to "java:comp/env/Converter" jndi name by one application. Here, i need to modify this object and rebind to the same jndi name. so i used as follows,
context.rebind("java:comp/env/converter", beanobj );
//'beanobj' is the modified bean (modified attribute's value)
it was bound successfully, but when i look up the bean object, i got the ClassCastException,
like "java.lang.ClassCastException : $Proxy5_1001 at ......"
can anybody help me?
regards,
Panneer.@Vladimir Pavlov
I did not understand what you are trying to convey...
Whenever an attribute of this bean is modified we want to access that latest value.... Is there any way to know, when the attribute is modified? Just with get/set we can not know, when it is modified... am i right?
We want to achieve this without modifying the existing source code of the EJB....
@ Ivo Simeonov
As of my knowledge, to use interceptors we need to modify the EJB source code, but we do not want to touch the source code....
All this has to be achieved dynamically when the application is deployed in the production.... is it possible??? -
Setting dynamic values to entity object
Is there any way to set bean values (dynamic values) to Entity Object while commit the record, and how can i set these values using Groovy language
Thanks in advanceYou need to give more information about the version of Jdev you use and your use case. read more -
https://forums.oracle.com/forums/ann.jspa?annID=56 -
Retrieving Session bean object in a Servlet from FacesContext Object
Hi,
I added code in a servlet to retrieve Session bean object from the Faces Context object. I don't know what the problem was, but when I am accessing the application from two different machines and I am trying to retrieve the value from the session object in the servelet it is giving the value what I set into the session bean on one machine browser into another machine browser. Just I want to know the code which I had included in the servlet is correct or not.
This is the code I am using in my servelt:
1) To get the Faces context object
protected FacesContext getFacesContext(HttpServletRequest request, HttpServletResponse response) {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext == null) {
//System.out.println("Current context was null...creating one now");
FacesContextFactory contextFactory =
(FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
LifecycleFactory lifecycleFactory =
(LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
facesContext =
contextFactory.getFacesContext(request.getSession().getServletContext(), request, response, lifecycle);
//Set using our inner class
InnerFacesContext.setFacesContextAsCurrentInstance(facesContext);
//set a new viewRoot, otherwise context.getViewRoot returns null
UIViewRoot view = facesContext.getApplication().getViewHandler().createView(facesContext, "ContextName");
facesContext.setViewRoot(view);
return facesContext;
2) Code to get the session bean:
Utils utilsBean = (Utils) getFacesContext(request, response).getApplication().getVariableResolver().resolveVariable (getFacesContext(request, response), "utils");
Edited by: Ramesh_Pappala on Nov 8, 2007 9:25 AMRamesh_Pappala wrote:
Hi Raymond,
Thank you for the reply and can you please send the code No, I cannot do that.
what you are talking about to get the bean from session through servelet session map so that I can use that one check whether it is working fine in my application or not.
Thanks. -
How to use bean objects in java script
function insertRow()
var row=1;
var tbl = document.all("TAU");
var tr = tbl.rows(row);
var td = tr.cells(0);
var td2 = tr.cells(1);
var td3 = tr.cells(2);
row++;
tr = tbl.insertRow();
tr.setAttribute(false);
td = tr.insertCell();
td2 = tr.insertCell();
td3 = tr.insertCell();
td.innerHTML = "<html:text property='unit' value ='02' />";
td2.innerHTML = "<html:text property='unit Id' />" ;
td3.innerHTML = "<html:text property='unit Type' />" ;
this is my code, it is basicaly add row at run time thru java scripts. i want to set property of beans with this script , in this code i foun error ie. "can not found bean in nay scope" so plz anybody can tell me how can i pass bean object to java script !!!!!!mmmh i'm not understanding so much....
well... as i told before i'm working in oracle database environment and i'm developing a java procedure.
now, i have this object
CREATE OR REPLACE
TYPE REPORT.FATTURA_OBJ AS OBJECT (
POD VARCHAR2(1000),
ID_FATTURA NUMBER,
ID_FILE NUMBER,
COERENZA_EA_F VARCHAR2(1000),
COERENZA_ER_F VARCHAR2(1000),
COERENZA_EA_M VARCHAR2(1000),
COERENZA_EF_M VARCHAR2(1000),
ANOMALIA VARCHAR2(1000),
MOTIVO_INVALIDAZIONE VARCHAR2(1000),
MATRICOLA_CONTATORE VARCHAR2(1000),
POTENZA_DISPONIBILE VARCHAR2(1000),
MEMBER PROCEDURE pulisci
/and i need to work with it inside this procedure:
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED REPORT."Manage_Excel_ASMBS" AS
import java.io.*;
import java.io.IOException;
import java.io.StringWriter;
public class Manage_Excel_ASMBS
public static void read_Excel(String inputFile,int var_Id_Caricamento, int var_Id_Distributore, String var_Distributore) throws SQLException, IOException
**here i need to put what i'm reading inside the excel file into oracle objects**
/can you please give me a sample ?
thanks -
I have an issue with mapping the bean values to fxml. Any hints on how to resolve this issue would be appreciated.
Basically I have a split pane on the screen. The left half displays the list of users in a table. When the admin clicks on a user record, I need to display the details on the right half of the pane.
My controller:
public class TabAdminController implements Initializable {
@FXML
private TableView<User> usersTable = new TableView<User>();
@FXML
private User selectedUser;
@Override
public void initialize(URL url, ResourceBundle rb) {
UserBean userBean = CAClient.getInstance().retrieveUserBeanFromCache();
Integer userId = userBean.getCommitteeStaffId();
Integer committeeId = userBean.getCommitteeId();
EventHandler click = new EventHandler() {
@Override
public void handle(Event t) {
User user = (User) usersTable.getItems().get(((TableCell) t.getSource()).getIndex());
selectedUser = user;
// Create the cell factory
MyCellFactory cellFactory = new MyCellFactory(click);
TableColumn firstNameCol = new TableColumn("First");
firstNameCol.setCellValueFactory(new PropertyValueFactory<User, String>("firstName"));
TableColumn lastNameCol = new TableColumn("Last");
lastNameCol.setCellValueFactory(new PropertyValueFactory<User, String>("lastName"));
TableColumn emailIdCol = new TableColumn("Email");
emailIdCol.setCellValueFactory(new PropertyValueFactory<User, String>("emailID"));
TableColumn roleCol = new TableColumn("Role");
roleCol.setCellValueFactory(new PropertyValueFactory<User, String>("userRole"));
firstNameCol.setCellFactory(cellFactory);
lastNameCol.setCellFactory(cellFactory);
emailIdCol.setCellFactory(cellFactory);
roleCol.setCellFactory(cellFactory);
ObservableList<User> usersList = retrieveUsersList(committeeId, userId);
usersTable.setItems(usersList);
usersTable.getColumns().setAll(firstNameCol, lastNameCol, emailIdCol, roleCol);
}My FXML:
<SplitPane dividerPositions="0.35">
<items>
<TabPane>
<tabs>
<Tab fx:id="TabList" closable="false">
<text>Users</text>
<content >
<TableView fx:id="usersTable"/>
</content>
</Tab>
</tabs>
</TabPane>
<TabPane>
<tabs>
<Tab closable="false">
<text>User Detail</text>
<content>
<ScrollPane>
<content>
<GridPane hgap="40.0" vgap="25.0" fx:id="DetailPane">
<children>
<Label>
<text>First Name</text>
<GridPane.columnIndex>0</GridPane.columnIndex>
<GridPane.rowIndex>1</GridPane.rowIndex>
</Label>
// Below I would like to set the first name from controller.selectedUser.firstName
<TextField fx:id="firstName" prefHeight="30.0">
<GridPane.columnIndex>1</GridPane.columnIndex>
<GridPane.rowIndex>1</GridPane.rowIndex>
<GridPane.hgrow>ALWAYS</GridPane.hgrow>
</TextField>
<Label>
<text>Last Name</text>
<GridPane.columnIndex>0</GridPane.columnIndex>
<GridPane.rowIndex>2</GridPane.rowIndex>
</Label>
// Below I would like to set the last name from controller.selectedUser.lastName
<TextField fx:id="lastname" prefHeight="30.0">
<GridPane.columnIndex>1</GridPane.columnIndex>
<GridPane.rowIndex>2</GridPane.rowIndex>
<GridPane.hgrow>ALWAYS</GridPane.hgrow>
</TextField>
</children>
</GridPane>
</content>
</ScrollPane>
</content>
</Tab>
</tabs>
</TabPane>
</items>
</SplitPane>
... ... ... ... ... ... ...and finally my model bean:
public class User {
private StringProperty firstName = new SimpleStringProperty(this, "firstName", "");
public final String getFirstName() {
return firstName.get();
public final void setFirstName(String value) {
firstName.set(value);
public final StringProperty firstNameProperty() {
return firstName;
private StringProperty lastName = new SimpleStringProperty(this, "lastName", "");
public final String getLastName() {
return lastName.get();
public final void setLastName(String value) {
lastName.set(value);
public final StringProperty lastNameProperty() {
return lastName;
} I have tried using $(controller.selectedUser.firstName) and various other combinations, however unsuccessful.
Thanks.Greg Brown wrote:
It's hard to tell what the problem might be without seeing a complete example. Can you post one?Hello Greg:
I have a simple complete example as requested:
I have five files, all in the same directory /fxtest
1. FXTest.java //Main method
2. Sample.fxml
3. Sample.java //Controller
4. User.java //Model Bean
5. GenericCellFactory.java //Util class
Here goes the code for the same:
FXTest.java:
package fxtest;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class FXTest extends Application {
public static void main(String[] args) {
Application.launch(FXTest.class, args);
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
stage.setWidth(500.0);
stage.setHeight(400.0);
stage.setScene(new Scene(root));
stage.show();
}Sample.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.GridPane?>
<BorderPane id="adminTab" xmlns:fx="http://javafx.com/fxml" fx:controller="fxtest.Sample">
<top>
</top>
<center>
<SplitPane dividerPositions="0.50f">
<items>
<TabPane>
<tabs>
<Tab fx:id="TabList" closable="false">
<text>Users</text>
<content >
<TableView fx:id="usersTable"/>
</content>
</Tab>
</tabs>
</TabPane>
<TabPane>
<tabs>
<Tab closable="false">
<text>User Detail</text>
<content>
<ScrollPane>
<content>
<GridPane hgap="40.0" vgap="25.0" fx:id="DetailPane">
<children>
<Label>
<text>First Name</text>
<GridPane.columnIndex>0</GridPane.columnIndex>
<GridPane.rowIndex>1</GridPane.rowIndex>
</Label>
<TextField fx:id="firstName" text="${controller.selectedUser.firstName}" prefHeight="30.0">
<GridPane.columnIndex>1</GridPane.columnIndex>
<GridPane.rowIndex>1</GridPane.rowIndex>
<GridPane.hgrow>ALWAYS</GridPane.hgrow>
</TextField>
<Label>
<text>Last Name</text>
<GridPane.columnIndex>0</GridPane.columnIndex>
<GridPane.rowIndex>2</GridPane.rowIndex>
</Label>
<TextField fx:id="lastname" text="${controller.selectedUser.lastName}" prefHeight="30.0">
<GridPane.columnIndex>1</GridPane.columnIndex>
<GridPane.rowIndex>2</GridPane.rowIndex>
<GridPane.hgrow>ALWAYS</GridPane.hgrow>
</TextField>
</children>
</GridPane>
</content>
</ScrollPane>
</content>
</Tab>
</tabs>
</TabPane>
</items>
</SplitPane>
</center>
</BorderPane>Sample.java
package fxtest;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
public class Sample implements Initializable {
@FXML
private TableView<User> usersTable = new TableView<User>();
private final ObservableList<User> data =
FXCollections.observableArrayList(
new User("Jacob", "Smith"),
new User("Isabella", "Johnson"),
new User("Ethan", "Williams"),
new User("Emma", "Jones"),
new User("Michael", "Brown"));
@FXML
private User selectedUser;
@Override
public void initialize(URL url, ResourceBundle rb) {
EventHandler click = new EventHandler() {
@Override
public void handle(Event t) {
System.out.println("Inside handle on click event....");
User user = (User) usersTable.getItems().get(((TableCell) t.getSource()).getIndex());
selectedUser = new User(user.getFirstName(), user.getLastName());
GenericCellFactory cellFactory = new GenericCellFactory(click);
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setCellValueFactory(
new PropertyValueFactory<User, String>("firstName"));
firstNameCol.setCellFactory(cellFactory);
TableColumn lastNameCol = new TableColumn("Last Name");
lastNameCol.setCellValueFactory(
new PropertyValueFactory<User, String>("lastName"));
lastNameCol.setCellFactory(cellFactory);
usersTable.setItems(data);
usersTable.getColumns().addAll(firstNameCol, lastNameCol);
}User.java
package fxtest;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class User {
public User(String fName, String lName) {
this.firstName = new SimpleStringProperty(fName);
this.lastName = new SimpleStringProperty(lName);
private StringProperty firstName = new SimpleStringProperty(this, "firstName", "");
public final String getFirstName() {
return firstName.get();
public final void setFirstName(String value) {
firstName.set(value);
public final StringProperty firstNameProperty() {
return firstName;
private StringProperty lastName = new SimpleStringProperty(this, "lastName", "");
public final String getLastName() {
return lastName.get();
public final void setLastName(String value) {
lastName.set(value);
public final StringProperty lastNameProperty() {
return lastName;
}GenericCellFactory.java
package fxtest;
import javafx.event.EventHandler;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.util.Callback;
public class GenericCellFactory implements Callback<TableColumn, TableCell> {
EventHandler click;
public GenericCellFactory(EventHandler click) {
this.click = click;
@Override
public TableCell call(TableColumn p) {
TableCell cell = new TableCell() {
@Override
protected void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
setText(item.toString());
if (click != null) {
cell.setOnMouseClicked(click);
return cell;
}On click of a user record in the left panel I see my action going into the event handle control and update the model bean. However the text fields in the right side panel are not reflecting the changes.
Thanks. -
Help me to set a wrong value in DateField object
Hi all,
I have a DateField object in my View Bean, which is having three seperate drop down for Date,month and year. When user select a wrong input (For Eg: 31 Sep 2006), the Error Action Handler will return with (01 Oct 2006) value as Date object is linient. So is there any hope to set my previouse value in the field.
Thanks in Advance.Are you asking if it's possible to make an incorrect
date default to the nearest correct date in the same
month?I meant, I want to set a wrong date object. As Date,Calendar and GregorianCalendar all are lenient in true in default, it will count the date value and go forward to the next date. I dont want to do this. I have to set the selected date as my date object.
Thanks -
How to access an object in a bean
I am looking for a way to access an object in a bean and make available to the page.
for example if i have a Bean called User and it contains an attribute Called Company as an attribute in User. Now I have User.getCompany(). and I can do this
<%User user = request.getUser();
Company company = user.getCompany();
request.setAttribute("comp", company); %>
how do I do this with useBean ?I am looking for a way to access an object in a bean
and make available to the page.
for example if i have a Bean called User and it
contains an attribute Called Company as an attribute
in User. Now I have User.getCompany(). and I can do
this
<%User user = request.getUser();
Company company = user.getCompany();
request.setAttribute("comp", company); %>
how do I do this with useBean ?You can access a JavaBean Object property of another JavaBean inside the JSP with the use of EL (Expression Language)
So if you are using JSP 2.0 or higher try this:
<jsp:useBean id="user" class="your.package.User" scope="request"/>
${user.company.id}I tested the above and it works.
Note that you need to set the Company object in the User object before trying to access it inside the JSP.
You can also set it in the JSP if you want, (before trying to access it), but its cleaner to do it in a Servlet.
Both User and Company must follow JavaBeans notation.
So in the above case the User object is something like this:
package your.package;
public class User{
private Customer customer;
public User(){}
public Customer getCustomer(){
return customer;
public void setCustomer(Customer customer){
this.customer = customer;
}And your Customer JavaBean is something like this:
package your.package;
public class Customer{
private int id;
public Customer(){}
public int getId(){
return this.id;
public void setId(int id){
this.id = id;
}
Maybe you are looking for
-
i have a old powerbook g4 which i usally use to store some photos and to listen music. the battery of my powerbook is completly dead so i used to use my powerbook using charger adapter so whenever my power cuts down my laptop will be shutdown. one da
-
JTextField(Document, string, int)
Dear friends, Could you just tell me how can I fix the size of the JTextField, such as just accept the maximum number of digits or characters in JTextField... I cant create the Document.... Could anyone give me a tips?
-
The tweet "..." cannot be sent because the connection to Twitter failed
I've been attempting to use the built in twitter functionality to post photos, however the title error message keeps popping up! I have deleted the account setings from the phone and reinstalled Twitter as suggested on the Twitter support blog for so
-
Directory 5.2 2004Q2 Compressed Archive
Where can I obtain a Directory 5.2 2004Q2 Compressed Archive? I cannot find it on the download site.
-
My phone says that I cannot backup to my cloud. How do I free up space so that I can do a back up or do I have to purchase more cloud storage space?