0
votes

I fetch a value via JSONP to my webpage. Now I want to update a backing-bean-property with this value? How to handle this? Thanks in advance.

UPDATE: Okay, my problem is that there are JavaScripts, JSF-Ajax-Calls and Webservices and I have to look, when which action got triggered. I guess I need to describe my situaton in more detail.

My backing bean:

logger.debug("CaseController - save(): tempCaseId [ " + tempIshCaseId + "];");

My xhtml-Page:

<!-- JSONP-Wert in die Bean hieven -->
<t:div id="tempIshCaseIdContainer">
    <h:outputText id="setTempIshCaseId" value="#{CaseController.tempIshCaseId}" />
</t:div>
<a4j:commandLink id="preSaveCaseButton" onclick="setTempIshCaseId();" title="..."
    reRender="jsonpRemoteURLs,hNumberRemoteURL,eNumberRemoteURL,ishCaseRemoteURL,tempIshCaseIdContainer" oncomplete="jQuery('a#form_saveCaseButton').click()">
</a4j:commandLink>
<a4j:commandLink id="saveCaseButton" title="..." reRender="serverWarningsParent"  action="#{CaseController.save}" onclick="if (validateCaseFormEntries(){ closeCaseWarningsBox(); } else { return false; }" oncomplete="if (#{CaseController.success}){ showCaseModalPanel(); patientConsistencyCheck(#{NavigationController.globalErrorState}, '#{PatientController.patienlistUrl}'); startJsonpSetters(); saveCase(); initializeFocusBlurEvents();} else { return false;}">
</a4j:commandLink>
<a4j:commandLink id="postSaveCaseButton" onclick="hideCaseModalPanel();" reRender="caseContainer,modifiedContainer">
</a4j:commandLink>

My Javascript-File:

function setTempIshCaseId(){// setze den Wert des a4j-value-Elements
var ishCaseId = jQuery('#form_ish').val();
jQuery('#form_setTempIshCaseId').text(ishCaseId);
}

I got three stages after page-rendering. preSaveCaseButton should update all JSONP-Urls, that is necessary because otherwise the system will produce Token-Timeouts and exceptions will be thrown. saveCaseButton will trigger the bean-action and save the edited setTempIshCaseId to the database, if it is valid. Summing up, I thought I just need to make sure, that at time when preSaveCaseButton gets called I updated the bean, as you can see I tried to use 'process'-attribute. Right after saveCaseButton will be called and I can check the bean-value. Unfortunately my log4j-logging-message tells me that my backing bean has the value '' (tempIshCaseId = '') and was not updated.

What to do know?

1

1 Answers

1
votes

Just send a request parameter with that value. It's not entirely clear how you're submitting the form, but you could use among others <h:inputHidden> for this.

<h:inputHidden id="hidden" value="#{bean.property}" />

In JS side, just change its value with the fetched value like follows:

document.getElementById("form:hidden").value = fetchedValue;