add pull2refresh to tabs in codenameone - codenameone

i have added the following codes for pull2refresh but the run method is not called. I have tested for form and its ok for form. How to make it workable for tabs so that I can update all tab at once . and I have pull2refresh of form for whole for refresh.
findTabs1(f).getContentPane().addPullToRefresh(new Runnable() {
#Override
public void run() {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
//
}
});

Tab doesn't have contentPane but TabbedPane.
To add pullToRefresh to a tab, you should add it to the container you added to the tab and it must be scrollable-Y.
Instead of findTabs1(f).getContentPane().addPullToRefresh do findMyContainerInsideTab().addPullToRefresh

Related

Side Menu stopped working after new update

I have an app that has a nice side menu that comes from the left, after today's update it is completely empty when it slides out and I have no idea why.
here is how I show it,
SideMenuBar smb = (SideMenuBar) Display.getInstance().getCurrent().getMenuBar();
smb.openMenu(null);
Here is how it is created (remember this worked perfectly until today when I updated libs):
private void addSideMenuToLeft(Form f)
{
_("addSideMenuToLeft");
//make a toolbarForLeftMenu so we can use its sidemenu (we can only have one on the left!)
if (toolbarForLeftMenu==null)
{
toolbarForLeftMenu = new Toolbar();
}
toolbarForLeftMenu.setHidden(true);
f.setToolbar(toolbarForLeftMenu);
if (SideMenuLEFT==null) //otherwise it keeps adding each time
{
SideMenuLEFT = (Container)this.createContainer(resources, "SideMenuLEFT");
SideMenuLEFT.setWidth(Display.getInstance().getDisplayWidth()/2);
SideMenuLEFT.setHeight((Display.getInstance().getDisplayHeight()));
SideMenuLEFT.setUIID("SideNavigationPanel");//so we get the nice background.
toolbarForLeftMenu.setUIID("Container");
toolbarForLeftMenu.addComponentToSideMenu(SideMenuLEFT);
//make each button live, there are 2 buttons the icon and the words, for each one
Button btCategory = (Button) Tools.findByNameX("btCategory", SideMenuLEFT,sm );
btCategory.addActionListener(new ActionListener(){
#Override
public void actionPerformed(ActionEvent evt) {
}
});
_("made left menu");
}
}
We deprecated the SideMenuBar and replaced it with the new on-top side menu. It was announced multiple times and discussed quite a bit.
To disable this and use the "old" functionality you can use:
Toolbar.setOnTopSideMenu(false);

I am getting null pointer exception for webelement defined under #FindBy annotation in page factory model

I'm new in Selenium learning. I'm getting null pointer exception when I try to use web element - Milestone_Tile_Text.click; in my code but it works fine when I use
LoginTestScript.fd.findElement(By.linkText("Milestone")).click();
Please see below code I have used PageFactory.initElements as well but not sure how to solve this error.
public class MilestoneTileModel
{
GenerateTestData objtestdata = new GenerateTestData() ;
public MilestoneTileModel() //constructor
{
PageFactory.initElements(LoginTestScript.fd, this);
}
#FindBy(xpath="//a[text()='Milestone']")
WebElement Milestone_Tile_Text;
public void Milestone_Tile_Click()
{
Milestone_Tile_Text.click();
LoginTestScript.fd.findElement(By.linkText("Milestone")).click();
LoginTestScript.fd.findElement(By.xpath("//*#id='CPH_btnAddNewMilestoneTop']")).click();
}
}
Timing issues might occur more often when you use an init method.
The timing issue is when you init an element the driver immediately try to find the elements, on failure you will get no warning but the elements will refer null.
The above can occur for example because the page was not fully rendered or the driver see an older version of the page.
A fix can be to define the elements as a property and on the get of the property use the driver to get the element from the page
Please note that selenium does not promise the driver sees the latest version of the page so even this might break and on some situations a retry will work.
First problem what I see: You didn't set LoginTestScript
Following documentation at first you need to set PageObject variable:
GoogleSearchPage page = PageFactory.initElements(driver, GoogleSearchPage.class);
The best way to rich that point is separate Page Object Model and scenario scipt
You fist file POM should contain:
LoginTestPOM
public class LoginTestPOM {
#FindBy(xpath="//a[text()='Milestone']")
WebElement MilestoneTileText;
public void clickMilestoneTitleText(){
MilestoneTitleText.click();
}
}
TestScript
import LoginTestPOM
public class TestLogin {
public static void main(String[] args) {
// Create a new instance of a driver
WebDriver driver = new HtmlUnitDriver();
// Navigate to the right place
driver.get("http://www.loginPage.com/");
// Create a new instance of the login page class
// and initialise any WebElement fields in it.
LoginTestPOM page = PageFactory.initElements(driver, LoginTestPOM.class);
// And now do the page action.
page.clickMilestoneTitleText();
}
}
This is basis of Page Object Pattern.
NOTE: I'm writing that code only in browser so it could contain some mistakes.
LINK: https://github.com/SeleniumHQ/selenium/wiki/PageFactory
The "ugly" solution without page object pattern is:
UglyTestScript
public class UglyTestLogin {
public static void main(String[] args) {
// Create a new instance of a driver
WebDriver driver = new HtmlUnitDriver();
// Navigate to the right place
driver.get("http://www.loginPage.com/");
// DON'T create a new instance of the login page class
// and DON'T initialise any WebElement fields in it.
// And do the page action.
driver.findElement(By.xpath("//a[text()='Milestone']").click()
}
}

codename one remove back button on ios

I removed the title of the form because I don't want it. when I did that, a back button on the iOS(On android back button does not show) started to show on the bottom of the form.
I've tried to override showForm() in the StateMachine and invoke setTitle("") but the back button is still there.
#Override
public Form showForm(String resourceName, Command sourceCommand) {
Form f = super.showForm(resourceName, sourceCommand);
f.setTitle("");
return f;
};
Is there a way to remove that back button?
That's not the way. Override allowBackTo as:
protected boolean allowBackTo(String formName) {
return false;
}

ADF Jdeveloper Refresh Parent Form on Popup close

I want to refresh(update few fields) on my parent form when OK button is clicked on Poup Dialog. But it does not refresh the fields. I have also set partialTriggers for the fields with Popup Id.
My Jdeveloper version is 11.1.1.7
Thanks
Umer Farooq
All you need is linking the OK button action (or action listener) property with a call through an EL to a method provided on a managed bean. Then, in it you should refresh either each component or just the form/parent component keeping all of them(by registering it's bind into a partial target of the ADF context). The method should be similar to this example:
public String refresh() {
AdfFacesContext.getCurrentInstance().addPartialTarget(formToRefresh);
return null;
}
private RichPanelFormLayout installDisable; //this should be the binding to the JSF form
public void setInstallDisable(RichPanelFormLayout installDisable) {
this.installDisable = installDisable;
}
public RichPanelFormLayout getInstallDisable() {
return installDisable;
}
I would need to see what you implemented in your code in order to provide you the "best" solution overall - as theres multiple ways to implement a dialog in a popup. However, here's a couple options depending on how your Popup Dialog is programmed:
Dialog Listener - use this if you use the built-in buttons of a dialog box. You'll need a managed bean for your jspx/jsf page. Create a Dialog Listener on your managed bean that is on your Dialog box. See below for a example of a dialog listener.
public void myDialogListener(DialogEvent dialogEvent) {
if (dialogEvent.getOutcome().equals(DialogEvent.Outcome.yes)) {
// do something...
} else if (dialogEvent.getOutcome().equals(DialogEvent.Outcome.no) {
//do something...
}
}
Return Listener - if you're running a task flow as a popup dialog, on your button, then add a ReturnListener to your page's managed bean. This fires whenever a your popup/dialog is closing.
public void myReturnListener(ReturnEvent returnEvent) {
//do something...
}
Otherwise, i'd add a an ActionListener to your manual button as Endrik suggests.
Now for refreshing your components, use this method in your managed bean, i use it all the time in my projects:
public void refreshComponent(UIComponent comp) {
RequestContext rContext = RequestContext.getCurrentInstance();
rContext.addPartialTarget(comp);
}
To use it, you need to bind your Form's UI components to a managed bean. Then feed in the UI Component's bean property into the method.
For example, below will refresh a Rich Output Text that i have bound to a managed bean:
private RichOutputText myOutputText;
public void refreshMyStuff() {
refreshComponent(myOutputText);
}
Have a good one.

Wicket - Inter-session communication or Create new Request(Cycle) manually

I have some wicket panel store in a static Hashmap from different sessions, i want to do some like if some panel notifies the map, then the map notifies all other panel.
for example:
public class PanelMap{
private static Map<Long, List<MyPanel>> map = new HashMap<Long, List<MyPanel>>();
public static void subscribe(Long id, MyPanel panel){
if (!map.containsKey(id)){
map.put(id, new ArrayList<MyPanel>());
}
map.get(id).add(panel);
}
}
public static void notify(Long id, String notification){
if (map.containsKey(id)){
List<MyPanel> panels = map.get(id);
for(MyPanel panel : panels){
panel.newNotification(notification);
}
}
}
}
In Panel, newNotification(String notification) i want to send request to server and refresh my panel in browser.
public void String newNotification(String notification){
// do some business logic depends on notification
onMyRequest();
}
i've made some search among wicket behavior source files and about i found in AbstractDefaultAjaxBehavior i tried to make my own onRequest method inside my wicket panel as follows
private void onMyRequest(){
AjaxRequestTarget target = ((WebApplication)getApplication()).newAjaxRequestTarget(getPage());
target.add( _some_wicket_components_ );
RequestCycle.get().scheduleRequestHandlerAfterCurrent(target);
}
but all i did is some Ajax error in Wicket Ajax Debug about
Wicket.Ajax.Call.processComponent: Component with id _containerdiv_ was not found while trying to perform markup update.
ERROR: Cannot find element with id: _someComponentIdOnPanel_
(those components are exist)
How could i send my own request to server (or how can i get valid AjaxRequestTarget to update my components? )
Update: I need inter-session communication.
To update panels on different user's sessions, you obviously can't use the current AjaxRequestTarget as this in a way represents a single communication between the server and the requesting user of which another user's Browser has no way of knowing. (Very very basically spoken)
You could either use an AjaxSelfUpdatingTimerBehavior to poll for updates. This would generate new AjaxRequestTarget for every user at regular intervals that you can use to attach changed panels to. It's a very basic and simple implementation that will most likely impact your systems performance and generate quite some traffic.
The other way would be to use something like Atmosphere, which is supported by Wicket-Atmosphere (quickstart can be found here) and has some examples over at the wicket-library.com, but that's all I know about this.
Use Wicket event bus system. Have a look to the "Wicket events infrastructure" chapter of the free Wicket guide.
First you need to create one class to encapsulate the notification and the AjaxRequestTarget and pass them using the events infrastructure.
private class Notification {
private String message;
private AjaxRequestTarget target;
... constructor, getters, setters...
}
Then the panels that want to recive the event have to override onEvent method, something like this:
public void onEvent(IEvent<?> event) {
if (event.getPayload() instanceof Notification) {
Notification notification = (Notification) event.getPayload();
... do whatever you want before updating the panel ...
// Update the panel
notification.getTarget().add(this);
}
}
All the components will recive all the events that are send using Wicket events infrastructure. So you can send the event from any other panel using one method like this
protected void sendMessage(String message, AjaxRequestTarget target) {
send(getSession(), Broadcast.BREADTH, new Notification(message, target));
}
Remember that if you want to update the components using AJAX, you need to set setOutputMarkupId(true). And if it's a component that can be hidden and you want to make it visible using AJAX, then you need to set setOutputMarkupPlaceholderTag(true).

Resources