如何在jsf支持bean中获取tinymce的值

时间:2012-04-16 07:18:32

标签: jsf tinymce

我在JSF中使用tinymce编辑器,但我不知道如何在我的Backing Bean中获取此值。如果有人使用过这个,请帮我解决这个问题。

       <script src="resources/tiny_mce/tiny_mce.js" type="text/javascript"></script>
<script type="text/javascript">
    tinyMCE.init({
   // General options
    mode : "textareas",
    theme : "advanced",
    plugins :  "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

   // Theme options
   theme_advanced_buttons1 :"bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
   theme_advanced_buttons2 : "cut,copy,paste,pastetext,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,preview,|,forecolor,backcolor",
   theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,media,advhr,|,styleprops,spellchecker,|,insertfile,insertimage",
   theme_advanced_toolbar_location : "top",
   theme_advanced_toolbar_align : "left",
   theme_advanced_statusbar_location : "bottom",
   theme_advanced_resizing : true,

   // Skin options
   skin : "o2k7",
   skin_variant : "silver",

  content_css : "css/example.css",

 });

   <ice:inputTextarea id="content" value="${bean.passage}" partialSubmit="true"/>   

2 个答案:

答案 0 :(得分:0)

value="${bean.passage}"替换为value="#{bean.passage}"${}无法调用setter方法,但#{}可以。

答案 1 :(得分:0)

通过选择器将tinyMCE连接到您的jsf组件

在以下示例中,您将加载一个自己的JavaScript文件“ loadhtmleditor.js”,其中包含函数“ loadMyEditor()”。此功能在 body onload 中调用。 在此javascript函数中,您可以通过 selector 而不是通过 mode 将tinyMCE连接到jsf组件。在选择器参数中,编写要连接的组件的html-id。请注意,在此参数中,由jsf生成的html-id中的':'分隔符必须用两个反斜杠屏蔽!在此示例中:选择器:“ #myForm \\:myHtmlText”

<?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://java.sun.com/jsf/html">
<h:head>
    <script src="resources/tiny_mce/tiny_mce.js" type="text/javascript"></script>
    <script src="resources/loadhtmleditor.js" type="text/javascript"></script>
</h:head>
<h:body onload="loadMyEditor();">
    <h:form id="myForm">
        <h:inputTextarea id="myHtmlText" value="#{bean.htmlText}">
        </h:inputTextarea>
    </h:form>
</h:body>
</html>

loadhtmleditor.js:

function loadMyEditor()
{
    tinyMCE.init({
           // General options
            selector : "#myForm\\:myHtmlText",
            theme : "advanced",
            plugins :  "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
           // Theme options
           theme_advanced_buttons1 :"bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
           theme_advanced_buttons2 : "cut,copy,paste,pastetext,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,preview,|,forecolor,backcolor",
           theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,media,advhr,|,styleprops,spellchecker,|,insertfile,insertimage",
           theme_advanced_toolbar_location : "top",
           theme_advanced_toolbar_align : "left",
           theme_advanced_statusbar_location : "bottom",
           theme_advanced_resizing : true,
           // Skin options
           skin : "o2k7",
           skin_variant : "silver",
          content_css : "css/example.css",
         });
}

这足以将您的jsf bean绑定到tinyMCE!

添加: 如果您想在用户更改html内容时通过进行响应,则可以像下面这样扩展tinyMCE编辑器的创建:

loadhtmleditor.js:

function loadMyEditor()
{
    tinyMCE.init({
           // General options
            selector : "#myForm\\:myHtmlText",
            theme : "advanced",
            plugins :  "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
           // Theme options
           theme_advanced_buttons1 :"bold,italic,underline,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
           theme_advanced_buttons2 : "cut,copy,paste,pastetext,|,bullist,numlist,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,preview,|,forecolor,backcolor",
           theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,media,advhr,|,styleprops,spellchecker,|,insertfile,insertimage",
           theme_advanced_toolbar_location : "top",
           theme_advanced_toolbar_align : "left",
           theme_advanced_statusbar_location : "bottom",
           theme_advanced_resizing : true,
           // Skin options
           skin : "o2k7",
           skin_variant : "silver",

           init_instance_callback: function (editor)
           {
               editor.on('Change', function(e){myFunctionEditorChanged(editor);});
               editor.on('Paste', function(e){myFunctionEditorPasted(editor);});
           },
           content_css : "css/example.css"
         });
}


function myFunctionEditorChanged(editor)
{
    tinyMCE.triggerSave(); // to be shure, that the changed content is in your jsf-component...
    // do something to trigger an ajax request handeling the changed html content. 
}


function myFunctionEditorPasted(editor)
{
    tinyMCE.triggerSave(); // to be shure, that the changed content is in your jsf-component...
    // do something to trigger an ajax request handeling the changed html content. 
}

通过这种方式,您可以对用户通过键盘输入或粘贴内容对html编辑器输入的所有更改做出反应。当用户通过tinyMCE菜单更改html内容时,我没有找到任何一种通知的方法。 (例如,当用户将某些单词更改为粗体时...)

相关问题