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

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

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

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  5. <!-- this allows the page to see the welcomepage style sheet-->
  6. <link rel="stylesheet" type="text/css" href="Group1/welcomepage.css" media="screen"/>
  7. <title>Main Page</title>
  8. <!-- allows the page to see the jquery function see "http://jquery.com/" for description -->
  9. <script src="jquery-1.11.0.min.js" type="text/javascript"></script>
  10. <!-- allows the page to see the js script tabs see file for detailed comments-->
  11. <script type="text/javascript" src = "tabs.js"></script>
  12. </head>
  13. <body>
  14. <!-- the wrapper places everyting in one frame so the objects do not move when browser size is altered-->
  15. <div id ="wrapper">
  16. <div id = "main">
  17. <div id ="header">
  18. <!-- again the logo this one will appear in the header in the top left and when clicked returns you to the home page -->
  19. <a href="index.xhtml">
  20. <img id ="logo1" alt="Group1 logo"/>
  21. </a>
  22. <!-- this is the single search bar and button the "this.select()" function selects all the content in the search box in one click-->
  23. <form name="Search" onsubmit="#{SearchUniprot.query}">
  24. <input type="text" id ="GeneralSearch" name="Search" value="#{SearchUniprot.userSearch}" onclick="this.select();"/>
  25. <input type="submit" id ="subSearch" value="Search" name="GenSearchButton"/>
  26. </form>
  27. </div>
  28. <!-- tab container this created the tabs according the to style set out in the CSS -->
  29. <div id="tab-container">
  30. <ul class="tab-menu">
  31. <li id="Start" class="active">Start</li>
  32. <li id="Genes">Genes/Proteins</li>
  33. <li id="Litrature">Litrature</li>
  34. <li id="Analysis">Analysis</li>
  35. </ul>
  36. <div class="clear"></div>
  37. <!-- each div section below determines what is written in each tab -->
  38. <div class="tab-top-border"></div>
  39. <div id="Start-tab" class="tab-content active">
  40. <h1>Recent Activiy</h1>
  41. <p>Recent files will be shown here</p>
  42. </div>
  43. <div id="Genes-tab" class="tab-content">
  44. <h1>Genes and Proteins</h1>
  45. <p>Results for genes and proteins based on search </p>
  46. </div>
  47. <div id="Litrature-tab" class="tab-content">
  48. <h1>Litrature</h1>
  49. <p>Results of Litrature search will be shown here</p>
  50. </div>
  51. <div id="Analysis-tab" class="tab-content">
  52. <h1>Analysis</h1>
  53. <p>A type of analysis will be shown here</p>
  54. </div>
  55. </div>
  56. </div>
  57. </div>
  58. </body>
  59. </html>

searchuniprot.java文件

  1. package TestGeneSearch;
  2. import javax.ejb.EJB;
  3. import javax.faces.bean.ManagedBean;
  4. import javax.faces.bean.ManagedProperty;
  5. import javax.faces.bean.RequestScoped;
  6. @ManagedBean (name ="SearchUniprot" )
  7. @RequestScoped
  8. public class SearchUniprot {
  9. String userSearch;
  10. public String getUserSearch() {
  11. return userSearch;
  12. }
  13. public void setUserSearch(String userSearch) {
  14. this.userSearch = userSearch;
  15. }
  16. public SearchUni getQuery() {
  17. // 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
  18. SearchUni query = new SearchUni("tuna");
  19. //run the RunQuery method in SearchUniprot
  20. query.RunQuery();
  21. return query;
  22. }
  23. public SearchUniprot() {
  24. }
  25. }

搜索uni.java

  1. package TestGeneSearch;
  2. import javax.ejb.Stateful;
  3. import uk.ac.ebi.webservices.axis1.stubs.ebeye.EBISearchService_PortType;
  4. import uk.ac.ebi.webservices.axis1.stubs.ebeye.EBISearchService_Service;
  5. import uk.ac.ebi.webservices.axis1.stubs.ebeye.EBISearchService_ServiceLocator;
  6. @Stateful
  7. public class SearchUni {
  8. // Add business logic below. (Right-click in editor and choose
  9. // "Insert Code > Add Business Method")
  10. //searchterm = what you want to search for
  11. private String searchterm;
  12. public SearchUni() {
  13. }
  14. //constrcutor
  15. public SearchUni(String s) {
  16. searchterm = s;
  17. }
  18. public String[] RunQuery() {
  19. try {
  20. //set up to connect to the searchservice
  21. EBISearchService_Service service = new EBISearchService_ServiceLocator();
  22. EBISearchService_PortType srvProxy = service.getEBISearchServiceHttpPort();
  23. // Get the number of results for the query - we don;t necessarily need this but it may be useful
  24. int result = srvProxy.getNumberOfResults("uniprot", searchterm);
  25. System.out.println(result);
  26. //get all results IDs - can easily limit it to however many we want
  27. String[] ids = srvProxy.getAllResultsIds("uniprot", searchterm);
  28. for (int i = 0; i + 1 < ids.length; i++) {
  29. System.out.println(ids[i]);
  30. }
  31. //get more fields - the fields we can get depend on the database to be searched.
  32. //a note about protein names in Uniprot - Uniprot contains two sections, reviewed and unreviewd
  33. //the reviewed entries will have a Reccomended Name (descRecName), the unreviewed entries will have
  34. //a Submitted name (descSubName) - so each of our results will have either a descRecName or a descSubName
  35. //but not both.
  36. //gene name (gene_primary_name) may be null
  37. //accession number (acc) is a stable identifier - the id field printed out above is not the same as an
  38. //accession number and shouldn't be assumed to be stable
  39. String fields[] = {"acc", "descRecName", "descSubName", "gene_primary_name", "organism_scientific_name"};
  40. String[][] results = srvProxy.getResults("uniprot", searchterm, fields, 1, 100);
  41. for (int i = 0; i < result; i++) {
  42. for (int j = 0; j < fields.length; j++) {
  43. System.out.println(results[i][j]);
  44. }
  45. }
  46. } catch (Exception ex) {
  47. ex.printStackTrace();
  48. }
  49. return null;
  50. }
  51. }
3j86kqsm

3j86kqsm1#

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

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

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

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml"
  4. xmlns:f="http://java.sun.com/jsf/core"
  5. xmlns:h="http://java.sun.com/jsf/html"
  6. xmlns:ui="http://java.sun.com/jsf/facelets"
  7. xmlns:p="http://primefaces.org/ui">
  8. <h:head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  10. </h:head>
  11. <h:body>
  12. <h:form>
  13. <p:inputText id="criteria" value="#{myMB.criteria}"/>
  14. <p:inputText id="result" value="#{myMB.result}"/>
  15. <p:commandButton value="query" action="#{myMB.query}" update="result"/>
  16. </h:form>
  17. </h:body>
  18. </html>

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

  1. package mypackage;
  2. import java.io.Serializable;
  3. import javax.ejb.EJB;
  4. import javax.faces.bean.ManagedBean;
  5. import javax.faces.bean.ViewScoped;
  6. @ManagedBean
  7. @ViewScoped
  8. public class MyMB implements Serializable{
  9. private static final long serialVersionUID = 1L;
  10. private String criteria;
  11. private String result;
  12. @EJB
  13. private MyEJB myEJB;
  14. public void query(){
  15. this.result = myEJB.query(this.criteria);
  16. }
  17. public String getCriteria() {
  18. return criteria;
  19. }
  20. public void setCriteria(String criteria) {
  21. this.criteria = criteria;
  22. }
  23. public String getResult() {
  24. return result;
  25. }
  26. public void setResult(String result) {
  27. this.result = result;
  28. }
  29. }

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

  1. package mypackage;
  2. import javax.ejb.Stateless;
  3. @Stateless
  4. public class MyEJB {
  5. public String query(String criteria) {
  6. //do your query here
  7. return "xyz";
  8. }
  9. }

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

  1. update="result"

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

展开查看全部

相关问题