redirect - JSF commandbutton ajax: how to capture the success/fail event -
my current code.
<h:form> <h:panelgroup id="messagepanel" layout="block"> <h:messages errorstyle="color: red" infostyle="color: green" layout="table"/> </h:panelgroup> <h:panelgrid columns="2"> // form input stuff here.. </h:panelgrid> <h:commandbutton class="register-btn" action="#{accountcontroller.create}" value="#{bundle.register}"> <f:ajax event="action" execute="@form" render="messagepanel"/> </h:commandbutton> </h:form>
messagepanel validation errors displays.
i want know how capture success event.
[done] if user input wrong values, ajax validation , displays wrong values
[problem] if success should redirect page.
**updated
create method
public string create() { seek { getfacadeuser().create(currentuser); jsfutil.addsuccessmessage(resourcebundle.getbundle("/bundle").getstring("accountcreated")); homecoming preparecreate(); } grab (exception e) { jsfutil.adderrormessage(e, resourcebundle.getbundle("/bundle").getstring("persistenceerroroccured")); homecoming null; } } public string preparecreate() { current = new account(); selecteditemindex = -1; homecoming "index"; }
i'm using jsf 2.1
this not right way redirection ajax request. should utilize externalcontext.redirect() instead:
facescontext.getcurrentinstance().getexternalcontext().redirect("yoururl");
in way receive partial response server to, redirection:
<partial-response> <redirect url="yoururl"> </redirect> </partial-response>
string returned in method irrelevant, can homecoming null
.
ajax redirect jsf-2
No comments:
Post a Comment