p:textEditor标记无法正常工作

时间:2018-05-04 19:23:44

标签: primefaces dialog text-editor

当我在p:对话框中插入p:textEditor标记时,工具栏中的许多按钮/选择列表 都不起作用。

按照以下步骤重现问题:

  • 我点击相应的按钮打开(启动)对话框。
  • 我在文本编辑器区域输入了一些文字。
  • 然后我选择/突出显示我刚刚输入的一些文字
  • 我单击字体大小选择下拉列表以选择其他 font-size(例如“Large”)。
  • 什么都没发生。我选择的文字保持不变。没有变化。

奇怪的是,如果我退出对话框然后重新打开对话框,工具栏中的选择列表和按钮就可以正常工作。显然,只是第一次时间,我打开工具栏按钮不起作用的对话框。

另外,我尝试在主窗体上插入p:textEditor标记 - 而不是在对话框中 - 它在主窗体上工作正常。换句话说,当p:textEditor标记在p:对话框之外时,它似乎工作正常。当p:textEditor标记在内部一个p:对话框中时,似乎只会出现这些问题。还有其他人遇到过这个问题吗?

任何反馈都将不胜感激。感谢。

JSF 2.2 Primefaces 6.2 GlassFish Server 4.1.1 Netbeans 8.2

更新:嗨。我能够使用以下代码重现该问题。当我在启动对话框的p:commandbutton按钮中使用“update”属性时,问题似乎浮出水面.- Ian

===============这是JSF文件============================ ==========

<?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:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>

        <h:form>
            <p:commandButton value="Login" oncomplete="PF('dlg').show();" update=":loginForm"   >
                <p:resetInput target=":loginForm" />     
            </p:commandButton>   
        </h:form>

            <p:growl id="growl" sticky="true" showDetail="true" life="3000" />

            <p:dialog header="Login" widgetVar="dlg" resizable="false">
                <h:form id="loginForm">
                    <h:panelGrid columns="2" cellpadding="5">
                        <h:outputLabel for="username" value="Username:" />
                        <p:inputText id="username" value="#{userLoginView.username}" required="true" label="username" />

                        <h:outputLabel for="password" value="Password:" />
                        <p:password id="password" value="#{userLoginView.password}" required="true" label="password" />

                        <h:outputLabel for="comment" value="Comment:" />
                        <p:textEditor widgetVar="txtEditor1" id="comment" value="#{userLoginView.text1}" height="100" style="margin-bottom:10px;margin-right:10px;" placeholder="Enter your content">
                        </p:textEditor> 

                        <f:facet name="footer">
                            <p:commandButton value="Login" update="growl" actionListener="#{userLoginView.login}"
                                             oncomplete="handleLoginRequest(xhr, status, args)" />
                        </f:facet>  
                    </h:panelGrid>
                </h:form>
            </p:dialog>


        <script type="text/javascript">
            function handleLoginRequest(xhr, status, args) {
                if(args.validationFailed || !args.loggedIn) {
                    PF('dlg').jq.effect("shake", {times:5}, 100);
                }
                else {
                    PF('dlg').hide();
                    $('#loginLink').fadeOut();
                }
            }
        </script>

    </h:body>
</html>

=============================================== ======================

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package demo;

/**
 *
 * @author admin
 */
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import org.primefaces.PrimeFaces;

@ManagedBean
public class UserLoginView {

    private String username;

    private String password;
    private String text1;

    public String getText1() {
        return text1;
    }

    public void setText1(String text1) {
        this.text1 = text1;
    }



    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void login(ActionEvent event) {
        FacesMessage message = null;
        boolean loggedIn = false;

        if(username != null && username.equals("admin") && password != null && password.equals("admin")) {
            loggedIn = true;
            message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", username);
        } else {
            loggedIn = false;
            message = new FacesMessage(FacesMessage.SEVERITY_WARN, "Loggin Error", "Invalid credentials");
        }

        FacesContext.getCurrentInstance().addMessage(null, message);
        PrimeFaces.current().ajax().addCallbackParam("loggedIn", loggedIn);
    }   
}

1 个答案:

答案 0 :(得分:-1)

我不知道您是否仍然遇到问题,但是可以通过在@PostConstruct方法中打开和关闭对话框来解决此问题。 对用户来说是透明的,但是仍然可以找到更可行的解决方案。

相关问题