繁体   English   中英

使用JSF Ajax的CommandLink,需要2次单击

[英]CommandLink with JSF Ajax requiring 2 clicks

我认为这不是AJAX在表单中包含表单的JSF问题,因为我只有1个表单。

我查看了有关Ajax和JSF渲染内容的线程,并且尝试了多种解决方案,但都没有碰到运气。

任何人都可以看到我很想念的明显的东西:-)

谢谢

index.xhtml

<!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui">

<h:head>
    <title>Manual</title>
    <h:outputStylesheet name="style.css" library="css" />
</h:head>
<h:body>
    <div id="page">
        <h:form id="myform"> 
        <div class="header" >
            <h:graphicImage library="img" name="Logo.gif" alt="Logo"/>
            <h1>Manual</h1>
        </div>

            <div class="menu">
        </div>

        <div class="nav">

            <h:outputText value="Navigation 1"/><br/>
            <p:commandLink value="Chapter100" action="#{contentBean.BuildContent}" update="content" >
                <f:ajax process="@this" render=":content" />
            </p:commandLink>

                    <!-- Add NewLine between links --> 
                    <h:outputText value="&#10;" />
            </div>
            </h:form>
            <div class="mycontent">
                <h:panelGroup id="content">
                    <h:outputText value="#{contentBean.content}" >
            </h:outputText>
                </h:panelGroup>
            </div>
        </div>
    </h:body>
</html>

豆角,扁豆

@ManagedBean(name="contentBean")
@ViewScoped
public class ContentBean implements Serializable{
    private List<String> lTocInfo = new ArrayList();

    private String content = "Steve Newer 002 Content";

    public String getContent() 
    {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public void BuildContent() throws Exception
    {
        this.setContent("Steve made it back from database");
    }     
}

不要在primefaces按钮内使用<f:ajax> ,因为默认情况下它是ajax请求(除非您要关闭ajax请求,否则可以将ajax属性设置为false)。 您可以使用更新和处理属性。

我相信,要解决此问题,您还可以在ajax中的链接中使用以下代码:

<p:commandLink value="Chapter100" action="#{contentBean.BuildContent}">
                <f:ajax execute="@form" event="blur" render="content" />
</p:commandLink>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM