Get parameter from URL in Java code

Hello everyone,
I've got strange problem. I have one JSF page with two controls:
- InputText
- Button
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<af:document title="view12.jsf" id="d1">
<af:messages id="m1"/>
<af:form id="f1">
<af:inputText label="Label 1" id="it98" value="#{param.test}" editable="always"/>
<af:commandButton actionListener="#{bindings.przekierowanie.execute}" text="przekierowanie"
disabled="#{!bindings.przekierowanie.enabled}" id="cb1"/>
</af:form>
</af:document>
</f:view>
And I want to initialize the InputText with parameter from URL (param name is test - value="#{param.test}"). In JSF page everything is fine. But after clicking button I have to read the value from InputText in Java Code, so I have URL:
http://127.0.0.1:7101/Application6-ViewController-context-root/faces/view12.jsf?test=asd
and my Java code which is executed after clicking button is:
public String przekierowanie() {
Map <String,String> map=FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String tttValue=map.get("test");
System.err.println("test:" + tttValue);
     return null;
but this doesn't work... Everytime I get null when I click the button. Could you tell me why and How to obtain this value, from InputTex in my java function?

Hi,
If you have a parameter in URL named as "product", you can get its value like:
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
FacesContext facesContext = FacesContext.getCurrentInstance();
HttpServletRequest httpRequest =
(HttpServletRequest)facesContext.getExternalContext().getRequest();
String product = httpRequest.getParameter("product");

Similar Messages

  • How to get parameter from URL - part II

    Is there a way to assign a value of JavaScript variable to JSF variable?, something like
    <h:commandButton value="Send" actionListener ="#{myBean.myAction}" 
    <f:attribute name="source" value="<some JavaScript variable>"/>
    </h:commandButton>Here is my problem
    Following the thread in http://forum.java.sun.com/thread.jspa?forumID=427&threadID=545973
    I have a facelets page that is used as a "contact us" from this page the information is send to the action bean for saving in the database. We want to know where the users come from to this page. This can be done either by using the "referring page" or adding parameters to the URL - http://mylink?param=myval
    In both cases the problem is that when transferring the information from the faclets page to the action bean the information is lost and instead of showing the "real" referring page or parameter it shows the information of the faclets page.
    One solution to the problem is to save the information in the faclets page in a javascript variable and then transfer it using the f:attribute to the action bean. By the way, the opposing is very easy, one can save easy the value of a JSF parameter in a javascript variable:
    <script type="text/javascript">
         // <![CDATA[
         var foo = "#{myBean.bar}"
    // ]]>
    </script>

    I can, but the EL doesn't contain the "right" value..
    But there is a general question
    Can one use javascript in expression like f:attribute ?
    BTW I solved the above problem by using AJAX like behavior, But I wanted to know if there is another way

  • How to get af:commandbutton id in java code when it is triggered?

    Hi All
    In my application's homepage, I am using 2 af:commandbuttons and each using action attribute to call a method. Both are calling the same method, and based on its id, it should perform different operations. Could anyone please tell me how to get command buttons id in java code, when it is triggered.
    Regards
    Venkat

    Venkat,
    why not call different methods from each button?
    public String actionButton1()
    return doAction("button1");
    public String actionButton2()
    return doAction("button2");
    public String doAction(String aBuuton)
    if ("button1".equalsIgnoreCase(aButton))
    // do work for button 1
    return "abc";
    }else {
    // do work for button 2
    return "abc";
    }Now you user actionbutton1 for the first button and actionButton2 for the second.
    Or you directly implement two different methods in the bean and call each one directly from the button.
    Timo

  • Search Results web part - Custom Query using "Value with a parameter from URL" inconsistent

    I have encountered what I think may be a bug, but I am hoping that there is something that I am missing.
    Within my search site, I have created a new search results page where I want to customize the "Search Results" web part query.  I can add in any number of property and keyword filters (using the "Build Your Query" dialog) without
    issue... until I add a filter that uses the QueryString property (the builder dialog calls this "Value with a parameter from URL").
    If I use {QueryString.MyParameterX} for filtering, it works beautifully in the query builder dialog.  I see the expected results in the search results preview pane, but as soon as I apply the changes things become inconsistent. 
    If I close/reopen my browser and navigate to my page at http://myaddress/search/Pages/testresults.aspx?MyParameterX=test I see results.  If I then refresh the page, I get a "Nothing here matches your search" message.  I can then go to
    the same address but change one character to an uppercase character and get results.  Refreshing that same page again returns "Nothing here matches your search".  I can only get search results one time per uniquely cased URL without having
    to close/reopen my browser.  This behavior was seen on both Firefox and IE.
    Finally, I found that if I instead navigate to http://myaddress/search/testresults?MyParameterX=test, it always returns results.  This, unfortunately isn't the best solution for me... but it is a solution.
    Any insight that anyone can provide is greatly appreciated!  I would really like to be able to depend on this working in all logical cases (especially since the search center of other sites is set using the path all the way down to /Pages).
    Thanks!

    Hi, have you been able to solve this issue? I'm getting the same issue and I cant solve it (required CU is installed).
    Fabio

  • Removing jsessionid parameter from url of Webdynpro iview

    Hi All,
             While i create a Webdynpro iview from SAP Webdynpro iview template, the generated url gets appended with the parameter jsessionid as shown.
    http://server:port/webdynpro/dispatcher/local/session/New_app;<b>jsessionid</b>=(J2EE14778100)ID1600385450DB11689045888563713719End
    I don't want this parameter to be appended and exposed in the url of the ivew. Is there any way i can hide/remove this parameter from the generated url?
    Regards,
    Vijay.K

    Hi All,
             I found that, the Webdynpro template which is an App-Integrator appends the parameter jsessionid to the generated URL. So, i tried changing some properties of the system regarding session, but i couldn't remove this parameter from URL.
    I also found that, custom Application integrators can also be developed. So, is it possible to get rid of the jsessionid parameter by developing a custom App-Integrator for Webdynpro application?
    Please help me in this regard.
    Regards,
    Vijay.K

  • How to send sms to mobile from tomcatserver using java code?

    Hi,
    Could you please let me know that,
    How to send sms to mobile from tomcatserver using java code? Please provide the code snippet.
    Thanks in advance.

    Yes, but something needs to send that message. You can't just take an arbitrary computer and send an SMS, it does not have the hardware to do that.
    So either you have a mobile through which you do that or more likely - you use some sort of online service to do it. Whatever choice you make will determine what code you will have to write to get it done. Nobody is going to deliver the code to you, that's your job. It is also your job to figure out what service you are going to use.

  • Pass data parameter from URL to Forms

    Hi
    Is it possible to pass a data parameter from asp to Forms?.
    In my asp I have a url to call a form (eg. http://servername:port/forms90/f90servlet/form=testform.fmx). In my testform.fmx I accept 'account no' as a parameter for querying the records. Since I am calling this form from asp, I already have the account no in my asp. I would like to pass this account no to the form automatically.
    Is it possible to pass this data parameter from url to forms?.
    If possible, what changes to be made in the form. Please help.
    sreekumar

    Create a parameter in your form, there's a node for it in the Navigator window. Imagine it is called myParam.
    Pass it on the URL like this:
    http://host/forms90/f90servlet?config=myApp&otherParams=myParam=somevalue
    Regards,
    Robin Zimmermann
    Forms Product Management

  • Getting resultset from some other java program

    how could i getting resultset from some other java program?
    plz

    a resultset is directly linked to your (prepared) query.
    for performance(and synchronization) reasons, you do want to retrieve the data as fast as possible and then release it.

  • Using unzip from unix in java-code ...

    Hi people,
    i have problem, i want to use the command unzip from unix, to unzip a zip-file, the commend unzip must invoke from java-code. Can someone help me. I use the zip-api, but i have 100Mb zip-file, it needs very long time to unzip the zip-file.
    thanks for your help ...

    ok, not sure how much improvement this will give in general, but its given a reliable 25% speed increase on my mini tests
    using the nio libraries will also get you a lot further, and is the way to go if you are very keen on speed
    asjf
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import java.util.zip.*;
    import javax.swing.*;
    public class Unzipper {
         private Unzipper() {}
         private static byte[] buffer = new byte[16384];
         public static void unzip(File file, Component parentComponent,     File outputDir) throws ZipException, IOException {
              unzip(new ZipFile(file), parentComponent, outputDir);
         public static void unzip(File file, int mode, Component parentComponent, File outputDir) throws IOException {
              unzip(new ZipFile(file, mode), parentComponent, outputDir);
         public static void unzip(String name, Component parentComponent, File outputDir)     throws IOException {
              unzip(new ZipFile(name), parentComponent, outputDir);
         public static void unzip(ZipFile zip, Component parentComponent, File outputDir)     throws IOException {
              if ( zip == null) {
                   throw new NullPointerException("outputDir is null");
              int size = zip.size();
              if (size > 0) {
                   if (outputDir == null) {
                        throw new NullPointerException("outputDir is null");
                   if (!outputDir.exists()) {
                        outputDir.mkdirs();
                   ProgressMonitor monitor =
                   new ProgressMonitor(parentComponent,
                   "Unpacking " + zip.getName() + "...", "", 0, size);
                   monitor.setMillisToDecideToPopup(0);
                   monitor.setMillisToPopup(0);
                   Enumeration entries = zip.entries();
                   for ( int i = 0; entries.hasMoreElements(); ) {
                        ZipEntry entry = (ZipEntry) entries.nextElement();
                        /*if (entry.getMethod() == ZipEntry.DEFLATED)
                        System.out.println(" Inflating: "+entry.getName());
                        else
                        System.out.println(" Extracting: "+entry.getName());*/
                        monitor.setNote(entry.getName());
                        File File = new File(outputDir, entry.getName());
                        File.getParentFile().mkdirs();
                        if (!entry.isDirectory()) {
                             InputStream in = null;
                             OutputStream out = null;
                             try {
                                  in = zip.getInputStream(entry);
                                  out = new FileOutputStream(File);
                                  for (int n = 0; (n = in.read(buffer)) > -1; )
                                       out.write(buffer, 0, n);
                                  monitor.setProgress(++i);
                             } finally {
                                  if (out != null) {
                                       try {
                                            out.close();
                                       } catch (IOException e) {
         public static void main(String[] args) throws ZipException, IOException
              if (args.length !=2) {
                   System.err.println("Usage: java Unzipper <zip file> <output dir>");
                   System.exit(1);
              long start = -System.currentTimeMillis();
              unzip(args[0], null, new File(args[1]));
              System.out.println(start+System.currentTimeMillis());
              System.exit(0);

  • How to get data from php to java via xmlrpc

    I have been trying to get data from php through apache xmlrpc to java.
    I do get an value as result. The result is "Array". How how do i convert the XMLRPC Object "Array" to Java Object?
    Inside the XMLRPC "Array" Object there is object too of type Array from php.
    See code for java here
    Object result = client.execute( "blogger.getCategories", params1 );
    Code from php here
    function getCategories($appkey, $username, $password)
         global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue;
         $structArray = array();
         $structArray[] = new xmlrpcval(array("one" => "test"));
         return new xmlrpcresp(new xmlrpcval( $structArray , $xmlrpcArray));     
    I do get Standard String and Integer from php to Java through XMLRPC.
    Can someone help me.
    Edited by: Electron32 on Aug 13, 2010 9:44 AM

    That is what is so strange. I return an 'array' through xmlrpcval() and in Java I tried to cast it to ArrayList, Vector,String[] but get an error
    Object[] result = (Object[]) client.execute( "blogger.getCategories", params1 );
    String[] array = (String[]) result;
    Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
            at com.dirdalit.window.Main.main(Main.java:41)
    Edited by: Electron32 on Aug 13, 2010 12:25 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Preventing JAXB xjc from re-generating java code of import ed schemas...

    Hi, I am using XJC to generate java code from xsd.
    However the xsd I run it on often has imports to another xsd that will be in a jar along with its java classes already existing.
    This jar is on the calsspath too.
    XJC however not only generates java code for existing xsd, but also for every import it has.
    And also for every import each of those imported xsd's might have.
    So if it were a long import chain A->B->C->D it generates code for all.
    How can i get it to generate code for only A and assume all the remaing code can be found on the jars in the classpath.
    The A.xsd also has a catalog file associated with it that has every namespace reference pointing to the correct xsd locations within jars.
    So it even has B->C mapping and C->D mapping. This was needed or else XJC didnt even generate anything at all and complained it could not reach C from B and so on.
    Catalog file solved that problem but not the fact that it keeps regnerating code.
    Thanks
    Edited by: Priyajeet on Dec 9, 2008 1:36 PM

    Problem solved.
    The xjc compiler reads file name in a case-sensitive fashion, even on windows.
    So, common.xsd and Common.xsd are seen as two distinct files.
    This was the cause of the compilation errors, since feature1 imported the schema using the filename Common.xsd, whereas the other schemas imported common using common.xsd
    I hope this could help.
    Salvatore

  • Author       "javax.sound.midi.InvalidMidiDataException: cannot get soundbank from stream" after java update

    Not sure where to post this issue.
    I am noticing this error since I did the Mac update. The Mac update included the java update. Right now the java version is 1.6.0_31. My Mac OS X version is 10.7.3. I am seeing the problem for all the soundfont files that I am trying to load. The error i get is.
    javax.sound.midi.InvalidMidiDataException: cannot get soundbank from stream
         at javax.sound.midi.MidiSystem.getSoundbank(MidiSystem.java:565)
         at myPackage.MyMusicApp.main(MyMusicApp.java:14)
    Below is a small program I built that shows the code.
    package myPackage;
    import java.io.File;
    import javax.sound.midi.*;
    public class MyMusicApp {
        public static void main(String[] args) {
            try {
                Synthesizer synth = MidiSystem.getSynthesizer(); synth.open();
                File f =  new File("/Users/poorav/eclipseGIT/myApp/soundbanks/1247_KitDRY.sf2");
                Soundbank soundbank = MidiSystem.getSoundbank( f);
                synth.loadAllInstruments(soundbank);
            } catch (Exception e)
                e.printStackTrace();
    I am not sure what the previous build of java I was on, but i know that it was a 1.6 version. Any ideas of what could have caused this?
    thanks

    No satisfactory progress!
    I submitted a bug for this using the Apple bug reporter on 9th April (#11208868) and despite asking for an update, it has been completely ignored (even now). I'm not impressed.
    I then issued a (paid for) Developer Technical Support issue which was credited back to my account a few days later with no explanation. When I asked why, I eventually got: "At this time DTS does not provide code-level support for Java"!
    So, Apple are assuming to responsibility for this problem. I realise that Oracle is mostly responsible for Java but Apple took this crippled version (how much testing did they do?) and updated our customers' machines with it. This has effectively disabled a key feature of our product and has cost us damage to our company's reputation. Still Apple don't care and they rely on the fact that we are too small to sue them. You can see I'm not happy! I naively thought Apple would make some attempt to assist their developers.

  • Getting parameters from URL: use of Special Chars

    I'm unable to retrieve the Special Chars from URL parameters.  Does someone have an idea where to look for?
    Examples where no Special Chars is retrieved :
    ...App?param=Aménagement
    ...App?param=Am<é>nagement
    ...App?param=Am%E9nagement
    I'm using this code :
              IWDProtocolAdapter protocolAdapter =
                   WDProtocolAdapter.getProtocolAdapter();
              IWDRequest request = protocolAdapter.getRequestObject();
                                    String param = request.getParameter("param");
    Thanks!

    okay, So if I use :
    ...App?param=Am%E9+nagement
    How would you then integrate URLDecoder.decode in the following code?
    IWDProtocolAdapter protocolAdapter =
         WDProtocolAdapter.getProtocolAdapter();
    IWDRequest request = protocolAdapter.getRequestObject();
    String param = request.getParameter("param");

  • Passing Parameter from URL to Web Forms - Oracle 10 Application Server

    Hi All -
    I want to pass parameter from a URL to 10g Oracle Web Forms - Oracle Application Server 10.1.2
    http://server1/forms/frmservlet?config=SATWEB_SSO&otherparams=username_sso=BABUS
    How to receive this 'username_sso' value inside my forms application ?
    Created a Parameter in the same name as URL parameter 'username_sso' in forms but didn't receive the value. I want to know how to receive the value of this parameter within forms from URL.
    Thanks - Suresh

    Try this,
    1. Create a parameter in the formsweb.cfg (say username_sso) under default section ( or you can create it in your own config section)
    2. Add the username_sso in otherparams parameter as username_sso=%username_sso%
    3. Add this username_sso parameter in your form.
    4. Run the form as
    http://<machine>:<port>.....?form=blahblah....&otherparams=username_sso=scott
    Regards,
    Arun

  • Invoke the command unzip from unix in java-code ...

    Hi people,
    i have problem, i want to use the command unzip from unix, to unzip a zip-file, the commend unzip must invoke from java-code. Can someone help me. I use the zip-api, but i have 100Mb zip-file, it needs very long time to unzip the zip-file.
    thanks for your help ...

    use Runtime.exec() to call your unix "unzip" command from java, if its much faster.

Maybe you are looking for

  • IPod Touch 5th gen starting music by itself.?

    My IPod Touch 5th generation has this problem that when I choose to play some music after sometime it will either pause, skip, or fast forward the song. Even if the IPod is locked. Sometimes it even turns on Siri. This all started yesterday, by the w

  • IPod Nano 6th gen won't sync - help please!

    I lost my iTunes and all my music when my laptop died, but managed somehow to get it all back onto my new laptop - none of my music is purchased though iTunes but downloaded separately or from CDs. However when I sync my iPod it doesn't actually chan

  • Mirror iPad to television?

    Hello everyone. I am trying to figure out how to mirror my iPad 2 to my tv. I have a new Mac mini hooked up to my tv as a monitor with wifi and hdmi. Do I need appletv or AirPlay since I have the Mac mini?

  • Mail converts all attached images to bmp

    I need to send all my (attached) images as jpg or gif. but windows recipients complain they are receiving them as bmp files. i do have windows friendly setting activated. any ideas?

  • Cannot read Java array in javascript. Please see my code

    Here is the script <webuijsf:script binding="#{temp.script2}" id="script2"> foo() var picture = <%=getApplicationBean1().getPictureDirName()[1].toString()%>; </webuijsf:script> <webuijsf:body binding="#{temp.body1}" id="body1" onLoad="foo();" style="