gpt4 book ai didi

forms - 无法从tinyMCE编辑器获取值

转载 作者:行者123 更新时间:2023-12-02 01:03:09 25 4
gpt4 key购买 nike

我正在使用 JSF 2.1。我正在尝试在 .这是我的 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:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>

<h:outputStylesheet library="css" name="editor_style.css" />
<h:outputStylesheet library="css" name="dropdown_menu/dropdown.css" />
<h:outputStylesheet library="css" name="css/main.css" />
<h:outputStylesheet library="css" name="css/dropdown.css" />
<h:outputStylesheet library="css" name="css/drop-down.css" />

<h:outputScript name="dropdown_menu/stuHover.js"></h:outputScript>
<h:outputScript name="js/my_js.js"></h:outputScript>
<h:outputScript name="js/jquery.min.js"></h:outputScript>
<h:outputScript name="js/tinyeditor.js"></h:outputScript>

</h:head>

<h:body>
<div class="content">
<ui:include src="/template/layout/commonLayout.xhtml" />
<ui:include src="/template/layout/menu.xhtml" />
<h:form id="form">
<div class="quick_links">
<div class="q_title"></div>
<div class="q_window">
<div class="q_top"></div>
<div class="q_main">

<h:inputTextarea id="input" value="#{EditorBean.value}"
style="width:100%; height:300px;">Sample FAQ</h:inputTextarea>

<h:outputScript>
new TINY.editor.edit('editor',{
id:'form:input',
width:945,
height:175,
cssclass:'te',
controlclass:'tecontrol',
rowclass:'teheader',
dividerclass:'tedivider',
controls:['bold','italic','underline','strikethrough','|','subscript','superscript','|',
'orderedlist','unorderedlist','|','outdent','indent','|','leftalign',
'centeralign','rightalign','blockjustify','|','unformat','|','undo','redo','n',
'font','size','style','|','hr','link','unlink'],
footer:true,
fonts:['Verdana','Arial','Georgia','Trebuchet MS'],
xhtml:true,
cssfile:'style.css',
bodyid:'editor',
footerclass:'tefooter',
toggle:{text:'Source',activetext:'HTML',cssclass:'toggle'},
resize:{cssclass:'resize'}
});
</h:outputScript>

</div>
<div class="q_bottom"></div>
</div>

<h:commandButton id="button" value="Savebutton"
action="#{EditorBean.test}"></h:commandButton>
</div>
<div class="push"></div>
</h:form>
</div>

<script language="javascript">footer();</script>

</h:body>
</html>

我的 Bean 类是

package com.denso.rms.beans;

import java.awt.Window;
import java.io.FileOutputStream;


import com.sun.java.swing.plaf.windows.resources.windows;

public class EditorBean {
private String value;


public String getValue() {
return value;
}

public void setValue(String value) {

this.value = value;
}
public String test() {
System.out.println("Value is-" +value);
return value;
}

}

我还在 faces-config.xml 中输入了内容

基本问题是,如果我尝试打印“值”,它什么也不会显示。如果我删除编辑器,那么它就可以正常工作。所以问题出在 <h:inputtextarea>编辑器,因为当我尝试在 getter 和 setter 中打印相同的值时,它什么也没显示。我缺少什么?

最佳答案

That's because it's not a textarea any longer. It's replaced with an iframe (and whatnot), and the serialize function only gets data from form fields.Problem jquery and tinymce : textarea value doesn't submit

因此,在发布到服务器之前,您必须提取其值

一种方法是将以下内容添加到提交 h:commandBttonon

onclick="tinyMCE.triggerSave();"

或者

onclick="$('#form\\:input').tinymce().save();"

如果这个不起作用,那么下面的解决方案会起作用(INMO 更好)

像这样修改你的h:commandButton

 <h:commandButton onclick="save_and_add();return false;" id="button" 
value="Savebutton"></h:commandButton>

这是js函数的内容

function save_and_add(){
tinyMCE.triggerSave();
$('#form\\:button2').click();
};

现在添加另一个隐藏按钮来执行实际的提交

<h:commandButton id="button2" style="display:none;"
action="#{EditorBean.test}"></h:commandButton>

关于forms - 无法从tinyMCE编辑器获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13739443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com