本文介绍了将inputRichText绑定到Bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将xp:inputRichText绑定到bean(ChatBean),但是当代码尝试将字段更新为bean时出现此验证错误:

I'm trying to bind an xp:inputRichText to a bean (ChatBean), but get this validation error when the code tries update the field to the bean:

java.lang.IllegalArgumentException: argument type mismatch

我尝试了几种不同的操作,例如转换器,以确保文本为字符串,打印调试消息以找出错误所在,并更改了"setChatContent()"方法的类型(输入为只读),但无法正常工作.

I've tried a few of different things like converters to make sure the text will be a string, printing debug messages to find out where things go wrong, changed the type of the "setChatContent()" method (that sets the input to read-only), but can't get it to work.

我错过了什么吗,还是不可能?有什么想法吗?

Am I missing something, or is it not possible? Any thoughts?

页面:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:messages id="messages1"></xp:messages>

<xp:inputRichText id="inputRichText1" value="#{Chat.chatContent}"></xp:inputRichText>

<xp:button value="Save" id="button1" type="button">
    <xp:eventHandler event="onclick" submit="true" refreshMode="complete" save="false">
        <xp:this.action>
            <xp:actionGroup>
                <xp:executeScript script="#{javascript:Chat.saveContent();}"></xp:executeScript>
                <xp:openPage name="/chat.xsp"></xp:openPage>
            </xp:actionGroup>
        </xp:this.action>
    </xp:eventHandler>
</xp:button>

我点击保存"按钮后出现错误,该按钮在Chat bean上调用了一个方法(代码缩短了):

The error occurs after I hit the "Save" button, which calls a method on the Chat bean (code is shortened):

public class ChatBean implements Serializable {
    private static final long serialVersionUID = 1L;
    private String chatContent;

    public String getChatContent() {
        return chatContent;
    }

    public void setChatContent(String chatContent) {
        this.chatContent = chatContent;
    }

    public void saveContent() {
        // TODO implement save
        this.chatContent = "";
    }
}

推荐答案

需要类型为com.ibm.xsp.http.MimeMultipart

如果您更改ChatBean以使其与此一起使用,则它应可按需工作:

If you change your ChatBean to work with this instead, it should work as desired:

public class ChatBean implements Serializable {
   private static final long serialVersionUID = 1L;
   private com.ibm.xsp.http.MimeMultipart chatContent;

   public com.ibm.xsp.http.MimeMultipart getChatContent() {
       return chatContent;
   }

   public void setChatContent(com.ibm.xsp.http.MimeMultipart chatContent) {
       this.chatContent = chatContent;
   }

   public void saveContent() {
       // TODO implement save
       this.chatContent = null;
   }
}

这篇关于将inputRichText绑定到Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:42