I am working in JSF very first time and without any knowledge in JSF. I did work on JavaScript, CSS, Ajax, Angular and Java. Since I don't know JSF, it is really difficult for me to understand why it is happening. And I do see there are some answers in Stack Overflow, but either they didn't work for or I could not understand.
Please help me here.
I have a search screen when I enter filter criteria/fields. Then I see results in the bottom of the same screen. Then I select any row and click on 'View Details' button, it takes me to another screen. In this detail screen, I have a 'Cancel' button.
Expectation: On click (only once) of the 'Cancel' button, it should bring back me to the search screen.
Issue: On my first click on 'Cancel' button, it does nothing. On my second click, it takes back me to the search screen
I added a debug message in Java, On my first click on the Cancel button, it doesn't print that logger message. On my second click it prints.
Also I noticed on my first click, I see a POST call in Chrome browser Inspect -> Network tab
Here is my code:
JSF:
<h:form id="partQuoteCCRFormId" styleClass="mainForm" >
<h:panelGrid columns="1" styleClass="buttonGridStyle">
<h:panelGroup>
<p:commandButton value="Update Code" id="updatePartQuote" ajax="true"
actionListener="#{partQuoteSearchBackingBean.displayDialog('UpdateQuoteCCR')}"
update="costChangeReasonDlg,ccrDialogForm:costChangeReasonDD, ccrDialogForm:apply"/>
<p:commandButton value="Cancel" id="cancelToSearch"
action="#{partQuoteSearchBackingBean.performCancel('SearchScreen')}"
ajax="true" />
</h:panelGroup>
</h:panelGrid>
</h:form>
Java:
public void performCancel(String targetPage){
logger.debug("targetPage: " + targetPage);
logger.info("targetPage: " + targetPage);
try{
if("SearchScreen".equals(targetPage)){
//for setting focus by default
//setFieldFocus("partQuoteSearchFormId:formPartQuoteSearchFocusID","partQuoteSearchFormId:partNumber");
FacesContext.getCurrentInstance().getExternalContext().redirect("partQuoteSearch.xhtml");
}else if("Home".equals(targetPage)){
FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml");
}
else if("enterPartQuote".equals(targetPage)){
//for setting focus
setFieldFocus("enterPartQuoteFormId:formFocusID","enterPartQuoteFormId:partNumber");
FacesContext.getCurrentInstance().getExternalContext().redirect("enterPartQuote.xhtml");
}
} catch (Exception e) {
handleSystemException(e, "messages");
}
}