You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Alonso Isidoro Roman <al...@gmail.com> on 2007/10/02 13:15:08 UTC

JSF, Tiles, xml, xsl

Good days people, I am employed at an app that wants to integrate JSF,
tiles, xml and xsl.

Basically the app receives information of the user's interfaz, builds an url
with the above mentioned information and invokes to a service web that a xml
returns with the information. The idea is to generate the exit in format
html or wml with an insole(staff) xsl and to send the result in this format
to every jsp that is going to form a part of the page that it will generate
tiles. at first I understand that it is feasible, i´d like to know if
someone already has done it and since it has done it.

Just now what I have is a managed bean that receives the parameters of the
altar frontal and invokes a method of a service, like this:

public String encuentra(){
        //deja los atributos privados rellenos.
        String mensaje ;
        crearYRellenarBusquedaVO();
        try {
              setResultado(this.getServicio().obtenerResultadosWML(
this.getBusquedaVO()));
              mensaje="succesNoJS";
        }catch(java.lang.IllegalArgumentException e){
            mensaje="error";
        }catch(
es.yell.frontlite.exceptions.SrvBusquedaNoxtrumServiceException e1){
            mensaje="error";
        }catch(Exception e2){
            mensaje="error";
        }
        return mensaje;
    }
//it returns html code!
protected String manejarObtenerResultadosWML(
es.yell.frontlite.service.impl.BusquedaVO busquedaVO)
    throws java.lang.Exception{

        try{
            // xmlOrigen has full xml response from server
            String xmlOrigen =
manejarObtenerResultadosJSActivado(busquedaVO);
     Source xmlSource = new StreamSource(new
StringBufferInputStream(xmlOrigen));
            Source xsltSource = new StreamSource(
SrvBusquedaNoxtrumServiceImpl.class.getResourceAsStream(Constantes.XSL_FILE
));
            StringWriter cadenaSalida = new StringWriter();
            Result bufferResultado = new StreamResult(cadenaSalida);
            TransformerFactory factoriaTrans =
TransformerFactory.newInstance();
            Transformer transformador = factoriaTrans.newTransformer
(xsltSource);
            transformador.transform(xmlSource, bufferResultado);
            System.out.println(cadenaSalida.toString());
            return cadenaSalida.toString();
        }catch(Exception e2){
            throw new
es.yell.frontlite.exceptions.SrvBusquedaNoxtrumServiceException (
e2.getMessage());
        }
    }

With this exit in html, since(as,like) how could i forward it towards a jsp
especially?

faces-config.xml
<navigation-rule>
        <from-view-id>/index.jsp</from-view-id>
        <navigation-case>
            <from-outcome>succesNoJS</from-outcome>
            <to-view-id>/jsDesactivado.jsp</to-view-id>
        </navigation-case>
        <navigation-case>
            <from-outcome>error</from-outcome>
            <to-view-id>/error.jsp</to-view-id>
        </navigation-case>
    </navigation-rule>

-- 

index.jsp

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<f:view>
    <f:loadBundle basename="MessageResources" var="msg"/>
<head>
        <title>
            ${msg.titulo}
        </title>
</head>

<body>
    <h:form id="formulario">
        Que:
        <h:inputText id="campoQue" value="#{yellProxy.campoQue}" />
        Donde
        <h:inputText id="campoDonde" value="#{yellProxy.campoDonde}" />
        <h:commandButton id="boton" value="Encuentra" action="#{
yellProxy.encuentra}"/>

    </h:form>
</f:view>
</body>
</html>

jsDesactivado.jsp

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>

    <h1>JSP Page</h1>
    jsDesactivado!!
    <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
    <%--
    <c:if test="${param.sayHello}">
        <!-- Let's welcome the user ${param.name} -->
        Hello ${param.name}!
    </c:if>
    --%>
        <jsp:getProperty name="yellProxy" property="resultado"/>
    </body>
</html>


regards a lot!

Alonso Isidoro Roman.