How to hide AFD component in JDeveloper when button clicked? - oracle-adf

I have tried the following to hide an ADF component but it doesn't work, any idea what im doing wrong?
#{Not mainBean.RequestBean.applyButton.selected}
What I expected this line to do is hide a table when the applyButton is clicked but it doesn't do anything.

You need to refresh the component when the button is clicked for the condition to be true. At the end of the button event add :
UIComponent component = findComponentInRoot("YOUR_COMPONEND_ID");
AdfFacesContext.getCurrentInstance().addPartialTarget(component.getParent()); //This will ask adf to trigger an ajax refresh on your component
To find the component in your java bean :
/**
* Locate an UIComponent in view root with its component id. Use a recursive way to achieve this.
* #param id UIComponent id
* #return UIComponent object
*/
public static UIComponent findComponentInRoot(String id) {
UIComponent component = null;
if (id != null) {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext != null) {
UIComponent root = facesContext.getViewRoot();
if (root != null) {
component = findComponent(root, id);
}
}
}
return component;
}

Related

How to make the property change listener fire in Codename One

I am trying to update the user location on a map. So I've defined my LocationListener as follows :
public class UserLocationListener implements LocationListener {
#Override
public void locationUpdated(Location location) {
User.getInstance().actualLocation.set(location);
}
#Override
public void providerStateChanged(int newState) {
}
}
The actualLocation is a Property defined following CN1 guide on Properties.
Within the simulator if I move user location with the location simulator then locationUpdated is fired.
Now in my MainForm class constructor if I add :
User.getInstance().actualLocation.addChangeListener((p) -> {
System.err.println("User location has changed");
// Update user location on the map
}
It is never fired although the map is shown with a marker (see myMap.addMarker(...)).
So my question is : why is this change listener not fired and where should I put it to make all work ?
Any help appreciated,
The location code reuses the same location object instance and just changes the values within. The set(T) method in property only fires a change event if the new value != the old value:
public K set(T value) {
if(this.value != value) {
this.value = value;
firePropertyChanged();
}
if(parent == null) {
// allows properties to work even if they aren't registered in the index
return null;
}
return (K)parent.parent;
}
So as a workaround you can use something like this:
public void locationUpdated(Location location) {
Location l = new Location();
l.setLatitude(location.getLatitude());
... // etc. sucks that we don't have new Location(location)
User.getInstance().actualLocation.set(l);
}
I'm not sure if it's wrong that we need that.

Actionlistener in the command of the side menu opens blank form but the same in the button action listener opens the form normally

I have called a form name Groups from button action listener and command action listener. In both, I have called a connection request. In postResponse method of
the connection showForm is declared. The issue here is that it works great when I click the button and the groups form opens normally but when I click the command from the hamburger menu, the blank form is shown but as soon as the screen is touched, the contents are displayed (both in real devices and simulator). PS I have also called revalidate method in Groups form. How can it work in one and not in other because I have same code in both command & button actionListener
Command in the side menu
Command goToGroup = new Command("Tables",homeIcon1) {
#Override
public void actionPerformed(ActionEvent evt) {
connectionGroup = new GroupConnection();
connectionGroup.groupConnection(StateMachine.this);
}
};
f.addCommand(goToGroup);
button action listener in a form
groups.addActionListener((e) -> {
connectionGroup = new GroupConnection();
connectionGroup.groupConnection(this);
});
Connection
public class GroupConnection {
void groupConnection(StateMachine sm) {
ConnectionRequest connectionRequest = new ConnectionRequest() {
#Override
protected void readResponse(InputStream input) throws IOException {
- - - - - -
- - - - - -
}
#Override
protected void postResponse() {
sm.showForm("Groups", null);
}
- - - - - -
- - - - - -
};
}
}
groups form:
protected void beforeGroups(Form f) {
Display.getInstance().scheduleBackgroundTask(() -> {
Display.getInstance().callSerially(() -> {
if (connectionGroup.responses != null) {
for (Map<String, Object> element : connectionGroup.responses) {
String id = (String) element.get("id");
String tableName = (String) element.get("name");
String tableImg = (String) element.get("tablelogo");
- - - - - - - -
- - - -- - - - - -
}
}
});
f.revalidate();
});
}
The main difference between the two is that the side menu navigates to a temporary form and then reshows the form after. I'm guessing your call to revalidate() was made at the wrong time when the form hasn't been shown/constructed yet.

GXT Grid with multiple CheckBoxCell with listener

I'm using GXT 3.0 and have a Grid with multiple checkboxes each row. These checkboxes reflect certain properties of my row data and checkin/unchecking does not implies selecting/unselecting the particular row. How can I add a listener to each checkbox and perform some action upon clicking it?
I override the handlesSelection() method to capture the check/uncheck event
CheckBoxCell checkCol = new CheckBoxCell() {
#Override
public boolean handlesSelection() {
//TODO:
return true;
}
};
Add some CheckBoxSelectionModel for each checkbox
IdentityValueProvider<Stock> identity = new IdentityValueProvider<Stock>();
SpecialRowClickCheckBoxSelectionModel<Stock> sm =
new SpecialRowClickCheckBoxSelectionModel<Stock>(identity);
public class SpecialRowClickCheckBoxSelectionModel<M>
extends CheckBoxSelectionModel<M> {
public SpecialRowClickCheckBoxSelectionModel(
IdentityValueProvider<M> identity) {
super(identity);
}
#Override
protected void handleRowClick(RowClickEvent event) {
M model = listStore.get(event.getRowIndex());
//TODO
}
}

Browsable(false) with DesignerSerializationVisibility(Content)

Is it possible to keep a property completely hidden from the property grid but still serialized by the designer?
I have a Parent property on a tray component that sets itself to the form's instance using the designer service from ISite. It gets serialized fine, but it bugs me that it shows up in the property grid even with Browsable(false) applied to it.
Are there custom designer or even custom code generation options?
It is unclear why you need to solve that problem, but we have nothing to look at. This sample component certainly doesn't show the host in the Properties window:
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
public partial class Component1 : Component {
private ContainerControl parent;
[Browsable(false)]
public ContainerControl ContainerControl {
get { return parent; }
set { parent = value; }
}
public override ISite Site {
set {
// Runs at design time, ensures designer initializes ContainerControl
base.Site = value;
if (value == null) return;
IDesignerHost service = value.GetService(typeof(IDesignerHost)) as IDesignerHost;
if (service == null) return;
IComponent rootComponent = service.RootComponent;
this.ContainerControl = rootComponent as ContainerControl;
}
}
}

AWT repaint issues

I am trying to make some small additions to some old java code that does not support swing. I need to add a small dialog that contains a panel which has a checkbox and a couple text fields. When the user clicks on the checkbox I want to disable or enable the checkboxes. This part seems to work well but the text fields are not properly getting redrawn. When I click the checkbox the fields do not appear to become enabled but if I then click on the panel or the text field you see that they are enabled (the opposite is also true, when I un-check the checkbox the fields still look enabled until you try and click on them and they become ghosted and do not become selected). I use the setEnabled(boolean) to set the status of the fields. I have tried calling repaint and validate on both the fields and the panel after changing the status and this does not seem to work. I have also tried to have the fields request focus and this did not work. Anyone have any other ideas?
//The class that contains all of this is of type Window
//Declaration of the components
private Panel _inputPanel;
private TextField min , max;
//This method adds to two text fields
public void addMinMaxtextFields(String min, String max) {
TextField minField = new TextField(min);
TextField maxField = new TextField(max);
this.min = minField;
this.max = maxField;
this.min.setEnabled(false);
this.max.setEnabled(false);
_inputPanel.add(minField);
_inputPanel.add(maxField);
}
//listener for the checkbox
public void itemStateChanged(ItemEvent e) {
Component[] components = _inputPanel.getComponents();
min.setEnabled(!min.isEnabled());
min.setVisible(true);
min.validate();
min.repaint();
_inputPanel.validate();
_inputPanel.repaint();
this.pack();
this.setSize(this.getWidth(), this.getHeight());
this.validate();
this.repaint();
/* do nothing */
}
You will need to call update(Graphics g) on Panel after setEnabled(boolean) is called.
check :
http://download-llnw.oracle.com/javase/1.4.2/docs/api/java/awt/Container.html#update(java.awt.Graphics)
I tried following code (built from code you provided), Its working fine.
import java.awt.Checkbox;
import java.awt.Component;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class CheckUI extends Dialog implements ItemListener {
// The class that contains all of this is of type Window
// Declaration of the components
private Panel _inputPanel;
private TextField min, max;
private Checkbox cb;
public CheckUI(Frame owner, boolean modal) {
super(owner, modal);
_inputPanel = new Panel();
this.add(_inputPanel);
addMinMaxtextFields("min", "max");
}
// This method adds to two text fields
public void addMinMaxtextFields(String min, String max) {
cb = new Checkbox();
cb.addItemListener(this);
TextField minField = new TextField(min);
TextField maxField = new TextField(max);
this.min = minField;
this.max = maxField;
this.min.setEnabled(false);
this.max.setEnabled(false);
_inputPanel.add(minField);
_inputPanel.add(maxField);
_inputPanel.add(cb);
}
// listener for the checkbox
public void itemStateChanged(ItemEvent e) {
Component[] components = _inputPanel.getComponents();
min.setEnabled(!min.isEnabled());
min.setVisible(true);
min.validate();
min.repaint();
_inputPanel.validate();
_inputPanel.repaint();
this.pack();
this.setSize(this.getWidth(), this.getHeight());
this.validate();
this.repaint();
/* do nothing */
}
/**
* #param args
*/
public static void main(String[] args) {
Frame parent = new Frame();
parent.setVisible(true);
parent.setExtendedState(Frame.MAXIMIZED_BOTH);
parent.pack();
CheckUI ui = new CheckUI(parent, true);
ui.pack();
ui.setVisible(true);
}
}

Resources