I have a popup that show a table with data, I am able to select a row, and by pressing a OK button I can retrieve the idNo of the selected row in the table.
What I want to do is to pass this idNo to the window that is calling the popup and update a outputText that is on this window.
Can some one help me?
Code for the button:
newBean Class for the button:
public String b1_action() {
// Add event code here...
System.out.println("Select One Button has been Clicked");
// Get bindings associated with the current scope, then access the one that we have assigned to our table - e.g. OpenSupportItemsIterator
DCBindingContainer bindings =
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding dcItteratorBindings =
bindings.findIteratorBinding("NameView1_1Iterator");
// Get an object representing the table and what may be selected within it
ViewObject voTableData = dcItteratorBindings.getViewObject();
// Get selected row
Row rowSelected = voTableData.getCurrentRow();
// Display attriebute of row in console output - would generally be bound to a UI component like a Label and or used to call another proces
System.out.println(rowSelected.getAttribute("IdNo"));
setOutputText("" + rowSelected.getAttribute("IdNo") + "");
closePopup("p1");
return null;
}
I want that my function: setOutputText() which is not implemented yet to be able to update my outputText on the main Window.
Thanks
Best Regards
Put the "IdNo" in view or page flow scope depending on how you want to keep the value.
//view scope
AdfFacesContext.getCurrentInstance().getViewScope().put("IdNo", value);
//or page flow scope
AdfFacesContext.getCurrentInstance().getPageFlowScope.put("IdNo", value);
In the window bean, write a listener for the popup dialog:
public void dialogCloseListener(DialogEvent dialogEvent) {
if (dialogEvent.getOutcome().equals(DialogEvent.Outcome.ok)) {
String idNo = AdfFacesContext.getCurrentInstance().getViewScope().get("IdNo");
//now you have the idNo, do whatever you want
}
}
You can also use the returnListener inside the button or link that is invoking the popup like in this article
Related
I have rename dialog for rename file
String renameTo = JOptionPane.showInputDialog(gui, "New Name", currentFile.getName());
it works this way, but I have a problem.
the problem is that I set the default value with the extension of the file
but I just want the file name to be selected.
sample : my file name = yusuf.png
I want select only yusuf like;
There is a lot going on inside JOptionPane, it's one of the things that makes it so powerful, it also makes it a little inflexible to.
Two immediate problems are apparent...
You can't gain direct access to the JTextField been used to get input from the user
The JOptionPane wants to control which components have focus when the dialog is first shown.
Setting up the JTextField is actually straight forward...
String text = "yusuf.png";
int endIndex = text.lastIndexOf(".");
JTextField field = new JTextField(text, 20);
if (endIndex > 0) {
field.setSelectionStart(0);
field.setSelectionEnd(endIndex);
} else {
field.selectAll();
}
This will basically select all the text from the start of the String up to the last . or all the text if no . can be found.
The difficult part now is taking back focus control from the JOptionPane
// Make a basic JOptionPane instance
JOptionPane pane = new JOptionPane(field,
JOptionPane.PLAIN_MESSAGE,
JOptionPane.OK_CANCEL_OPTION,
null);
// Use it's own dialog creation process, it's simpler this way
JDialog dialog = pane.createDialog("Rename");
// When the window is displayed, we want to "steal"
// focus from what the `JOptionPane` has set
// and apply it to our text field
dialog.addWindowListener(new WindowAdapter() {
#Override
public void windowActivated(WindowEvent e) {
// Set a small "delayed" action
// to occur at some point in the future...
// This way we can circumvent the JOptionPane's
// focus control
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
field.requestFocusInWindow();
}
});
}
});
// Put it on the screen...
dialog.setVisible(true);
dialog.dispose();
// Get the resulting action (what button was activated)
Object value = pane.getValue();
if (value instanceof Integer) {
int result = (int)value;
// OK was actioned, get the new name
if (result == JOptionPane.OK_OPTION) {
String newName = field.getText();
System.out.println("newName = " + newName);
}
}
And, crossing our fingers, we end up with something looking like...
Personally, I'd wrap this up in a nice reusable class/method call which returned the new text or null based on the action of the user, but that's me
Isn't there an easier way?
Of course, I just like showing you the most difficult solution possible ... 😳 (sarcasm) ... it's kind of why I suggested wrapping it up in it's own utility class, so you can re-use it later 😉
I'm having a problem with Label and TextField placement in a gridpane in response to toggled RadioButtons.
The window will display the same options except for two different labels and text fields which depend on which RadioButton the user has selected.(See images attached).
InHouse RB Selected
Outsourced RB Selected
I added the RadioButton objects to a Toggle Group, then coded the "on actions" to add the "Machine ID" or "Company Name" fields to the GridPane as needed when one of the options is selected.
My problem is that I can only select each option once, and the display of the second option only overlaps the first instance instead of replacing it. If I try to switch back again, I get a runtime error(in Netbeans) about adding the same object twice to the grid.
Any code that I have tried that could remove the node from the display had no affect on the menu's behavior.
ArrayList<Label> typeSpecLabels = new ArrayList<Label>();
ArrayList<TextField>typeSpecFields = new ArrayList<TextField>();
typeSpecLabels.add(machineIDLabel);
typeSpecLabels.add(companyLabel);
typeSpecFields.add(machineIDField);
typeSpecFields.add(companyNameField);
inHouseBtn.setOnAction(inHouseSpecificEvent ->
{
typeSpecLabels.add(machineIDLabel);
grid1.add(typeSpecLabels.get(0),0,8,1,1);
grid1.add(typeSpecFields.get(0), 1,8,1,1);
if(outSourceBtn.isArmed() == true){
grid1.getChildren().remove(companyLabel);
grid1.getChildren().remove(companyNameField);
}
});
outSourceBtn.setOnAction(outSourceSpecificEvent ->
{
typeSpecLabels.add(companyLabel);
grid1.add(companyLabel,0,8,1,1);
grid1.add(companyNameField,1,8,1,1);
if(outSourceBtn.isArmed() == true){
grid1.getChildren().remove(machineIDLabel);
grid1.getChildren().remove(machineIDField);
}
});
I have heard that I could try using 2 or 3 different scenes(one for each state of the RadioButtons), so I may try that. But if it can be done the way I have coded it so far, I would prefer to do it that way.
I would suggest to remove all type specific labels and fields from your grid and then add ones that you need. So the code will look like following:
inHouseBtn.setOnAction(inHouseSpecificEvent ->
{
grid1.getChildren().removeAll(machineIDLabel, companyLabel, machineIDField, companyNameField);
grid1.add(machineIDLabel,0,8,1,1);
grid1.add(machineIDField, 1,8,1,1);
});
outSourceBtn.setOnAction(outSourceSpecificEvent ->
{
grid1.getChildren().removeAll(machineIDLabel, companyLabel, machineIDField, companyNameField);
grid1.add(companyLabel,0,8,1,1);
grid1.add(companyNameField,1,8,1,1);
});
This code ended up working, as Pavlo suggested.
Although I just removed the objects specific to the opposing event.
The code works with no errors or overlapping.
inHouseBtn.setOnAction(inHouseSpecificEvent ->
{
grid1.add(machineIDLabel,0,8,1,1);
grid1.add(machineIDField,1,8,1,1);
grid1.getChildren().remove(companyLabel);
grid1.getChildren().remove(companyNameField);
});
outSourceBtn.setOnAction(outSourceSpecificEvent ->
{
grid1.add(companyLabel,0,8,1,1);
grid1.add(companyNameField,1,8,1,1);
grid1.getChildren().remove(machineIDLabel);
grid1.getChildren().remove(machineIDField);
});
I am trying to have wicket display an information dialog after a save button is clicked which invokes an onsubmit that has no access to AjaxRequestTarget target. Here is code snippet
if (trainingmode() && !recordDecision.equalsIgnoreCase("Primary")) {
if (trainingEvalService.compareDecisions(recordDecision, recordSet.getRecordSetId())) {
System.out.println("Validity matchesMaserati: " + trainingEvalService.getTrainingEval().getActual_validity_decision_comment());
// Dialog associated with save button
dialog = new MessageDialog("dialog", "Notice", "Decision Matches " + trainingEvalService.getTrainingEval().getActual_validity_decision_comment() , DialogButtons.OK_CANCEL, DialogIcon.WARN) {
public void onClose(AjaxRequestTarget target, DialogButton button) {
}
};
dialog.open(target) // breaks here without reference to AjaxTarget
} else {
}
}
How can I get a reference to the current AjaxRequestTarget?
Two ways :
If you are doing the form submit through a link, then you can add a SimpleAttributeModifire to it.
Example :
yourLink.add(new SimpleAttributeModifier("onclick","alert('information')"));
This ll display a javascript info, on which you can show the information.
Note :
If you are not submitting from link, then you can do that by putting the submit code in the onSubmit() of a SubmitLink.
You can also use ModalWidow for this, but for that you ll need Ajax submit.
You can use AjaxSubmitLink for that.
You can find ModalWindow code from here:
http://www.wicket-library.com/wicket-examples-6.0.x/ajax/modal-window;jsessionid=2E08EC28B0C0A1AD3F8399628F048003?0
I am working on Java swing application using data base with MySQL
I need to know if I can deactivate components until select an element from JComboBox? I must know the choice of the 1st jcombobox to fill the 2nd JComboBox; the 1st choice is a foreign key on the 2nd, like that :
ResultSet res = st.executeQuery("SELECT NomF FROM famille_de_type");
while (res.next()) {
comboBox_Fam_innewT.addItem(res.getString(1));
}
this is my example :
Of course, you can. When you start work call setEnabled(false) to second comboBox. And add to 1st combobox ItemListener. It will be listen item selection.
firstComboBox.addItemListener(new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
if (e.getStateChange()==ItemEvent.SELECTED)
{
Object selectedItem = e.getItem(); // new item selected
// TODO select values for 2nd combobox
// TODO fill 2nd combobox
secondComboBox.setEnabled(true);
}
}
});
So in the ActionListenr of the JComboBox, simply call the setEnabled methods, passing false to disable them, or true to enable them
I need to know if i can deactivate components until select an element from jcombobox ?
YES. Why not Component.SetEnabled(false)?
Also you might want to look at ItemListener interface to achieve your goal. Here is more about Handling Events on a Combo Box.
I am working on a project where I have many radio buttons in several radio groups. What I would like to do is save the configuration of all the radio groups in accordance to a specific button in the first radio group. For example the first radio group is called select and I have 4 different select radio buttons. When I switch from the 4 buttons inside that group I would like the other radio group buttons to be filled in automatically to that of what they were previously, I would also like to save the configuration of the current button when it is switched through out the radio group. So for example if a radio button in the first radio group is switched it remembers the configuration of the previous one and will automatically load itself again when it comes back to that view.
Create a model that models all of this. Use a property change listener (or many other listeners) to allow you to listen for update in state. The state will be updated whenever you call a setter on the model.
For example, when you set the outer radio button group to the 2nd button, then the model can throw property change events for all of the buttons which depend on that state. The getters for the state of the inner radio buttons can depend on the state of the outer button.
You will probably need to add listeners in the view that listen for user actions on the buttons. The actions in these listeners will call the setters on the model. Be careful to not cause recursive events this way.
Example:
This is an example of the model you could build. Say you have an outer radio button group with 2 buttons and single inner button group with 3 buttons. The inner group options are always the same regardless of the selected outer button.
public class Model {
private int outerSelected = 0; // 0 or 1
private InnerModel[] innerModels = new InnerModel[2];
private class InnerModel {
private int selected = 0; // 0, 1, or 2
public void setSelected(int selected) {
this.selected = selected;
// Send event
}
public int getSelected() {
return selected;
}
}
public int getSelectedInnerModel() {
return innerModels[outerSelected];
}
public int setOuterSelected(int outerSelected) {
this.outerSelected = outerSelected;
// send event for selectedInnerModel change
// If you use beans binding, this should cause the view to re-query the
// getSelected on the InnerModel as well
}
}
I wouldn't suggest you actually use integers. The enum is a better idea, but I didn't write it out. Optionally, you can make this Model class be private inside your view.