javascript - How to show Ajax message from JSF bean? -


i trying fire alert message given java function. system simple this:

    public class adminbean extends abstractlistbean {      private collection <hours> a;     private modeldto selectedmodel;     private string message;  public void insert() {          //some preparations         setmessage("");          if ( selectedmodel!= null ) {                  try{                  //try insert of selected model                 setmessage("success");                  }catch (exception e) {                      setmessage("unespected error");                 }              }else{                 setmessage("not available");             }          //gethttpservletrequest().setattribute("message", getmessage());         //facescontext.getcurrentinstance().addmessage(null, new facesmessage(message));       } 

}

and, @ client side, have wrote xhtml this:

<a4j:commandlink styleclass="inscribirse" rendered="#{model.status eq 'n' , model.styleclass eq 'font-weight:bold;'}">     <a4j:jsfunction name="okclicked" actionlistener="#{adminbean.insert}" oncomplete="redirigir(message)">     <a4j:actionparam name="message" assignto="#{adminbean.message}"/>     </a4j:jsfunction>    <h:outputtext value="inscribirse" />    <f:setpropertyactionlistener target="#{adminbean.selectedmodel}" value="#{model}" /> </a4j:commandlink> 

so, when a4j command clicked, function "insert" runs, see watching database, "redirigir" function, not working:

function redirigir(c){          alert(c);         window.location.href='#{facescontext.externalcontext.request.contextpath}/strutsjsfservlet?beanname=menubean&method=eventos';          } 

my intention show message bean, , refresh page. suggestions?

thank much!

ps: xhtml code inside iteration collection , #{model} alias used in iterator:

<a4j:jsfunction name="okclicked" actionlistener="#{adminbean.insert}" oncomplete="redirigir(message)"> 

this not work. send "message" backing bean, won't sent , may used in javascript function.

assuming want alert(...) message (which in opinion kind of ugly) it's easiest have hidden input field value message. commandlink rerender hidden field can access value after bean invocation via javascript.

with jquery might easy $('input#hidden_input_id').val()

your function redirigir mayb this

function redirigir() {     alert($('input#hidden_input_id').val());     window.location.href='#{facescontext.externalcontext.request.contextpath}/strutsjsfservlet?beanname=menubean&method=eventos'; } 

i can't tell if redirect correct that, problem "message" parameter didn't exist before. without it, should working now.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -