方法完成过程后更改Primefaces命令按钮的禁用状态

如何解决方法完成过程后更改Primefaces命令按钮的禁用状态

我有一个页面,其中

用于开始搜索。搜索完成后,它将刷新<p:gmap>和dataTable。同时,我创建一个包含搜索详细信息的文本文件。我想在页面末尾为此文件创建一个下载按钮。

但是,生成文件需要时间。如果用户在该过程完成之前单击该按钮,则将收到HTTP 404错误。我试图仅在创建文件时启用“下载”按钮,但是我不知道仅在文件完成后如何将下载按钮中的Disabled属性从true切换为false。有可能吗?

我已经尝试过描述here的解决方案,但是没有用。

网页

<?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">
<ui:composition template="template.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets">  


    <ui:define name="menuDireito"> 
        <f:view transient="true">
            <script src="https://maps.google.com/maps/api/js?sensor=false"></script>         
            <h:form id="form"> 
                <br></br>                                
                <p:selectOneMenu  immediate="true" value="#{circlesView.selectedCategory}"  converter="categoriaConverter" panelStyle="width:150px"  
                                  effect="fade" var="p" style="width:200px"  filter="true" filterMatchMode="startsWith">  
                    <f:selectItem itemLabel="Selecione o Estabelecimento" itemValue="" />  
                    <f:selectItems value="#{autoCompleteCategoria.categories}" var="category" itemLabel="#{category}" itemValue="#{category}"/>                                   

                    <p:column>  
                        #{p}  
                    </p:column>  

                </p:selectOneMenu>                                 

                <br></br><br></br>           
                <div style="text-align: left">Indique a área de busca:</div>
                <p:inputText id="range" value="#{circlesView.range}" /> 
                <p:watermark for="range" value="Ex: 1000" id="watermark" />

                <br></br><br></br>                   

                <div style="text-align: center">
                    <p:commandButton icon="fa fa-fw fa-search" style="width:150px !important; height: 30px !important;" ajax="false" process="@all" value="Pesquisar" action="#{circlesView.filteredQuery()}" update="dataTable" oncomplete="PF('dlg').show()" />             
                </div>

                <br></br><br></br> 

                <p:separator style="margin-bottom:10px"/>

                <p:gmap id="gmap" center="-23.5569834,-46.6362086" zoom="13" type="HYBRID" style="width:100%;height:400px" model="#{circlesView.circleModel}">                
                </p:gmap>

                <p:separator style="margin-bottom:10px"/>                                         

                <h3>Resultados</h3>  
                <p:dataTable id="basicDT" var="obj" value="#{circlesView.objs}">
                    <f:facet name="header">
                        Locais com infectados na vizinhança
                    </f:facet>
                    <p:column style="text-align: center" headerText="Nome">
                        <h:outputText value="#{obj.name}" />
                    </p:column>
                    <p:column style="text-align: center" headerText="# pessoas">
                        <h:outputText value="#{obj.score}" />
                    </p:column>               
                    <p:column style="text-align: center" headerText="Visualizar">
                        <p:commandButton update=":form:localDetail" oncomplete="PF('mapDialog').show()" icon="ui-icon-search" title="View">
                            <f:setPropertyActionListener value="#{obj}" target="#{circlesView.selectedObj}" />
                        </p:commandButton>                                       
                    </p:column>
                    <p:column style="text-align: center" headerText="Visualizar">
                        <p:commandButton update=":form:nDetail" oncomplete="PF('ndialog').show()" icon="ui-icon-search" title="View">
                            <f:setPropertyActionListener value="#{obj}" target="#{circlesView.selectedObj}" />
                        </p:commandButton>
                    </p:column>  
                </p:dataTable>  

                <p:dialog header="Local Position" widgetVar="mapDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false" width="625" height="400">

                    <p:outputPanel id="localDetail" style="text-align:center;">
                        <p:panelGrid  rendered="#{not empty circlesView.selectedObj}" >
                            <p:gmap id="gmap2" center="#{circlesView.selectedObj.coordPattern}" zoom="14" type="HYBRID" style="width:100%;height:400px" model="#{circlesView.selectedObj.mapModel}"/>
                        </p:panelGrid>         
                    </p:outputPanel>
                </p:dialog> 

                <p:dialog header="Neighborhood Info" widgetVar="nDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
                    <p:outputPanel id="nDetail" style="text-align:center;">
                        <p:panelGrid  columns="2" rendered="#{not empty dtSelectionView.selectedCar}" columnClasses="label,value">                

                            <h:outputText value="Id:" />
                            <h:outputText value="#{circlesView.selectedObj.id}" />

                            <h:outputText value="Dist" />
                            <h:outputText value="#{circlesView.selectedObj.distancia}" />
                        </p:panelGrid>
                    </p:outputPanel>
                </p:dialog>

            </h:form>
            <br></br>

            <h:form id="downloadForm">
                <p:commandButton action="#{circlesView.downloadAction()}" value="Download" ajax="false" icon="fa fa-fw fa-download" disabled="#{circlesView.disable}">
                    <p:fileDownload value="#{circlesView.file}" />
                </p:commandButton>                  
            </h:form>

        </f:view>
    </ui:define>        

</ui:composition>

Bean

@ManagedBean(name = "circlesView")
@SessionScoped
public class PreferenceQuery implements Serializable {

    private MapModel circleModel;
    private String path;
    private String contentType;
    private boolean disable;
    Integer range;
    Properties properties;
    DefaultStatisticCenter statistics;
    Integer k = 20;
    List<ScoredObjectMarked> objs;
    ScoredObjectMarked selectedObj;
    String selectedCategory;
    private static final long serialVersionUID = 1L;

    public PreferenceQuery() {
        disable = true;
    }

    public List<ScoredObjectMarked> query() throws FileNotFoundException,UnsupportedEncodingException,IOException {

        disable = true;
        objs = new ArrayList<ScoredObjectMarked>();
        statistics = new DefaultStatisticCenter();

        try {
            properties = Settings.myLoadProperties(new File("D:\\Documents\\GitHub\\COVID-Geo-Monitoring\\web\\search.properties"));
        } catch (IOException ex) {
            Logger.getLogger(PreferenceQuery.class.getName()).log(Level.SEVERE,null,ex);
        }

        //Converte para radius
        double radius = (180 * range) / (6378137.0 * Math.PI);

        PreferenceFileTermManager fileTermManager = createPreferenceFileTermManager();

        PreferenceTreeTermManager treeTermManager = createPreferenceTreeTermManager();

        PreferenceIndex prefIndex = createPreferenceSpatialInvertedIndex(fileTermManager,treeTermManager,false);

        StarRTree rTree = null;
        try {
            rTree = createRtree(null);
        } catch (IOException ex) {
            Logger.getLogger(PreferenceQuery.class.getName()).log(Level.SEVERE,ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PreferenceQuery.class.getName()).log(Level.SEVERE,ex);
        }

        try {
            prefIndex.open();
        } catch (SSEExeption ex) {
            Logger.getLogger(PreferenceQuery.class.getName()).log(Level.SEVERE,ex);
        } catch (ColumnFileException ex) {
            Logger.getLogger(PreferenceQuery.class.getName()).log(Level.SEVERE,ex);
        } catch (IOException ex) {
            Logger.getLogger(PreferenceQuery.class.getName()).log(Level.SEVERE,ex);
        }

        PreferenceSearch experiment = new PreferenceSearch(statistics,false,prefIndex.getTermVocabulary(),1,k,0.5 /*alfa*/,Double.parseDouble(properties.getProperty("dataset.spaceMaxValue")),selectedCategory,prefIndex,rTree,3,true,radius);

        try {
            experiment.open();
        } catch (ExperimentException ex) {
            Logger.getLogger(PreferenceQuery.class.getName()).log(Level.SEVERE,ex);
        }

        Iterator<SpatioTextualObject> result = null;
        try {
            result = experiment.search("patient",20);
        } catch (ExperimentException ex) {
            Logger.getLogger(PreferenceQuery.class.getName()).log(Level.SEVERE,ex);
        }

        while (result.hasNext()) {
            ScoredObject p = (ScoredObject) result.next();
            ScoredObjectMarked p_model = new ScoredObjectMarked(p.getId(),p.getLatitude(),p.getLongitude(),range,p.getMessage());
            p_model.setScore(p.getScore());
            objs.add(p_model);
        }

        try {
            experiment.close();
        } catch (ExperimentException ex) {
            Logger.getLogger(PreferenceQuery.class.getName()).log(Level.SEVERE,ex);
        }

        circleModel = new DefaultMapModel();

        for (int a = 0; a < objs.size() && a < k; a++) {

            ScoredObject poi = objs.get(a);

            LatLng coords = new LatLng(poi.getLatitude(),poi.getLongitude());

            Circle circle = new Circle(coords,range);
            circle.setStrokeColor("#d93c3c");
            circle.setFillColor("#d93c3c");
            circle.setFillOpacity(0.5);

            circleModel.addOverlay(circle);
        }

        reportFeatures();
        disable = false;
        return objs;
    }

    public void downloadAction() {
        path = "D:\\Documents\\GitHub\\COVID-Geo-Monitoring\\src\\java\\query\\fullReport.txt";
        contentType = FacesContext.getCurrentInstance().getExternalContext().getMimeType(path);
    }

    public StreamedContent getFile() throws FileNotFoundException {
        return new DefaultStreamedContent(new FileInputStream("D:\\Documents\\GitHub\\COVID-Geo-Monitoring\\src\\java\\query\\fullReport.txt"),contentType,"Report.txt");
    }

    public void reportFeatures() throws FileNotFoundException,IOException {

        Writer output = new OutputStreamWriter(new FileOutputStream("D:\\Documents\\GitHub\\COVID-Geo-Monitoring\\src\\java\\query\\fullReport.txt",false),"ISO-8859-1");

        for (ScoredObjectMarked poi : objs) {

            output.write("Pacientes próximos ao " + poi.getName() + "\n\n");

            SpatioItemCollection collection = poi.getNN();
            Iterator colIt = collection.iterator();

            while (colIt.hasNext()) {
                SpatioItem paciente = (SpatioItem) colIt.next();
                output.write("\t Paciente " + paciente.getId() + ": (" + paciente.getLatitude() + "," + paciente.getLongitude() + ") "
                        + "Distância para o Hospital: " + paciente.getDistancia() + "\n");
            }
            output.write("\n");
            output.flush();
        }
        output.close();
    }

    public List<ScoredObjectMarked> filteredQuery() throws IOException,FileNotFoundException,ClassNotFoundException,SSEExeption,ColumnFileException {

        objs = new ArrayList<ScoredObjectMarked>();
        statistics = new DefaultStatisticCenter();

        try {
            properties = Settings.myLoadProperties(new File("D:\\Documents\\GitHub\\COVID-Geo-Monitoring\\web\\search.properties"));
        } catch (IOException ex) {
            Logger.getLogger(PreferenceQuery.class.getName()).log(Level.SEVERE,false);

        StarRTree rTree = createRtree(selectedCategory);

        prefIndex.open();

        PreferenceSearch experiment = new PreferenceSearch(statistics,k);
        } catch (ExperimentException ex) {
            Logger.getLogger(PreferenceQuery.class.getName()).log(Level.SEVERE,p.getMessage());
            p_model.setScore(p.getScore());
            p_model.setNN(p.getNN());
            objs.add(p_model);
        }

        try {
            experiment.close();
        } catch (ExperimentException ex) {
            Logger.getLogger(PreferenceQuery.class.getName()).log(Level.SEVERE,range);
            circle.setStrokeColor("#d93c3c");
            circle.setFillColor("#d93c3c");
            circle.setFillOpacity(0.5);

            circleModel.addOverlay(circle);
        }

        reportFeatures();
        disable = false;

        return objs;
    }

    public boolean getDisable() {
        return disable;
    }

    public void setDisable(boolean disable) {
        this.disable = disable;
    }

    public List<ScoredObjectMarked> getObjs() {
        return objs;
    }

    public void setObjs(List<ScoredObjectMarked> objs) {
        this.objs = objs;
    }

    public MapModel getCircleModel() {
        return circleModel;
    }

    public void onCircleSelect(OverlaySelectEvent event) {
        FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO,"Circle Selected",null));
    }

    public Integer getRange() {
        return range;
    }

    public void setRange(Integer range) {
        this.range = range;
    }

    public ScoredObject getSelectedObj() {
        return selectedObj;
    }

    public void setSelectedObj(ScoredObjectMarked selectedObj) {
        this.selectedObj = selectedObj;
    }

    public String getSelectedCategory() {
        return selectedCategory;
    }

    public void setSelectedCategory(String selectedCategory) {
        this.selectedCategory = selectedCategory;
    }

    private StarRTree createRtree(String poi) throws FileNotFoundException,IOException,ClassNotFoundException {

        if (poi == null) {
            poi = "Sao Paulo";
            selectedCategory = "Sao Paulo";
        }

        Path path = Paths.get(properties.getProperty("experiment.folder") + "\\rtrees\\" + selectedCategory);
        Files.createDirectories(path);

        StarRTree rTree = new StarRTree(statistics,"",properties.getProperty("experiment.folder") + "\\rtrees\\" + selectedCategory + "\\rtree",Integer.parseInt(properties.getProperty("srtree.dimensions")),Integer.parseInt(properties.getProperty("srtree.cacheSize")),Integer.parseInt(properties.getProperty("disk.blockSize")),Integer.parseInt(properties.getProperty("srtree.minNodeCapacity")),Integer.parseInt(properties.getProperty("srtree.maxNodeCapacity")));

        System.out.println("POI: " + poi);
        LoadRTree.load(rTree,"D:\\Documents\\GitHub\\COVID-Geo-Monitoring\\web\\Categorias\\" + poi + ".txt");

        return rTree;
    }

    private PreferenceIndex createPreferenceSpatialInvertedIndex(PreferenceFileTermManager fileTermManager,PreferenceTreeTermManager treeTermManager,boolean constructionTime) {
        return new PreferenceIndex(statistics,properties.getProperty("experiment.folder"),100,fileTermManager,constructionTime);
    }

    private PreferenceTreeTermManager createPreferenceTreeTermManager() {
        return new PreferenceTreeTermManager(statistics,Integer.parseInt(properties.getProperty("srtree.maxNodeCapacity")),100);
    }

    private PreferenceFileTermManager createPreferenceFileTermManager() {
        return new PreferenceFileTermManager(statistics,properties.getProperty("experiment.folder") + "/s2i",Integer.parseInt(properties.getProperty("srtree.cacheSize")));
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-