无法在 ajax 重新渲染上显示 deployJava 按钮 [英] Trouble to display deployJava button on ajax rerender

查看:25
本文介绍了无法在 ajax 重新渲染上显示 deployJava 按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在 ajax rerender 上显示 deploy-java 按钮

I'm having trouble displaying the deploy-java button on ajax rerender

<h:form id="deployJavaForm" rendered="#{myBean.shouldRender}">
<h:outputScript library="js" name="http://java.com/js/deployJava.js" target="head" />
<script type="text/javascript">
    deployJava.createWebStartLaunchButton('blah.jnlp', '1.7.0');
</script>
</h:form>

什么时候

myBean.shouldRender == true

表单更新后,唯一显示的内容(在白页上)是 deployJava 按钮,并且请求被挂起.如果初始请求中的 shouldRender 为 true,则页面和按钮将正确显示.我正在使用 primefaces 以防万一.

and the form is updated the only thing being displayed (on a white page) is the deployJava-button and the request is left hanging. if shouldRender is true on the initial request, page and button is displayed correctly. Im using primefaces in case it can help.

我想要做的是让按钮正确显示,无论它是 ajax 重新渲染的一部分还是完整的初始请求.

What I want to do is to have the button to be displayed correctly regardless if its part of a ajax rerender or a complete initial request.

更新:我做了功课并创建了一个仍然重现问题的最小示例.无论脚本声明是在头部还是在主体中,我似乎仍然遇到同样的问题(我在资源/js 中有 deployJava.js 的副本)

Update: I did my homework and created a minimal example that still reproduces the problem. It seems I still get the same problems regardless if script declaration is in head or in body (I have copy of deployJava.js in resources/js)

<?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>
    <!-- <script type="text/javascript" src="http://java.com/js/deployJava.js" />-->
</h:head>
<h:body>
    <h:outputScript library="js" name="deployJava.js" target="head" />
    <h:form id="djForm">
        <script type="text/javascript">
            deployJava.createWebStartLaunchButton(
                    'test.jnlp', '1.7.0');
        </script>
        <p:commandButton value="update" update="djForm" />
    </h:form>
</h:body>
</html>

(特殊宝石)下面的测试给出了与之前观察到的相同的问题.

edit: (specialgems) below test give same problem as observed earlier.

<h:outputScript>
deployJava.createWebStartLaunchButton(
                'test.jnlp', '1.7.0');
</h:outputScript>

添加图片

点击更新按钮后,只呈现deployJava按钮并且页面正在加载

after click of update button, only deployJava button is rendered and page is loading

编辑(丹尼尔):成功和完成时都给出相同的行为:(

edit (daniel): both on success and oncomplete give same behaviour :(

<h:form id="djForm">
    <h:outputScript>
        function abcefg() {
            deployJava.createWebStartLaunchButton('test.jnlp', '1.7.0');
        }
    </h:outputScript>
<p:commandButton value="update" update="djForm" onsuccess="abcefg()" />
</h:form>

推荐答案

除了使用我的评论中描述的 js 和 css 可见性之外,您还可以编写自己的复合按钮组件.使用 Firebug,您可以调查由 deployJava.createWebStartLaunchButton 脚本生成的标记并自行静态添加.所以你的组件可能是:

Alternatively to using js and css visibility described in my comment you can write own composite button component. Using Firebug you can investigate which markup is generated by the deployJava.createWebStartLaunchButton script and add it by yourself statically. So your component could be:

<!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:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:composite="http://java.sun.com/jsf/composite">
<head>
<title>deployJava Button component</title>
</head>
<body>

    <composite:interface>
        <composite:attribute name="version" required="true"
            type="java.lang.String" />
        <composite:attribute name="url" required="true"
            type="java.lang.String" />
    </composite:interface>

    <composite:implementation>
        <a onmouseover="window.status=''; return true;"
            href="javascript:if (!deployJava.isWebStartInstalled(&quot;#{cc.attrs.version}&quot;)) {if (deployJava.installLatestJRE()) {if (deployJava.launch(&quot;#{cc.attrs.url}&quot;)) {}}} else {if (deployJava.launch(&quot;#{cc.attrs.url}&quot;)) {}}"><img
            border="0" src="//java.com/js/webstart.png" /></a>
    </composite:implementation>
</body>
</html> 

所以你的页面将是:

<?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:comps="http://java.sun.com/jsf/composite/comps"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <!-- <script type="text/javascript" src="http://java.com/js/deployJava.js" />-->
</h:head>
<h:body>
    <h:outputScript library="js" name="deployJava.js" target="head" />
    <h:form id="djForm">
       <comps:deployJavaButton version="1.7.0" url="test.jnlp" rendered="#{myBean.shouldRender}" />

        <p:commandButton value="update" update="djForm" />
    </h:form>
</h:body>
</html>

主要思想是避免执行按钮创建脚本两次以上.

The main idea is to avoid executing button creation script twice and more.

这篇关于无法在 ajax 重新渲染上显示 deployJava 按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆