Bind an object to a choice box
Is there a way to bind a list of objects to a choice box or at least a name value pair?
For instance, I have a drop down that lists the user roles. Each role has a specific id.
Now in my FXML I would like to display the role on the screen, but however when user selects a role, I would like to see the role id in my action method.
This is how my FXML looks:
<VBox fx:id="vboxInner" spacing="30">
<children>
<HBox spacing="30">
<children>
<Label text="*Password:" prefWidth="115.0"/>
<PasswordField promptText="Password" prefHeight="30.0" prefWidth="200.0" fx:id="password" />
</children>
</HBox>
<HBox spacing="30">
<children>
<Label text="*Repeat Password:" prefWidth="115.0"/>
<PasswordField promptText="Repeat Password" prefHeight="30.0" prefWidth="200.0" fx:id="repeatPassword" />
</children>
</HBox>
<HBox spacing="30">
<children>
<Label text="*User Role:" prefWidth="115.0"/>
<ChoiceBox fx:id="userRoles"></ChoiceBox>
</children>
</HBox>
<Label text="* indicates mandatory" textFill="red"/>
</children>
</VBox>And my controller:
@FXML
private ChoiceBox userRoles;
@Override
public void initialize(URL location, ResourceBundle resources) {
userRoles.setItems(retrieveUserRoles());
private ObservableList<String> retrieveUserRoles() {
ObservableList<String> userRolesList = null;
try {
ServiceLocator serviceLocator = ServiceLocator.getInstance();
LoginAuthenticateSLBeanRemote loginRemoteBean = serviceLocator.retrieveLoginAuthenticateEJB();
ArrayList<UserRole> roles = loginRemoteBean.retrieveUserRoles();
ArrayList<String> strRoles = new ArrayList<String>();
for(UserRole role : roles){
strRoles.add(role.getUserRole());
userRolesList = FXCollections.observableArrayList(strRoles);
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, "Roles Size::{0}", roles.size());
} catch (Exception ex) {
Logger.getLogger(LoginController.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
return userRolesList;
}UserRole object contains both role and roleId.
Any hints on implementing this would be highly appreciated.
Thanks.
Thanks jsmith.
overriding the toString method took care of my problem and I can now bind my entire object to the dropdown item.
Thanks.
jsmith wrote:
You can see an examples of doing something similar to this (without fxml) here:
https://gist.github.com/1422104 "JavaFX ChoiceBox control backed by Database IDs"
A previous thread discussing this is:
ChoiceBox containing 2 values
On the thread Richard also suggests "What about using a custom selection model that has methods on it to select an item by id or by name?" which is a route I haven't explored.
For JavaFX 2.1 there are some new implementations which may assist this task (both of which I haven't really used, so I can't really advise on them):
1. StringConvertors which can be applied to ChoiceBox items
2. More functional ComboBox control.
Similar Messages
-
Fire a function from a Choice Box selection
I can't seem to figure out where to place code to create an event when the user selects a choice from a Choice Box:
def theChoice = ChoiceBox {
items: ['one', 'two''],
function MySelect(){
if(theChoice.selectedIndex == 1){
println("test...");
As far as I can tell, the Choice Box control has no "action" variable (like a Button object) so I'm not sure how to like an event to a selection....
thanksLol, you beat me by a few minutes! :-D
To be more precise, Button has no state we can override to detect the action, hence the specific callback. While ChoiceBox has several states (selectedIndex, selectedItem) and can have others in the future (eg. in an editable choice box). -
How do I make to populate choice box in the JavaFX Scene Builder? I have that to make a class or is there another way?
Thanks!Hi,
1. In SceneBuilder, add a unique fx:id to your ChoiceBox object - this fx:id should be the name of a private variable in your controller's class.
<AnchorPane id="AnchorPane" ... xmlns:fx="http://javafx.com/fxml" fx:controller="myexample.MyController">
<children>
<ChoiceBox fx:id="myChoiceBox" layoutX="257.0" layoutY="190.0"/>
</children>
</AnchorPane>
2. In your controller's initialize method, initialize the content of your choice box.
package myexample;
import ...
public class MyController implements Initializable {
@FXML // fx:id="myChoices"
private ChoiceBox<?> myChoices; // Value injected by FXMLLoader
@Override // This method is called by the FXMLLoader when initialization is complete
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
assert myChoices != null : "fx:id=\"myChoices\" was not injected: check your FXML file 'foo.fxml'.";
// initialize your logic here: all @FXML variables will have been injected
// => you can add items to "myChoices" here:
myChoices.setItems(FXCollections.observableArrayList());
myChoices.getItems().add(...);
} -
Creating and Binding View Objects dynamically : Oracle Jdeveloper 11g
Hello,
We are trying to create and bind view objects dynamically to adf data visualization components.
The view object is a result of multiple tables.
We are using Oracle JDeveloper 11g Technical Preview. ( can't upgrade to TP2 or TP3 now).
We have found this : http://radio.weblogs.com/0118231/stories/2003/07/15/creatingUpdateableMultientityViewObjectDefinitionsDynamically.html on our search for the same.
The sample application however, is in 10g , hence required migration.
Also, it was a standalone application with the TestClient.java having a main() method.
Our requirement is for Web Application; we use Adf+jsf .
Guidance of any sort is very much appreciated.
Thanks in advance.
-Anil GollaHi,
there also exist a forum for JDeveloper 11: JDeveloper and OC4J 11g Technology Preview
What you are trying todo is not trivial because you need to not only dynamically create the VO, you would also dynamically need to create the binding meta data for it (assuming you use ADF). Not sure if the API to modify the binding is public, so posting it on the JDeveloper 11 forum bears a glimpse of hope for an answer
In JDeveloper 10.1.3 you can't do this
Frank -
How to match the width of the choice box's dropdown to the choice box
Hi there,
I'm using a ChoiceBox control. The choice box seems to be composed of two parts: the box(displaying the current selection) and a context menu(dropdown). What I find strange is that the dropdown of the choice box(the context menu) has different size than the choice box by default:
http://manvox.com/javafx1.3/choice-box-dropdown.jpeg
I can style the choiceBox's box element by modifying the +.choice-box+ CSS selector. I can also style the dropdown using the +.context-menu+ and +.menu-item+ selectors.
How can I ensure that the dropdown has the same size of it's parent choice box and is aligned to it?@alabala: Please, if you can spare a few minutes, can you file a bug report for this at the JavaFX Jira issue tracker here: http://javafx-jira.kenai.com
If you set the 'project' to 'runtime', and 'component' to controls, it'll end up on my desk and I'll get the owner of the ChoiceBox control to take a look at it.
Thanks,
-- Jonathan -
Firefox will not start in normal (hour glass for a second) or in safe mode (closes after choice box).
I tried all of the following with no success:
- uninstalling and reinstalling mozilla with no success.
- End all firefox.exe from the task manager and then open again the firefox from quick launch or desktop or program files folder.
- Change the firefox.exe name to firefox2.exe
- Start in safe mode and choose several alternatives after choice box, but nothing happen.
Please help.What is your computer system, and what Firefox are you using?
Start your '''Computer''' in safe mode. Then start Firefox. Try '''Safe''' web sites.
'''[http://encyclopedia2.thefreedictionary.com/Linux+Safe+Mode Starting The Computer In Safe Mode;<br>Free Online Encyclopedia]''' -
How can I place multiple choice boxes on the same line instead of in a column?
I know it is possible to place multiple fields on the same line, using drag and drop.
But to save space, I would like to have 3 or 4 multiple choice boxes next to each other on one line.
Is this possible, and if so, how?
Thanks
PeterYou may click on the "+" button to the right of the first multiple choice box to add more in the same line. When you hover over the button, the tooltip says "insert item beside".
-
Properly binding an object to a custom component.
I am apparently not doing this. What am I missing to properly
bind an
object from a repeater looping over an array of object to the
custom
component called in the repeater?
<mx:Repeater
id="dayCells"
dataProvider="{days}"
startingIndex="{weekRows.currentItem}"
count="7">
<mx:GridItem
width="14%"
borderColor="black"
borderThickness="1"
borderStyle="solid">
<mx:Label
text="{dayCells.currentItem.formatedDate}" />
<ian:dayFormat2
drawData="{dayCells.currentItem as drawDay}"
test="{dayCells.currentItem.formatedDate}" />
</mx:GridItem>
</mx:Repeater>
{days} is an array of drawDate.as objects returned with a
remoteObject.
I can correctly bind properties of these drawDate objects in
the
lable and the test property of the dayFormat2
customComponent. But I
can NOT correctly bind the entire object over to dayFormat2.
What am I
missing?
My current version of dayFormat2.mxml, I have tried several
alternatives
for this file.
?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="
http://www.adobe.com/2006/mxml"
width="100%">
<mx:Script>
<![CDATA[
import drawDay;
//Define public variables
[Bindable]
public var drawData:drawDay;
[Bindable]
public var test:String;
]]>
</mx:Script>
<mx:DateFormatter id="dayNum" formatString="DD" />
<mx:HBox
backgroundColor="0x002649"
width="100%"
horizontalAlign="right">
<mx:Label
text="{test}"
color="white" />
<mx:HBox
backgroundColor="0xAF1E2D"
horizontalAlign="center">
<mx:Label
text="{dayNum.format(drawData.date)}"
color="white" />
</mx:HBox>
</mx:HBox>
<mx:Label text="foobar" />
</mx:VBox>
The first label bound to the test String works correctly. The
second
label bound to the drawData drawDay object date property does
not work
correctly.
What is the proper way to bind this object?I have struggled with this all day and made no headway. The
only
strange thing I get is with this line:
<mx:Label text="{dayCells.currentItem.toString()}" />
outputs [object Object]
Not the expected string from this drawDay.as function.
// toString()
public function toString():String
return "Date: " + formatedDate;
Ian Skinner wrote:
> I am apparently not doing this. What am I missing to
properly bind an
> object from a repeater looping over an array of object
to the custom
> component called in the repeater?
>
> <mx:Repeater
> id="dayCells"
> dataProvider="{days}"
> startingIndex="{weekRows.currentItem}"
> count="7">
> <mx:GridItem
> width="14%"
> borderColor="black"
> borderThickness="1"
> borderStyle="solid">
> <mx:Label
> text="{dayCells.currentItem.formatedDate}" />
> <ian:dayFormat2
> drawData="{dayCells.currentItem as drawDay}"
> test="{dayCells.currentItem.formatedDate}" />
> </mx:GridItem>
> </mx:Repeater>
>
> {days} is an array of drawDate.as objects returned with
a remoteObject.
> I can correctly bind properties of these drawDate
objects in the lable
> and the test property of the dayFormat2 customComponent.
But I can NOT
> correctly bind the entire object over to dayFormat2.
What am I missing?
>
> My current version of dayFormat2.mxml, I have tried
several alternatives
> for this file.
>
> ?xml version="1.0" encoding="utf-8"?>
> <mx:VBox xmlns:mx="
http://www.adobe.com/2006/mxml"
width="100%">
> <mx:Script>
> <![CDATA[
> import drawDay;
>
> //Define public variables
> [Bindable]
> public var drawData:drawDay;
>
> [Bindable]
> public var test:String;
> ]]>
> </mx:Script>
>
> <mx:DateFormatter id="dayNum" formatString="DD" />
>
> <mx:HBox
> backgroundColor="0x002649"
> width="100%"
> horizontalAlign="right">
> <mx:Label
> text="{test}"
> color="white" />
> <mx:HBox
> backgroundColor="0xAF1E2D"
> horizontalAlign="center">
> <mx:Label
> text="{dayNum.format(drawData.date)}"
> color="white" />
> </mx:HBox>
> </mx:HBox>
>
> <mx:Label text="foobar" />
> </mx:VBox>
>
> The first label bound to the test String works
correctly. The second
> label bound to the drawData drawDay object date property
does not work
> correctly.
>
> What is the proper way to bind this object? -
How to change the selection background color of the selected item in the popup menu of the choice box ?
By defaut, the selection background color likes "blue", but if I want it to be "yellow" for example, how should I do ?
ThanksThe id is applied by (I think) the skin class of the ChoiceBox. You don't need to define it.
You have to apply the css in an external style sheet. You can apply the external style sheet to any parent of your choice box, or to the scene (the most usual way to do it).
Example:
import java.util.ArrayList;
import java.util.List;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ChoiceBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class ChoiceBoxTest extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Example 2");
final ChoiceBox<String> choiceBox = new ChoiceBox<>();
List<String> tempResult = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
tempResult.add("Item " + i);
choiceBox.getItems().setAll(tempResult);
VBox root = new VBox();
root.getChildren().add(choiceBox);
final Scene scene = new Scene(root, 300, 250);
scene.getStylesheets().add("choiceBox.css");
primaryStage.setScene(scene);
primaryStage.show();
public static void main(String[] args) {
launch(args);
choiceBox.css:
@CHARSET "UTF-8";
#choice-box-menu-item:focused {
-fx-background-color: yellow ;
#choice-box-menu-item .label {
-fx-text-fill: black ;
Message was edited by: James_D -
Javax.naming.NameAlreadyBoundException: Failed to bind remote object
I am getting an error while deploying wli-ejbs.ear file. This ear uses oracle thin drivers to connect to database. But while deploying i am receiving an error as below. Can anyone please help me to solve this problem?
Deployer:149033]preparing application wli-ejbs on managed2_cvf01
[Deployer:149033]preparing application wli-ejbs on managed1_cvf01
[Deployer:149033]prepared application wli-ejbs on managed1_cvf01
[Deployer:149033]prepared application wli-ejbs on managed2_cvf01
[Deployer:149033]activating application wli-ejbs on managed1_cvf01
[Deployer:149033]activating application wli-ejbs on managed2_cvf01
[Deployer:149034]An exception occurred for task [Deployer:149026]Deploy application wli-ejbs on cvf01_cluster.: weblogic.management.DeploymentException:
Exception:weblogic.management.ApplicationException: activate failed for calendar/oracle
Module: calendar/oracle Error: Exception activating module: EJBModule(calendar/oracle,status=PREPARED)
Unable to deploy EJB: RemoteCalendarBean from calendar/oracle:
[EJB:011008]Unable to bind EJB Home Interface to the JNDI name: RemoteCalendarBean.
javax.naming.NameAlreadyBoundException: Failed to bind remote object (ClusterableRemoteRef(704752282736664516S:172.24.206.163:[7003,7003,7004,7004,7003,7004,-1,0,0]:172.24.206.163:7003,172.24.206.163:7003:cvf01:managed1_cvf01 null)/948 [com.bea.wli.calendar.api.BusinessCalendarHome+javax.ejb.EJBHome+weblogic.ejb20.interfaces.RemoteHome]) to replica aware stub at RemoteCalendarBean(ClusterableRemoteRef(704752282736664516S:172.24.206.163:[7003,7003,7004,7004,7003,7004,-1,0,0]:172.24.206.163:7003,172.24.206.163:7003:cvf01:managed1_cvf01 [704752282736664516S:172.24.206.163:[7003,7003,7004,7004,7003,7004,-1,0,0]:172.24.206.163:7003,172.24.206.163:7003:cvf01:managed1_cvf01/944, -8505871579836432025S:172.24.206.163:[7005,7005,7006,7006,7005,7006,-1,0,0]:172.24.206.163:7003,172.24.206.163:7003:cvf01:managed2_cvf01/1008])/944 [com.bea.wli.calendar.api.BusinessCalendarHome+javax.ejb.EJBHome+weblogic.ejb20.interfaces.RemoteHome]); remaining name ''
at weblogic.rmi.cluster.ClusterableRemoteObject.onBind(ClusterableRemoteObject.java:177)
at weblogic.jndi.internal.BasicNamingNode.bindHere(BasicNamingNode.java:347)
at weblogic.jndi.internal.ServerNamingNode.bindHere(ServerNamingNode.java:124)
at weblogic.jndi.internal.BasicNamingNode.bind(BasicNamingNode.java:291)
at weblogic.jndi.internal.WLEventContextImpl.bind(WLEventContextImpl.java:279)
at weblogic.jndi.internal.WLContextImpl.bind(WLContextImpl.java:386)
at weblogic.ejb20.deployer.ClientDrivenBeanInfoImpl.activate(ClientDrivenBeanInfoImpl.java:1141)
at weblogic.ejb20.deployer.EJBDeployer.activate(EJBDeployer.java:1385)
at weblogic.ejb20.deployer.EJBModule.activate(EJBModule.java:631)
at weblogic.j2ee.J2EEApplicationContainer.activateModule(J2EEApplicationContainer.java:3315)
at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2194)
at weblogic.j2ee.J2EEApplicationContainer.activate(J2EEApplicationContainer.java:2167)
at weblogic.management.deploy.slave.SlaveDeployer$ComponentActivateTask.activateContainer(SlaveDeployer.java:2503)
at weblogic.management.deploy.slave.SlaveDeployer$ActivateTask.doCommit(SlaveDeployer.java:2421)
at weblogic.management.deploy.slave.SlaveDeployer$Task.commit(SlaveDeployer.java:2138)
at weblogic.management.deploy.slave.SlaveDeployer.commitUpdate(SlaveDeployer.java:676)
at weblogic.drs.internal.SlaveCallbackHandler$2.execute(SlaveCallbackHandler.java:35)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)run the sync.bat file as mentioned in the instructions...
or through EBCC(select sampleportal-project dir, app name "sampleportal")...
good luck
Vijay
"ellen" <[email protected]> wrote:
>
I installed sampleportal and did all the changes according to the documents,
when
the server started, there is this error:
Unable to deploy EJB: CatalogWebService from catalogwe.jar:
Unable to bind EJB Home Interface to the JNDI name: sampleportal.BEA_commerce.CatalogWebService.
The error was: javax.naming.nameAlreadyBoundException: Failed to bind remote
object...to
replica aware stub at CatalogWebService; remaining name'sampleportal.BEA_commerce'
After the server started with the above error, I tried to run the app, here
is what
occured:
PortalPersistenceManager: portal'sampleportal/sampleportal' not found.
Has anybody seen this before?
Ellen -
i have a choice box whic display from 0 to 59. when i cselect the choice box it display from top to bottom of my screen . how will i make it look only 5 items when it displays.
here is my code. pls help
final ChoiceBox minitueChoice = new ChoiceBox();
minitueChoice.autosize();
minitueChoice.setItems(FXCollections.observableArrayList(
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"));
minitueChoice.getSelectionModel().selectFirst();Hi,
I hope the ComboBox is a better option for this case.
final ComboBox<String> minitueChoice = new ComboBox<String>();
minitueChoice.autosize();
minitueChoice.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
@Override
public ListCell<String> call(ListView<String> paramP) {
paramP.setMaxHeight(146); // To show list view till 5 options
return new ListCell<String>(){;
@Override
protected void updateItem(String paramT,boolean paramBoolean) {
super.updateItem(paramT, paramBoolean);
if(!isEmpty()){
setGraphic(new Label(paramT));
minitueChoice.setItems(FXCollections.observableArrayList(
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"));
minitueChoice.getSelectionModel().selectFirst();Regards,
Sai Pradeep Dandem. -
Hi,
I intend to bind a few objects in JNDI context so that they can later be just looked up and then used.
I can use code like this:
=========
Hashtable env = new Hashtable();
env.put(Context.PROVIDER_URL, SOME_PROVIDER_URL);
env.put(Context.SECURITY_PRINCIPAL, "user");
env.put(Context.SECURITY_CREDENTIAL, "passwd");
Context ctx = new InitialContext(env);
context.bind("name", object);
=========
This object can later be looked up. So far so good. However, this will bind the object in the same VM "only".
Is there any way of calling something like:
====
someOC4JClass.getNamingService().bind("name", object);
===
so that the underlying naming service takes care of making this object available across JVMs?
Any help/pointers will be highly appreciated.
Thanks,
RaviRavi -- Currently OC4J's internal JNDI is not a global JNDI shared by all OC4Js. One way to approach this problem would be to bind the objects in some global / common JNDI like OID.
Thanks -- Jeff -
I'd like to create 2 choice boxes in applet, how can I can it ?
I have done a choice box in applet like this:
Panel p2 = new Panel();
p2.setLayout(new GridLayout(3,0));
choice.add("Leftfoot");
choice.add("Layer1");
choice.add("Layer2");
choice.add("Layer3");
choice.add("Layer4");
choice.add("Rightfoot");
p2.add(choice);
This choice box shows all components of a furniture, but now I'd like to add another furniture in the applet, and it also has several different components. I want that when user selected the furniture name in first choice box, then the second choice box will automatically and only shows the components the furniture u selected has. so how can I make the actions between the 2 choices. Thanks in advance.look at the function addItemListener in choice and then look ate the interface ItemListener.
-
Binding ActionScript object to webservice
Hi,
Can someone please provide me with simple example as to how
to bind an ActionScript object to the webservice.
The Scenario is I have an actionscript class. I have the
webservice in the mail mxml. I want to create an object of the
class and want to bind that object to the webservice rather than
binding each of the property.
Thanks in advance.Do not bind directly to a webService result. Use a result
handler, and assign the result to a bindable variable. Bind to
that.
To intercept binding events in AS code, use a ChangeWatcher.
Tracy -
Hi,
Is it possible to bind an object to the thread and is so how.
Thanks and Regards,
PradeepAlthough I have no idea of what you mean, I guess it have something to do with synchronized keyword or Object.wait() or event Thread.join().
Maybe you are looking for
-
Image Adjustments won't stay on
Hey everybody, I'm Steven! I'm working on a sci-fi mural spacescape for my art class, and I'm having a bit of difficulty in the star scape area. See, whenever I do anything in the "Image > Adjustments" tab at the top of Photoshop, the preview on
-
SRM-Synching company code description between SRM and ECC
Hi, I have two questions: 1. Is company code descriptions and other details are stored in SRM (like T001 in ECC)? 2. If yes, how can we synch the company code description in SRM and ECC? What is the program name to synch both system Jit
-
Importing tables in paralell sessions
Hi I am doing a import of tablelevel its big table around 3 gb with indexes.Th export dump is compressed.I want to start another import session for another big table for saving time.Whether its possible to start 2 sessions of import for different tab
-
Add a new field in basic data tab in PPOME for a position
Hello Evryone, I want to display a Job ID field in Basic Data tab when displaying a position. Is this something to do in config? If yes, could anyone please guide me how to do it? Right now I can see only the Job description, but no ID. Thank you, Ru
-
I am in Korea trying to download Photoshop CC. I am an English speaking and read person, the pages to download are coming up in Korean. I can't read them. How do I change the lanaguge