[SEAM] 最近用seam Remoting 的碰到个问题不知道怎么解决?

yangyang566566 2010-11-21
GetXMLAction 是我用来解析xml文档的内容 我想利用remoting 将GetXMLAction 的返回值content 回发到客户端中,然后再将返回值嵌套在前台页面上
下面的办法得不到返回值。
我也想过把返回值放到实体bean 中然后再用el表达式求值下面是官方文档说的 内容
25.3. Evaluating EL Expressions
Seam Remoting also supports the evaluation of EL expressions, which provides another convenient method for retrieving data from the server. Using the Seam.Remoting.eval() function, an EL expression can be remotely evaluated on the server and the resulting value returned to a client-side callback method. This function accepts two parameters, the first being the EL expression to evaluate, and the second being the callback method to invoke with the value of the expression. Here's an example:
  function customersCallback(customers) {

    for (var i = 0; i < customers.length; i++) {

      alert("Got customer: " + customers[i].getName());

    }   

  }

  Seam.Remoting.eval("#{customers}", customersCallback); 
In this example, the expression #{customers} is evaluated by Seam, and the value of the expression (in this case a list of Customer objects) is returned to the customersCallback() method. It is important to remember that the objects returned this way must have their types imported (via s:remote) to be able to work with them in Javascript. So to work with a list of customer objects, it is required to import the customer type:
<s:remote include="customer"/>


但是这种办法我不知道可行么?
请问大家有没有好的办法解决这个问题


服务端代码
package org.domain.tohtml.action;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.remoting.WebRemote;

@Name("getxmlaction")
public class GetXMLAction {

@WebRemote
  public String  OutPutHtml( String con) throws IOException
  {
         String file = "";
String filePath="E:/eclipse/workspace/tohtml/WebContent/test.xml";
FileInputStream fileinputstream = new FileInputStream(filePath);//读取XML文件内容
int lenght = fileinputstream.available();
byte bytes[] = new byte[lenght];
fileinputstream.read(bytes);
fileinputstream.close();

String  content = new String(bytes); //取出构建好的XML文档

return content;
}
}

客户端代码:
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:s="http://jboss.com/products/seam/taglib">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <s:remote include="getxmlaction"/>
 
  <script type="text/javascript">   
    function xmlinserthml() {
        debugger;
      var callback = function(result) { alert(result); };
      var value =  Seam.Component.getInstance ("getxmlaction").OutPutHtml();
   
       
              
    }
    function sayHelloCallback(result) {
        alert(result);
      }

function showContent()
{


try
{
          var responseXML = request.responseXML;
var xmldom = responseXML.documentElement;

   document.getElementById("attribute").innerHTML =   xmldom.childNodes.item(0).getAttribute("attribute");
    document.getElementById("content").innerHTML = xmldom.childNodes.item(0).childNodes.item(0).text;
}
catch(exception)
{;}

}
       
  </script> 
</head>
  <body onload="xmlinserthml()">
  <center>
    <table align="center" border="0">
    <tr>
    <td><strong><span id="attribute"> </span></strong></td>
    </tr>
    <tr>
    <td><strong><span id="content"> </span></strong></td>
    </tr>
    </table>
    </center>
  </body>
</html>

Global site tag (gtag.js) - Google Analytics