java—将基因搜索结果打印到html选项卡

vwoqyblh  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(280)

我已经创建了一个托管bean来搜索基因数据库,目前它只将结果返回到glassfish控制台。我想知道是否有人可以提供任何建议,如何让我的搜索结果显示到我的基因/蛋白质搜索标签。
我当前的代码集:
主页.xhtml

<?xml version="1.0" encoding="UTF-8"?>

<html xmlns="http://www.w3.org/1999/xhtml">

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <!-- this allows the page to see the welcomepage style sheet-->
    <link rel="stylesheet" type="text/css" href="Group1/welcomepage.css"   media="screen"/>
    <title>Main Page</title>
    <!-- allows the page to see the jquery function see "http://jquery.com/" for description -->
    <script src="jquery-1.11.0.min.js" type="text/javascript"></script>
    <!-- allows the page to see the js script tabs see file for detailed comments-->
    <script type="text/javascript" src = "tabs.js"></script>
    </head>

    <body>
        <!-- the wrapper places everyting in one frame so the objects do not move when  browser size is altered-->     
       <div id ="wrapper">  
        <div id = "main">
            <div id ="header">

                    <!-- again the logo this one will appear in the header in the top left and when clicked returns you to the home page -->
                <a href="index.xhtml">
                    <img  id ="logo1"  alt="Group1 logo"/>
                </a>

                <!-- this is the single search bar and button the "this.select()" function selects all the content in the search box in one click-->

                <form name="Search" onsubmit="#{SearchUniprot.query}"> 
                    <input type="text" id ="GeneralSearch" name="Search" value="#{SearchUniprot.userSearch}" onclick="this.select();"/>
                    <input type="submit" id ="subSearch" value="Search" name="GenSearchButton"/>
                </form>    
              </div>   

        <!-- tab container this created the tabs according the to style set out in the CSS -->
        <div id="tab-container">  
            <ul class="tab-menu">  
                <li id="Start" class="active">Start</li>  
                <li id="Genes">Genes/Proteins</li>  
                <li id="Litrature">Litrature</li>  
                <li id="Analysis">Analysis</li>
            </ul>  
        <div class="clear"></div> 

        <!-- each div section below determines what is written in each tab -->  
        <div class="tab-top-border"></div>
            <div id="Start-tab" class="tab-content active">
                <h1>Recent Activiy</h1>
                <p>Recent files will be shown here</p>  
            </div>

            <div id="Genes-tab" class="tab-content">
                <h1>Genes and Proteins</h1>
                <p>Results for genes and proteins based on search </p>
            </div>

            <div id="Litrature-tab" class="tab-content">  
                <h1>Litrature</h1>
                <p>Results of Litrature search will be shown here</p>
            </div>

            <div id="Analysis-tab" class="tab-content">  
                <h1>Analysis</h1>
                <p>A type of analysis will be shown here</p>
            </div>

            </div>

            </div>
          </div>     
    </body>
</html>

searchuniprot.java文件

package TestGeneSearch;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

@ManagedBean (name ="SearchUniprot" )
@RequestScoped
public class SearchUniprot {

   String userSearch;         

    public String getUserSearch() {
        return userSearch;
    }

    public void setUserSearch(String userSearch) {
        this.userSearch = userSearch;
    }

    public SearchUni getQuery() {

        // make a new object of the SearchUniProt class and set the search term - obviously we need to read this in from the user in a demo
        SearchUni query = new SearchUni("tuna");
        //run the RunQuery method in SearchUniprot
        query.RunQuery();

        return query;
    }

    public SearchUniprot() {

    }

}

搜索uni.java

package TestGeneSearch;

import javax.ejb.Stateful;
import uk.ac.ebi.webservices.axis1.stubs.ebeye.EBISearchService_PortType;
import uk.ac.ebi.webservices.axis1.stubs.ebeye.EBISearchService_Service;
import uk.ac.ebi.webservices.axis1.stubs.ebeye.EBISearchService_ServiceLocator;

@Stateful

public class SearchUni {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

        //searchterm = what you want to search for
        private String searchterm;

    public SearchUni() {
    }

//constrcutor
    public SearchUni(String s) {
        searchterm = s;
    }

    public String[] RunQuery() {
        try {

            //set up to connect to the searchservice
            EBISearchService_Service service = new EBISearchService_ServiceLocator();
            EBISearchService_PortType srvProxy = service.getEBISearchServiceHttpPort();
            // Get the number of results for the query - we don;t necessarily need this but it may be useful
            int result = srvProxy.getNumberOfResults("uniprot", searchterm);
            System.out.println(result);

            //get all results IDs - can easily limit it to however many we want
            String[] ids = srvProxy.getAllResultsIds("uniprot", searchterm);
            for (int i = 0; i + 1 < ids.length; i++) {
                System.out.println(ids[i]);
            }

            //get more fields - the fields we can get depend on the database to be searched. 
            //a note about protein names in Uniprot - Uniprot contains two sections, reviewed and unreviewd
            //the reviewed entries will have a Reccomended Name (descRecName), the unreviewed entries will have
            //a Submitted name (descSubName)  - so each of our results will have either a descRecName or a descSubName
            //but not both.
            //gene name (gene_primary_name) may be null
            //accession number (acc) is a stable identifier - the id field printed out above is not the same as an
            //accession number and shouldn't be assumed to be stable

            String fields[] = {"acc", "descRecName", "descSubName", "gene_primary_name", "organism_scientific_name"};
            String[][] results = srvProxy.getResults("uniprot", searchterm, fields, 1, 100);
            for (int i = 0; i < result; i++) {
                for (int j = 0; j < fields.length; j++) {
                    System.out.println(results[i][j]);
                }
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
       return null;  
    }
}
3j86kqsm

3j86kqsm1#

您只能在控制台中看到结果,因为您只是在此行中打印结果

System.out.println(ids[i]);

您需要做的是将这些结果存储在某个地方,使它们对托管bean可用(例如,存储在托管bean属性中),并通过这个属性getter和setter使这些信息在xhtml中可用。
有一件事我还不清楚,那就是为什么您需要一个有状态的ejb来完成这个任务。如果您只需要查询数据库并显示结果,那么您可能更喜欢使用无状态ejb,它更简单,而且可能性能更好。
我还建议您使用一些jsf前端库,比如primefaces,这样您就可以使用一整套丰富的gui元素了。在您的特定情况下,由于您处理的是基因组数据,因此某些结果(我猜)可能会非常大,您可能希望使用一些惰性加载特性,这些特性对于primefaces来说是微不足道的(没有这些特性就不那么微不足道了)
逻辑是这样的
xhtml

<?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">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</h:head>
<h:body>
    <h:form>
        <p:inputText id="criteria" value="#{myMB.criteria}"/>
        <p:inputText id="result" value="#{myMB.result}"/>
        <p:commandButton value="query" action="#{myMB.query}" update="result"/>
    </h:form>
</h:body>
</html>

当您点击query按钮时,将调用mymb.query()方法,mymb.criteria填充在托管bean中,如下所示

package mypackage;
import java.io.Serializable;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class MyMB implements Serializable{

    private static final long   serialVersionUID    = 1L;
    private String criteria;
    private String result;

    @EJB
    private MyEJB myEJB;

    public void query(){
        this.result = myEJB.query(this.criteria);
    }

    public String getCriteria() {
        return criteria;
    }

    public void setCriteria(String criteria) {
        this.criteria = criteria;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

}

注意,我在这里使用了这样的无状态ejb

package mypackage;
import javax.ejb.Stateless;

@Stateless
public class MyEJB {

    public String query(String criteria) {
        //do your query here
        return "xyz";
    }

}

查询完成后,结果将转到mymb.result,但仅在xhtml处理之后显示

update="result"

注意,上面一行中的“result”不是mymb.result,而是id=“result”的xhtml标记
我希望现在更清楚了。

相关问题