6 Replies Latest reply on Nov 7, 2009 11:21 AM by nbelaevski

    Help!

      Hi Guys!

      I'm migrating a tool to richfaces. The tool has Session-based and it was listed using h:commandLink when it used jsf:

      <h:column>
       <f:facet name="header" >
       <h:outputText value="#{msgs.items_title}"/>
       </f:facet>
       <h:commandLink id="enterLink" action="#{WbBean.join}" rendered="#{Bean.canJoin}">
       <h:outputText value="#{entry.title}"/>
       </h:commandLink>
       <h:outputText value="#{entry.title}" rendered="#{not Bean.canJoin}"/>
      </h:column>


      When a user clicks in link, the action invokes a void method. This method prepares to send information to the servlet that will generate the JNLP file. So, an application open with Java WebStart.

      I tried using a4j:commandLink, but it didn't open Java WebStart. A page was opened and the JNLP was printed.

      Any suggestion?

      Thanks

        • 1. Re: Help!

          Hi!

          The application works fine when I use jsf:

          <h:commandLink id="enterLink" action="#{Bean.join}" rendered="#{Bean.canJoin}">

          But if I replace with ajax4jsf:

          <a4j:commandLink id="enterLink" action="#{Bean.join}" rendered="#{Bean.canJoin}">

          The page printed the JNLP.

          I think the tag is wrong. The code is right because the application works fine with jsf.
          How to create a link using ajax4jsf that it will open my webStart application?!

          Thanks!

          • 2. Re: Help!
            nbelaevski

            Hi,

            a4j:commandLink doesn't allow direct file downloads.
            Either use h:commnadLink or do redirect to JNLP file in action.

            • 3. Re: Help!

              Hi!

              The method called (when a user clicks in link) is a void of my bean. This method redirect to JNLP file :

              ...
               ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
               HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
               HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
               request.setAttribute(...);
               ...
               ExternalContext extContext = (ExternalContext) FacesContext.getCurrentInstance().getExternalContext();
               ServletContext servletContext = (ServletContext) extContext.getContext();
               ServletContext newcontext = (ServletContext) servletContext.getContext("/my-tool");
               RequestDispatcher dispatcher = newcontext.getRequestDispatcher("/my-servlet-mapping");
               dispatcher.forward(request, response);
               FacesContext.getCurrentInstance().responseComplete();


              A class is called using servlet mapping.This class extends HttpServlet and is a servlet that dynamically generates the JNLP file for clients:

              ...
               response.setContentType("application/x-java-jnlp-file");
               String jnlp = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><jnlp spec=\"1.0+\""+ " codebase=\""+ host + ":" + port + "/"+ "my-tool"+ "\">" ... + "<argument>"+ request.getAttribute(" ... ")+ "</argument>" + ...;
               out.println(jnlp);


              But, when a user clicks in link, the page prints the jnlp. My application doesn't open with Java WebStart.

              Any idea?




              • 4. Re: Help!
                nbelaevski

                 

                ...
                 ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext()
                ;
                 HttpServletRequest request = (HttpServletRequest) externalContext.getRequest();
                 HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
                 request.setAttribute(...);
                 ...
                 ExternalContext extContext = (ExternalContext) FacesContext.getCurrentInstance().getExte
                rnalContext();
                 ServletContext servletContext = (ServletContext) extContext.getContext();
                 ServletContext newcontext = (ServletContext) servletContext.getContext("/my-tool");
                 RequestDispatcher dispatcher = newcontext.getRequestDispatcher("/my-servlet-mapping");
                 dispatcher.forward(request, response);
                 FacesContext.getCurrentInstance().responseComplete();

                I see forward there, but no redirect.

                • 5. Re: Help!

                  I can't redirect to adress that have o jnpl. The problem is that there isn't a "static address" for the jnlp. Because it is generated dynamically:

                  ...
                   response.setContentType("application/x-java-jnlp-file");
                   String jnlp = "<?xml version=\"1.0\" encoding=\"ISO-8859-\"?><jnlp spec=\"1.0+\""+ " codebase=\""+ host + ":" + port + "/"+"my-tool"+ "\">" ... + "<argument>"+ request.getAttribute(" ... ")+"</argument>" + ...;
                   out.println(jnlp);


                  I need of a servlet, that's why I use a mapping.

                  • 6. Re: Help!
                    nbelaevski

                    Use h:commandLink then.