Return url from action method?

okay, I typically use
1. return "success"
2. or return "bad_login"
3. or etc. etc.
I now have a situation where a service is telling me the url to direct too. In JSF, how can I send a redirect so the browser points to a new url(with attached parameters in the url to pass to the other application).
I am newb, so go slowly on this please.
thanks,
dean

I got what sounded like a really good answer on the MyFaces user forums. Their answer was this.....
I am not definitely sure, but maybe a navigation handler could help.
*) create a class which extends from
"javax.faces.application.NavigationHandler"
*) create a constructor which takes one parameter which is also a
NavigationHandler - we call it originalHandler
*) override handleNavigation
*) configure this class in your faces-config.xml
*) if the fromAction is a url (e.g. starts with http://) get the
externalContext/response object - cast it to httpServletresponse and
*) call sendRedirect (or so, cant remember now)
*) else call originalHandler.handleNavigation

Similar Messages

  • NEED HELP on returning values from a method

    Hello Java World,
    Does anyone know how to return more then 1 value from a method..
    ex.
    //the following returns one value
    //Person Class
    private String getname()
    return this.name;
    how can i get two values (ex. name and occupation of person)
    Thank you in advance.

    Create a Class which will hold the values you want and return that object. Or return a List, or return an array, or - taking your example with the person, why don't you return the whole person object?
    Thomas

  • Remote Object - not able to get the returned value from java method

         Hi ,
    I am developing one sample flex aplication that connects to the java code and displays the returned value from the
    java method in flex client. Here I am able to invoke the java method but not able to collect the returned value.
    lastResult is giving null .  I am able to see the sysout messages in server console.
    I am using flex 3.2 and blazeds server  and java 1.5
    Here is the code what I have written.
    <?xml version="1.0" encoding="utf-8"?><mx:WindowedApplication  xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#FFFFFF" initialize="initApp()">
     <mx:Script><![CDATA[
    import mx.controls.Alert; 
    import mx.binding.utils.ChangeWatcher; 
    import mx.rpc.events.ResultEvent; 
    import mx.messaging.*; 
    import mx.messaging.channels.* 
    public function initApp():void { 
         var cs:ChannelSet = new ChannelSet(); 
         var customChannel:Channel = new AMFChannel("my-amf", "http://localhost:8400/blazeds/messagebroker/amf");     cs.addChannel(customChannel);
         remoteObj.channelSet = cs;
    public function writeToConsole():void {      remoteObj.writeToConsole(
    "hello from Flash client");
          var returnedVal:String = remoteObj.setName().lastResult;     Alert.show(returnedVal);
    //[Bindable] 
    // private var returnedVal:String; 
    ]]>
    </mx:Script>
    <mx:RemoteObject id="remoteObj" destination="sro" /> 
    <mx:Form width="437" height="281">
     <mx:FormItem>  
    </mx:FormItem>  
    <mx:Button label="Write To Server Console" click="writeToConsole()"/>
     </mx:Form>
     </mx:WindowedApplication>
    Java code
    public  
         public SimpleRemoteObject(){  
              super();     }
      class SimpleRemoteObject { 
         public void writeToConsole(String msg) {          System.out.println("SimpleRemoteObject.write: " + msg);     }
         public String setName(){          System.
    out.println("Name changed in Java"); 
              return "Name changed in Java";
    And I have configured destination in  remote-config.xml
    <destination id="sro">
       <properties>    
        <source>SimpleRemoteObject</source>
        <scope>application</scope>
       </properties>
      </destination>
    Please help me .

    You are not able to get the returned value because if you see the Remote object help you will realise you have to use result="resultfn()" and fault = "faultfn()"
    In this you define what you wish to do.
    More importantly in the remote object you need to define which method you wish to call using the method class like this
    <mx:RemoteObject id="remoteObj" destination="sro" result="r1" fault="f1"  >
         <Method name="javaMethodName" result="r2" fault="f2"/>
    <mx:RemoteObject>
    r2 is the function where you get the result back from java and can use it to send the alert.

  • The problem of return value from a method

    Hi everyone:
    I want return a value from following method. The basic idea is that I want use Num as a parameter to get a value from a field, therefore I can input this value into another database for the display purpose by using other classes. However I got error message when I compiled it.
    "method does not return a value"
    I know it is a problem, but how I can fix it? I need your help. Thanks in advance.
    Dawei
    Method:
    public int Read(int Num) {
    try{
    String qr1 = "select Record form Buffer where Record="+Num+"";
    ResultSet rs = statement.executeQuery(qr1);
    while (!rs.next()){
              int result=rs.getInt(1);
    return(result);
         catch (SQLException e){
                   System.err.println("Error in inserting into database " + e);
                        System.exit(1);
    return 1;

    "select Record form Buffer ...Hopefully "form" is actually "from" in your code.
    You have three points of exit from your routine, and only two return value statements.
    1 -Return inside the while loop has a value.
    2- Return inside the exception block (not sure that '1' would be a valid number)
    3- The very end of the method, just before the last '}' does not have a return statement.
    By the way, this question has nothing to do with JDBC, so another forum might be a better place to post it.

  • Can I get 2 return datatypes from a method?

    I am looking to get a int from a method but also need a boolean value to indicate if it is a valid number which is tested in my method. If it is allowed must I declare the method twice for each datatype?
    Edited by: Yucca on Apr 19, 2008 5:26 PM

    Hi jverd. This is part of my program from last night. I do test in the method for valid value and throw an exception. However if I leave it at that it will still update my object with value and furthe update my ArrayList with the onject. This is not correct. As u see in my code I am already testing my arrayList with a boolean value and find that if I continue so it will be beneficial as I still have 2 more datatypes that need to be tested.
    public void createNew()
         { // start of createNew()
              Person p = new Person();
              String firstName = getName("Create");
              String lastName = getSurname();
              int homeNum = getHome();
              int count =0;
              boolean found = false;
              //Test if the contact is in phonelist already
              for(Person c: phoneList)
                   c = phoneList.get(count);
                   if((c.name).equals(firstName.trim().toUpperCase())&&(c.surname).equals(lastName.trim().toUpperCase()))
                        JOptionPane.showMessageDialog(null,"You may not enter duplicate contacts. \nPlease abbreviate or change the contacts name/surname.","Error",JOptionPane.ERROR_MESSAGE);
                        found = true;
                        createNew();
                        break;
                   count ++;
              // If contact is not in list the update it
              if(found == false)
                   p.name = firstName.trim().toUpperCase();
                   p.surname = lastName.trim().toUpperCase();
                   phoneList.add(p);
    public int getHome()
              int homeNum = 0;
              String home = JOptionPane.showInputDialog(null,"Please enter the contacts home number or press cancel to exit.");
              //If a string was entered make sure it is a integer
              if(home.length() > 0)
                   try
                        homeNum = Integer.parseInt(home);
                   catch(NumberFormatException nfe)
                        JOptionPane.showMessageDialog(null,"You may not use letters as a phone number. Please try again","Error",JOptionPane.ERROR_MESSAGE);
              return homeNum;
         }I want the getHome method to return a boolean value to and pass it up to the part where I test for corectness before updating the arrayList.

  • Trouble returning String from JNI method

    I'm a JNI newbie who is going through the SUN online book on JNI and have put together the 2nd program example (right after "helloworld"), but it is not working right. It is supposed to prompt you for a string, then returns the string that you type in. Right now it compiles without error, but it returns only the first word that I type, not the whole sentence. What am I doing wrong?
    Here's the code:
    Prompt.java
    package petes.JNI;
    public class Prompt
        private native String getLine(String prompt);
        static
            System.loadLibrary("petes_JNI_Prompt");
        public static void main(String[] args)
            Prompt p = new Prompt();
            String input = p.getLine("Type a line: ");
            System.out.println("User typed: " + input);
    }petes_JNI_Prompt.h
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class petes_JNI_Prompt */
    #ifndef _Included_petes_JNI_Prompt
    #define _Included_petes_JNI_Prompt
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class:     petes_JNI_Prompt
    * Method:    getLine
    * Signature: (Ljava/lang/String;)Ljava/lang/String;
    JNIEXPORT jstring JNICALL Java_petes_JNI_Prompt_getLine
      (JNIEnv *, jobject, jstring);
    #ifdef __cplusplus
    #endif
    #endifpetes_JNI_Prompt.c
    #include <jni.h>
    #include <stdio.h>
    #include "petes_JNI_Prompt.h"
    JNIEXPORT jstring JNICALL Java_petes_JNI_Prompt_getLine
      (JNIEnv *env, jobject this, jstring prompt)
         char buf[128];
         const jbyte *str;
         str = (*env)->GetStringUTFChars(env, prompt, NULL);
         if (str == NULL)
              return NULL;  /*  OutOfMemoryError already thrown */
         printf("%s", str);
         (*env)->ReleaseStringUTFChars(env, prompt, str);
         // assume here that user will ty pe in 127 or less characters
         scanf("%s", buf);
         return (*env)->NewStringUTF(env, buf);
    }Thanks in advance!
    /Pete

    OK, I have something that works now by substituting fgets for scanf. I have two other questions:
    1) Do I need to free the memory created in buf? Will it allocate memory every time the method is run? Or will it allocate only once on creation, and so is no big deal?
    2) A minor question: When I run this program in eclipse, the prompt string is displayed in the console only after the input string is entered and displayed. It works fine when I run it from the command line however. I have a feeling that this is a problem with how Eclipse deals with native methods and perhaps nothing I can fix. Any thoughts?
    Thanks
    Pete
    Addendum, the updated code:
    #include <jni.h>
    #include <stdio.h>
    #include "petes_JNI_Prompt.h"
    JNIEXPORT jstring JNICALL Java_petes_JNI_Prompt_getLine
      (JNIEnv *env, jobject this, jstring prompt)
         char buf[128];
         const jbyte *str;
         str = (*env)->GetStringUTFChars(env, prompt, NULL);
         if (str == NULL)
              return NULL;  /*  OutOfMemoryError already thrown */
         printf("%s", str);
         (*env)->ReleaseStringUTFChars(env, prompt, str);
         //scanf("%s", buf);
         fgets(buf, 128, stdin);
         return (*env)->NewStringUTF(env, buf);
    }Message was edited by:
    petes1234

  • Returned array from a method don't work properly over my Servlet

    Hi folks,
    I show you my code and then explain ;).
            double particle_sys[] = new double[100*5];
         double particle[];
      try {
             for(i = 0; i < 10; i++)
              particle_sys[i*5] = 1;
              particle_sys[i*5 + 1] = 0;
              particle_sys[i*5 + 2] = 1;
              particle_sys[i*5 + 3] = 0;
              particle_sys[i*5 + 4] = 0;     
         class call = new class();
         particle = call.MyFailingMethod(particle_sys);Now the code for the class which owns the method I call
    public class Jfjni
         static
                 System.loadLibrary("nativelibrary");
         public native void .........
         public double[] MyFailingMethod(double particle_sys[])
               double particle[] = new double[100*5];
               .... A call to a the native library to recibe the new data of particle_sys ....
             for(int i = 0; i < 10; i++)
              particle[i*5] = particle_sys[i*5];
              particle[i*5 + 1] = particle_sys[i*5 + 1];
              particle[i*5 + 2] = particle_sys[i*5 + 2];
              particle[i*5 + 3] = particle_sys[i*5 + 3];
              particle[i*5 + 4] = particle_sys[i*5 + 4];     
              return particle; 
    }A function in the native code changes the "particle_sys" array, but the returning value stills the same as the original passed to the function.
    Because of this, I have tested returning the array, dont works. I have tested also returning a copy of the array in "particle", dont works.
    Over standalone app and applet it runs correctly in all different ways, when I try it over a servlet the values of the array stand the same as before the method call.
    Please suggestions!
    Edited by: bifiado on Jan 15, 2008 10:27 AM
    Edited by: bifiado on Jan 15, 2008 10:28 AM

    I have partially solutioned this mistake but I have collateral ones. Looks like I forgot to put in web.xml the definition of the class I was calling from the principal servlet class. In other words, I have two classes, one is the extension of Httpservlet and the other (the class that make mistakes) is a class I call to do the JNI work.
    Now, I added in web.xml the definition of the JNI class (before I forgot) and looks the mistakes with arrays works, but know the there's a new problem and get an IOexception on the applet that call the servlet. When I coment the JNI calls the exception dissapears and all works ok, but I am not getting any exception report on the tomcat ".out".
    Please suggestions.

  • Return Subclass From Superclass Method

    Is there a way to have a method from a superclass dynamically return the object cast as the subclass? Basically I'd like to be able to do the following:
    SubClass1 obj1 = new SubClass1 ().setId("x");
    SubClass2 obj2 = new SubClass2 ().setId("x");
    Thanks for any help.
        public class SubClass1 extends SuperClass {
        public class SubClass2 extends SuperClass {
        public class SuperClass {
          private String id = null;
          public ????? setId (String x) {
            id = x;
            return this;
        }

    As muel said you should try use abstract dependencies whenever possible and a supertype should never have a dependency to a subtype. However, there are situations where you allready have a dependency to a specific subtype (from somewhere outside this inheritance tree). Java 1.5 introduced a slight modification on the method overriding rules to allow you to do this (something they should have done from the beginning):
    class A
        private String id;
        A setId(String s)
            id = s;
            return this;
    class B extends A
        B setId(String s)
            super.setId(s);
            return this;
    }

  • Capture Return Value from Contextual Events Subscriber Method

    Hi
    I was wondering if anyone knew whether you could capture the return value from a method exposed as  a subscriber for a contextual event?
    Requirement: We have 2 bounded task flows (parent-child) with the child task flow embedded as a region in a view activity in the parent task flow.  Based on an action in the parent task flow we raise a contextual event which calls an application module method exposed as a data control within the child task flow.  We need to be able to capture the return value from the method on the managed bean.
    Example method within child task flow application module:
    public String contextualEventSub(){
      Return "Y";
    So here we would like to capture String value when the event is raised by the event producer (parent task flow action).
    Within the Event Map on the page definition of the parent task flow view activity it is possible to set parameters to pass to the subscriber but it’s not obvious where you can capture the return value.
    Many thanks!
    Technology:
    ADF 11.1.1.7 – ADFbc with ADF task flows and page fragments

    Check this URL it may help you
    One size doesn't fit all: JDev 11g: Programmatic Contextual Events

  • Why findCtrlBinding fails in action method?

    And here we are...
    In JDeveloper 10.1.3 EA I have a JSF JSP page with backing bean.
    Drag and drop a View Object (called "VoPolizasAsociadasEntidadExterna1") from Data Contol Palette as ADF Table Read-Only. The table is called "tablePolizas".
    Drag and Drop an ADF CommandButton from Component Palette. The button is called "cmdBtnCrear".
    In the backing bean I have a private method to execute my ViewObject, (as you will see, ViewObject has a bind variable):
    private void ejecutarConsultaPolizas(){
    DCBindingContainer dcbc;
    DCControlBinding cb;
    String rutEntidad;
    ViewObject vo;
    FacesContext ctx =FacesContext.getCurrentInstance();
    ValueBinding vb = ctx.getApplication().createValueBinding("#{SessionManager.rutEntidad}");
    rutEntidad = vb.getValue(ctx).toString();
    dcbc = this.getBindingContainer();
    cb = dcbc.findCtrlBinding("VoPolizasAsociadasEntidadExterna1");
    vo = cb.getViewObject();
    vo.setNamedWhereClauseParam("RUT_ENTIDAD", rutEntidad);
    vo.executeQuery();
    Then I call this method within the "getter" method of the tablePolizas table. Works fine:
    public CoreTable getTablePolizas() {
    ejecutarConsultaPolizas();
    return tablePolizas;
    The ADF Table show filtered data as expected !!!!
    But when ejecutarConsultaPolizas() method is called from action method of CommandButton "cmdBtnCrear":
    public String cmdBtnCrear_action() {
    ejecutarConsultaPolizas();
    return null;
    The following exception is thrown:
    javax.faces.FacesException: #{backing_CrearUsuario.cmdBtnCrear_action}: javax.faces.el.EvaluationException: java.lang.NullPointerException
    In debug mode run step by step and encounter that exception is thrown in the following line of ejecutarConsultaPolizas():
    cb = dcbc.findCtrlBinding("VoPolizasAsociadasEntidadExterna1");
    The ejecutarConsultaPolizas() method fails when is called from an action method. Why?
    There is something in the JSF Life-Cycle that I must consider?
    JSF/ADF got me going crazy!!!!!
    Thanks for your help!

    You need to add the reference to the ADF binding using managed properties on the bean
    In the backing bean create
    private BindingContainer bindings;
    public BindingContainer getBindings() {
    return this.bindings;
    public void setBindings(BindingContainer bindings) {
    this.bindings = bindings;
    In the faces-config.xml file ad the following to your backing bean configuration
    <managed-bean>
    <managed-bean-name>your bean name</managed-bean-name>
    <managed-bean-class>your.bean.class</managed-bean-class>
    <managed-bean-scope>request or session or application</managed-bean-scope>
    <managed-property>
    <property-name>bindings</property-name>
    <value>#{bindings}</value>
    </managed-property>
    </managed-bean>
    <managed-bean>
    In your backing bean code you can now use
    getBindings() to access the business service. Note that you need to call the getDataProvider and the cast it to the BC AM
    Frank

  • From-action

    I understand from-outcome, but is from-action not outdated in the beta? I thought "Action-Klasses" are gone....
    <!--
    The "from-action" element contains an action reference expression
    that must have been executed (by the default ActionListener for handling
    application level events) in order to select this navigation rule. If
    not specified, this rule will be relevant no matter which action reference
    was executed (or if no action reference was executed).
    This value must be of type "Action".
    -->
    <!ELEMENT from-action (#PCDATA)>

    The "Action" API is indeed gone, but the concept is still useful. Consider a submit button coded like this:
      <h:command_button ... action="#{mybean.submit}"/>You can define navigation rules that only pay attention to the outcome returned by this action method, by including the following in your navigation case:
      <from-action>#{mybean.submit}</from-action>Craig McClanahan

  • RE: (forte-users) returning variants from OLE methodcalls

    I'm getting an error when calling an OLE method which
    requires two VARIANT
    parameters, one input and one output. Both parameters are treated as
    arrays
    by the OLE method.
    Error during Invoke; status code: -2147352562(0x8002000E)This error is "Invalid Number of Parameters"
    The code itself, I cannot really comment on as I have had very little
    experience with COM objects
    Cheers
    David McPaul
    Lumley Technology
    This message has been Content Filtered by MailMarshal.
    ---------------------------------------------------------------------

    As an FYI, to find out what the error message means, you can take the hex
    number (in this case 0x8002000E) and search through the winerror.h file.
    That will give you a better idea of what the actual problem is.
    Katie Tierney
    Akili Systems Group
    601 Jefferson, Suite 3975
    Houston, Texas 77002
    Office: (713) 655-1400
    Cell: (409) 255-1643
    "The bitterness of poor quality remains long after the sweetness of low
    price is forgotten" --Larry Anderson
    -----Original Message-----
    From: David McPaul [mailto:dmcpaullumley.com.au]
    Sent: Tuesday, March 07, 2000 5:27 PM
    To: 'Isaak Peretsman'; forte-userslists.xpedior.com
    Subject: RE: (forte-users) returning variants from OLE method calls
    I'm getting an error when calling an OLE method which
    requires two VARIANT
    parameters, one input and one output. Both parameters are treated as
    arrays
    by the OLE method.
    Error during Invoke; status code: -2147352562(0x8002000E)This error is "Invalid Number of Parameters"
    The code itself, I cannot really comment on as I have had very little
    experience with COM objects
    Cheers
    David McPaul
    Lumley Technology
    This message has been Content Filtered by MailMarshal.
    For the archives, go to: http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To unsubscribe, send in a new
    email the word: 'Unsubscribe' to: forte-users-requestlists.xpedior.com

  • Is there a way to get "clientId" from an action method?

    Actions and action listeners are similar, but there is an important difference. The listener does not return a view for navigation, but an action does not get the ActionEvent parameter, and hence does not have a trivial way to get at the client id that invoked it.
    Sometimes its seems you need both.
    If an action can fail and you cannot know for certain until the action is attempted (for example, a database operation), it is nice to be able to queue a message to the component that invoked the action and redisplay the view which now contains the error indication. On success however, an new view should be navigated to.
    This requires that the action get at a client id, and often the logical client id is of the component the user used to invoke the action. Is there a built in way to get this id from an action method?
    Ideally an action should have the signature Object action(ActionEvent) or am I missing something?

    hanafey wrote:
    Unfortunately this requires both action and actionListener be specified in the viewThere is a nasty workaround possible where you get the clientId of the invoked button from the RequestParameterMap so that you can only use the UICommand action method, but I wouldn't recommend that.
    and if the listener is forgotten the message will get attached in the wrong place, or end up global.Isn't that just a developer fault?
    Also, is'nt there a (tiny) concern about multi-threaded failure if a user happens to have two windows open on the same application?Not if your bean is request scoped. If your bean is session scoped, then the user have to be very fast, or your server have to be very slow. With very I really mean very+.
    The other way I considered was via binding, but his also burdens the view with an extra attribute.What is your functional requirement after all? Sounds like to me that you rather need f:setPropertyActionListener or f:attribute. Also see http://balusc.blogspot.com/2006/06/communication-in-jsf.html for some examples and new insights.

  • How to obtain a URL from a path in a class' method?

    Hey everyone!
    Newbie here needing to convert the following method from a jsp page into a class for one of our applications.
    I have a method in a class which takes a path (as a string). However, I can't seem to figure out how to have java output the corresponding URL in a jsp page.
    For example, in the jsp file, I would provide something like:
    "./../../../../../../temp/gfx/" as the path.
    The "getRealPath()" method converts it nicely to a URL. However, I can't seem to figure out how to use this method within a class file. Is there a way to obtain the URL from a class' method? If so, how?
    --- old code below ---
    ServletContext application = getServletConfig().getServletContext();
    String msg = "";//#Either the IMG tag or message to be returned.
    File dir = new File(application.getRealPath(IMAGE_DIRECTORY));

    Thanks for that hint!
    Also, we're using Websphere... is there an easy way to take a partial url passed as a string and find the full path for it?
    Example:
    /images/today/
    and have it automatically converted to:
    F:/Inetpub/wwwroot/images/today/
    automatically in java?
    Or is this something where both a full system path and URL need to be passed?
    Thanks!

  • Returning multiple values from a method

    I have to return a string and int array from a method (both are only of size 5 for a total of 10) What would be considered the best manner in which to do this ?
    Dr there's 10 points in it for you or whoever gives me the best idea ;-P

    hey here it is easy that you can return many things
    what ever you want from a single method man....
    you know the main thing what you have to do is.....
    Just create a VECTOR or LIST object, then add all the
    values what ever you want to return like string and
    int array like etc...
    Then make the method return type is VECTOR and after
    getting the Vector you can Iterate that and you can
    get all the values from that method what ever you
    want....
    jus try this,,,,,,,,,,
    Its really work......
    reply me..but it relies purely on trust that the returned collection would contain exactly the right number and type of arguments

Maybe you are looking for

  • How to put smileys in my e-mails ?

    how to put smileys in my e-mails ?

  • Can I go back n forth between FCE HD and iMovie?

    Hey all, I'm new to FCE HD and I love love love it. But I still need to use some of my iMovie crutches while getting up to speed. I recently shot a wedding in HDV and pulled all the clips together in FCE HD. Can I move the clips to quicktime and then

  • Handle Event for Characters At Serial Port in an eventstructure

    I want to write an event driven application for serial communcation without polling for characters at serial port, instead I want to have an event case in the event structure for this event. Is this possible and how can i do it?

  • CCMS auto reaction methode

    Hi guys, can anybody explain me how I get an email for every alert within the same MTE (ccms) Auto reaction method is CCMS_ON_ALERT_EMAIL Thanks Christian

  • Even Keyframe spacing

    I have a composition in which my keyframes are too close to each other making my clip way too fast. I researched online a method and it said that when you right click on a keyframe and click on "Keyframe Interpolation", than go to "Rove Across Time"