I have a xp:repeat control with a list of entries. For each entry I have defined a button to remove the back-end document from the database:
<xp:button value="Delete" id="button2">
<i class="fa fa-trash"> </i>
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action>
<![CDATA[#{javascript:employeeBean.remove(obj.unid)}]]>
</xp:this.action>
</xp:eventHandler>
</xp:button>
This works fine although I notice an odd behavior: when I refresh the page (F5 in browser) I get a message: Confirm Form Resubmission. In case I select Confirm another entry is removed from the list.
This process continues as long as I press F5 and refresh the page. How can I stop this?
The remove method is not rocket-science:
public void remove(String id) {
try {
Document doc;
openDatabaseAndView();
if (id != null) {
doc = view.getDocumentByKey(id, true);
} else {
doc = null;
}
if (doc != null) {
doc.remove(true);
} else {
//message to user
}
closeDatabaseAndView();
} catch (NotesException e) {
e.printStackTrace();
}
}
I placed the repeat control within a panel and set a partial refresh on this panel from the Delete button...
F5 with form resubmition in fact repeats last request (delete) that executes button click again, and again...
Take a look at "POST/GET" pattern: https://stackoverflow.com/a/18821569/206265
Related
Getting this popup every time whenever calling a bean method via valueChangeListener property from SelectOneChoice in a jsff page.
I need help to block this unwanted popup.
SelectOneChoice's property of the .jsff page:
<af:selectOneChoice value="................."
label=".................."
required="..............."
shortDesc=".............."
id="....................."
valueChangeListener="#{TransferWorkAreaBean.onBookLovChange}"
autoSubmit="true">
<f:selectItems value="............" id="si2"/>
<f:validator binding="......."/>
</af:selectOneChoice>
Method in Bean Class::
public void onBookLovChange(ValueChangeEvent valueChangeEvent) {
valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
invokeELMethod("#{bindings.methodToExecute.execute}", new Class[0], new Object[0]);
AdfFacesContext.getCurrentInstance().addPartialTarget(getBusinessTable());
}
Method details of binding Method::
public void executeInvetoryQueryOnBookChange(String btg) {
OAViewObjectImpl vo = getBusinessOverview();
VariableValueManager vvm = vo.ensureVariableManager();
vvm.setVariableValue("bindBookTypeCode", btg);
vo.executeQuery();
}
Please note, in some places I have used encrypted data for policy.
Please also note, that the uncommittedDataWarning property is not ENABLED.
This popup only appear when the option uncommittedDataWarning is set to "on" at the root af:document tag. Try to run a full search in your JDevelopper for "uncommittedDataWarning".
Another way of avoiding this popup in this specific case would be to ensure that your data are committed or rollback in your data model. As the popup only appear if some data aren't committed when a user navigate outside the af:document. You could run something like so right before your
invokeELMethod("#{bindings.methodToExecute.execute}", new Class[0], new Object[0]);
How to commit if needed (https://cedricleruth.com/how-to-programmatically-commit-or-rollback-a-transaction-in-oracle-adf/)
private void commitIfDirty() {
try {
ViewObject vo = this.getViewObjectFromIterator("YOUR_ITERATOR_NAME");
boolean isNotSaved = vo.getApplicationModule()
.getTransaction()
.isDirty();
if (isNotSaved) {
vo.getApplicationModule()
.getTransaction()
.validate();
vo.getApplicationModule()
.getTransaction()
.commit();
}
} catch (ValidationException validationException) {
//log it and warn the user that his data isn't valid
} catch (Exception error) {
//log it and warn the user something went wrong
}
}
private ViewObjectImpl getViewObjectFromIterator(String nomIterator) {
ViewObjectImpl returnVO = null;
DCBindingContainer dcb = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
if (dcb != null) {
DCIteratorBinding iter = dcb.findIteratorBinding(nomIterator);
if (iter != null) {
returnVO = (ViewObjectImpl)iter.getViewObject();
}
}
return returnVO;
}
I am working on my first JavaFX app with FXML file.
My program consists of few elements:
addDeviceButton (addMyoButton)
few TextArea, that will have printed data collected from device.
Short description of working:
Pressing addDecideButton should start collecting data from
DataController (DeviceListener),
Collected data and system
communicates should be printed to TextAreas.
I have two problems:
printing in TextArea doesn't work,
app freezes (doesn't respond after pressing addMyoButton)
In 1) I have no idea what's wrong. With 2) I think I shouldn't put running dataCollector in method responsible for button event. However, I'm not sure how to make this properly.
Do you have any suggestions, ideas how I should write these fragments??
Is the problem in FXML or methods?
Responsible of this part of FXML file looks like:
<TextArea fx:id="communicateTextField"
prefHeight="300.0" prefWidth="300.0" >
<Button fx:id="addMyoButton"
onAction="#addMyo" >
Method addMyo(), that runs after pressing button.
public void addMyo(ActionEvent event) {
try {
Hub hub = new Hub("com.example.hello-myo");
communicateTextField.setText("Attempting to find a Myo...");
Myo myo = hub.waitForMyo(10000);
if (myo == null) {
throw new RuntimeException("Unable to find a Myo!");
communicateTextField.setText(""Unable to find a Myo!");
}
communicateTextField.setText("Connected to a Myo armband!");
DeviceListener dataCollector = new DataCollector();
hub.addListener(dataCollector);
while (true) {
hub.run(1000 / 20);
communicateTextField.setText(dataCollector);
}
} catch (Exception e) {
System.err.println("Error: ");
e.printStackTrace();
System.exit(1);
}
}
Method for printing communicates to TextArea
public void printCommunicate(String communicate) {
communicateTextField.setText(communicate);
}
I'm trying to create an email client. This is the output when I open the program:
As you can see, the only button enabled is the Reply-All one. This is because I cannot forward or reply to an email not selected, but I can reply to all the emails in the list. Then, If I delete all the emails this is the output:
All the buttons are disabled (and this is correct). Now, if I change account by pressing Cambia Account a new list of email will be generated, but the Reply-All button will not get enabled. I guess that this is because the listener only check the status of the current mail and not if there is a list of them. How can I solve it?
This is the code which manage the part where I disable the buttons:
public void initModel(DataModel model) {
if (this.model != null) {
throw new IllegalStateException("Model can only be initialized once");
}
this.model = model;
model.currentEmailProperty().addListener((obs, oldEmail, newEmail) -> {
if (oldEmail != null) {
reply.setDisable(false);
forward.setDisable(false);
replyall.setDisable(true);
}
if (newEmail == null) {
reply.setDisable(true);
forward.setDisable(true);
replyall.setDisable(true);
} else {
reply.setDisable(false);
forward.setDisable(false);
replyall.setDisable(false);
}
});
}
If the disabled status of your replyall button depends on whether the list has items, why are you changing it in currentEmailProperty listener? You should listen to changes to the list and update it there.
#Then ("^I hover on (.+) menu and (.+) submenu$")
public void mousehover(String elementName,String subMenu) throws InterruptedException{
Actions actions = new Actions(webdriver);
WebElement menuHoverLink = webdriver.findElement(By.xpath("//a[text() = '" + elementName + "']"));
actions.moveToElement(menuHoverLink).build().perform();
Thread.sleep(2000);
actions.moveToElement(menuHoverLink).moveToElement(webdriver.findElement(By.xpath("//a[text() = '" + subMenu + "']"))).click().build().perform();
System.out.println("Sub menu "+subMenu+" Has been clicked");
}
Blockquote Hi every one. This is my code to done mouse hover event and then click sub link. But most of the time sub link click event is working. But some time which is not works. The mouse hover event has been done. But sub link click event is not triggering. Really don't know why this happen. Thanks in advance..
I would try somethin like moving to where you want to click and then just clicking. With hover menus you can get some odd behaviour from selenium about when an elemenet is and isnt clickable. Try;
actions.MoveToElement(menuHoverLink).Perform();
//wait til clickable, you are sleeping, a wait til element is both displayed and enabled would be better - can explain more if needed
action.Click().Perform();
note: I think just using peform will build the action without explicitly stating
EDIT:
I would assume that sometimes it takes longer than the 2seconds sleep time for the the element to be clickable. What exception is thrown?
Instead of thread.sleep use a wait to decide if the element can be clicked, something like:
public void WaitForElementToBeClickable(IWebElement element)
{
var wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(10));
wait.Until<bool>((d) =>
{
if (IsElementDisplayed(element) && IsElementEnabled(element))
return true;
else return false;
});
}
public Boolean IsElementEnabled(IWebElement element)
{
try
{
return (element.Enabled);
}
catch (NoSuchElementException)
{
return false;
}
}
public Boolean IsElementDisplayed(IWebElement element)
{
try
{
return (element.Displayed);
}
catch (NoSuchElementException)
{
return false;
}
}
I am kinda new to HtmlUnit and am having some trouble getting a form to submit with HtmlImageInput.click(). When I call the method, nothing seems to happen, no form submission, no round trip to the server, or anything, as far as I can tell. The method returns immediately, returning the current page.
There's no Javascript event handler attached to the image input. It's just a plain old vanilla image input, nothing special going on. The input is initially set to disabled when the page is loaded, and then gets enabled as the user interacts with certain AJAXy elements within the page. But by the time I click on the input, it has already been enabled, so I don't think it's an AJAX issue.
Anybody have an idea of what is going on? Runnable source code pasted below.
Thanks,
Matthew
import java.io.*;
import java.util.*;
import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.html.*;
import org.w3c.dom.*;
public class Test {
public static void main(String args[]) {
try {
WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_7);
webClient.setThrowExceptionOnScriptError(false);
HtmlPage page = webClient.getPage("http://us.megabus.com");
System.out.println("got the page");
HtmlForm form = page.getFormByName("ctl01");
System.out.println("got the form");
HtmlSelect select = form.getSelectByName("SearchAndBuy1$ddlLeavingFrom");
select.click();
System.out.println("clicked the select");
HtmlOption option = select.getOptionByValue("13");
option.click();
System.out.println("clicked the option...going to sleep");
try { Thread.sleep(15000); } catch(InterruptedException e) {}
select = form.getSelectByName("SearchAndBuy1$ddlTravellingTo");
select.click();
System.out.println("clicked the select 2");
option = select.getOptionByValue("37");
option.click();
System.out.println("clicked the option 2...going to sleep");
try { Thread.sleep(15000); } catch(InterruptedException e) {}
HtmlImage image = (HtmlImage)page.getElementById("SearchAndBuy1_imgOutboundDate");
image.click();
System.out.println("clicked the image");
String month = "April";
String date = "09";
HtmlTable table = (HtmlTable)page.getElementById("SearchAndBuy1_calendarOutboundDate");
HtmlTableRow row = ((HtmlTable)table.getCellAt(0, 0).getChildElements().iterator().next()).getRow(0);
String monthString = row.getCell(1).getTextContent();
monthString = monthString.substring(0, monthString.indexOf(' '));
while(!monthString.equals(month)) {
row.getCell(2).getChildElements().iterator().next().click();
System.out.println("clicked to go to the next month");
try { Thread.sleep(15000); } catch(InterruptedException e) {}
table = (HtmlTable)page.getElementById("SearchAndBuy1_calendarOutboundDate");
row = ((HtmlTable)table.getCellAt(0, 0).getChildElements().iterator().next()).getRow(0);
monthString = row.getCell(1).getTextContent();
monthString = monthString.substring(0, monthString.indexOf(' '));
}
DomNodeList<HtmlElement> aList = table.getElementsByTagName("a");
for (int i = 0; i < aList.size(); i++) {
HtmlAnchor anchor = (HtmlAnchor)aList.get(i);
if (anchor.getAttribute("title").equals(DomElement.ATTRIBUTE_NOT_DEFINED) || anchor.getAttribute("title").equals(DomElement.ATTRIBUTE_VALUE_EMPTY))
throw new RuntimeException("DomElement ATTRIBUTE_NOT_DEFINED or ATTRIBUTE_VALUE_EMPTY");
if (anchor.getAttribute("title").equals(month + " " + date)) {
anchor.click();
try { Thread.sleep(15000); } catch(InterruptedException e) {}
break;
}
}
HtmlImageInput imageInput = (HtmlImageInput)page.getElementByName("SearchAndBuy1$btnSearch");
page = (HtmlPage)imageInput.click();
System.out.println("clicked search button");
} catch(FailingHttpStatusCodeException e) {
e.printStackTrace();
} catch(IOException e) {
e.printStackTrace();
} catch(ElementNotFoundException e) {
e.printStackTrace();
} catch(IndexOutOfBoundsException e) {
e.printStackTrace();
}
}
}
That image is not an input field, it's just a plain old image:
<img id="SearchAndBuy1_imgOutboundDate" disabled="disabled" alt="calendar"
CausesValidation="False" src="images/icon_calendar.gif" style="border-width:0px;" />
There are no JS handlers specified there, so they must be attached elsewhere, and seems it's at the bottom of the page:
Sys.Application.add_init(function() {
$create(AjaxControlToolkit.PopupControlBehavior,
{"PopupControlID":"SearchAndBuy1_panelOutboundDate","Position":3,"dynamicServicePath":"/default.aspx","id":"SearchAndBuy1_pceImageOutboundDate"}, null, null, $get("SearchAndBuy1_imgOutboundDate"));
});
When your program clicks on the image, there is no form submit, just an AJAX call (presumably), so you're right, you don't get a new page back. But as your code proves (I just ran it with a debugger), the content of the HtmlPage has changed, since it now contains the calendar widget, which you were able to pull details from.
It can be a bit confusing knowing when you will get a net new HtmlPage back, but usually it's only when you would see a whole new page in the browser. I've never tried HtmlUnit against something like Gmail, but I suspect you might only ever deal with the one HtmlPage object, and everything takes places within it.