JSF - Richfaces, process submitted form data and then confirm to continue or cancel
I want to show a confirmation dialog to continiue or cancel a save operation when a form is submitted. I have a form with a save button which is calling an action methode to persist data in the form. When save button is clicked, a file will be readed on serverside before the form data is persisted. Data from the file will be joined into form data and then te form data will be persisted. I need some values from the form to define which file will be readed. There is no problem so far. When a FileNotFoundException throwed or the neccessary data from the file is not found, then i want to show a confirmation dialog to continiue or cancel save operation with caused message.
Does anybody have some examp开发者_JS百科les or any ideas how to handle this? Do i need to use a4j? Thanks. I am using Rifchfaces 3.3.3 and Seamframework 2.2.
At first i have to correct my question title. It is not going on "processing submitted form data" but a form data that will be submitted after some validation.
Now the solution.
For example I have following in my form:
some filelds
an a4j:commandButton to reRender the fields and perform doSomeStuff() action
an hidden h: or a4j:commandButton to submit the form.
1- User clicks on 'fake' submit button which is an a4j:commandButtton,
2- Ajax call updates fields in reRender attribute
3- After that,method doSomeStuff() is performed with rerendered field values
4- In the end Javascript will run to submit form or not.
Form:
<h:form id="myForm">
<h:inputText id="name" value="#{personHome.person.name}"/>
<h:inputText id="surname" value="#{personHome.person.surname}"/>
<a:commandButton value="Save" reRender="name, surname"
action="#{personHome.doSomeStuff()}"
oncomplete="return checkMessage('#{personHome.success}')"
id="a4jSave" />
<h:commandButton id="save" value="Save"
action="#{personHome.persist}"
style="visibility:hidden" />
</h:form>
JavaScript:
<script language="javascript">
function checkMessage(success) {
if(success =='false')
{
return confirm('Do you want to submit this form?') ? submitForm() : false;
} else {
submitForm ();
}
}
function submitForm() {
document.getElementById('myForm:save').click();
return false;
}
</script>
Yes you need to use a4j.
Try something like that (non tested, but follow the algorithm) :
<a4j:commandButton onclick="if(messageHasToBeDisplayed){Richfaces.showModalPanel('modalId');}else{doSomeStuff();}" />
...
<a4j:jsFunction name="doSomeStuff" action="#{controller.doSomeStuff}" reRender="..."/>
This shows you how to display a modal panel if necessary. Without more code I can't help you more, but I think this should help you...
精彩评论