Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 将支持的bean中的字符串值添加到inputtext字段_Jsf - Fatal编程技术网

Jsf 将支持的bean中的字符串值添加到inputtext字段

Jsf 将支持的bean中的字符串值添加到inputtext字段,jsf,Jsf,我有一个web程序,必须能够执行以下操作: 用户将编写一条消息,发送到多个目标。在这种情况下,用户必须能够在其消息中插入变量数据。例如: 亲爱的${strName}生日快乐 在这种情况下,用户将有一个inputtext字段来编写消息,一个带有预定义字符串(姓名、年龄、性别等)的下拉菜单将通过命令按钮传递到inputtext字段。程序如何读取这些子字符串并将其转换为变量数据并不重要,我已经弄明白了 我的问题是我不知道如何像那样将下拉列表中的值插入InputEx表单。有什么想法吗?我将制作一个我的身

我有一个web程序,必须能够执行以下操作:

用户将编写一条消息,发送到多个目标。在这种情况下,用户必须能够在其消息中插入变量数据。例如:

亲爱的${strName}生日快乐

在这种情况下,用户将有一个inputtext字段来编写消息,一个带有预定义字符串(姓名、年龄、性别等)的下拉菜单将通过命令按钮传递到inputtext字段。程序如何读取这些子字符串并将其转换为变量数据并不重要,我已经弄明白了

我的问题是我不知道如何像那样将下拉列表中的值插入InputEx表单。有什么想法吗?我将制作一个我的身体模型

XHTML:

         <div class="col-md-3">
                                    <label style="padding-top:5px">Dados variaveis:</label><br/>
                                    <p:selectOneMenu value ="#{sistemaDeAvisos.buscaAlvosDB.variavel}" onchange="submit()">
                                        <f:selectItems value="#{sistemaDeAvisos.buscaAlvosDB.alvosTestesDropdown}"/>
                                    </p:selectOneMenu>
                                    <p:commandButton value="Submit"/>
                                </div>
                            </div>
                            <div class="row"  style="margin-left: 5px;margin-right: 5px">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label for="strMensagem">
                                            Mensagem(*): 
                                        </label>
                                        <h:inputTextarea value="#{sistemaDeAvisos.mensagem.strMensagem}" id="strMensagem" style="width:100%;min-height:200px"/>     
                                    </div>
                                </div> 

根据我们的评论,您可以将JSF代码包装在一个独立的
标记中,并使用AJAX将表单发送到bean,然后更新textarea的内容。我是这样想的:

    <h:form prependId="false" id="form">
        <h:selectOneMenu id="sel" label="Name: " value="#{testBean.selectValue}">
            <f:selectItem itemLabel="Choose" itemValue="" />
            <f:selectItem itemLabel="Joe" itemValue="Joe" />
            <f:selectItem itemLabel="Amy" itemValue="Amy" />
        </h:selectOneMenu>

        <h:commandButton type="button" value="Submit" id="btn" action="#{testBean.updateTextarea}">
            <!-- This sends the form with the "onclick" event to the backing bean to update the bean attributes, and then it updates the textarea -->
            <f:ajax execute="@form" event="click" render="txt" />
        </h:commandButton>

        <h:inputTextarea value="#{testBean.textareaValue}" id="txt" />
    </h:form>

尝试一下,如果您还需要其他内容,请告诉我。

我需要将下拉列表中的字符串作为子字符串写入inputTextfield@BalusC:我认为OP希望在客户端,在textArea字段的某个位置(光标处)插入字符串。要插入的文本需要来自dropdown@Kukeltje如果我让自己很难理解,那听起来像是一个简单的onchange事件,然后用AJAX更新textarea。使用
prependId=“false”
是一个不好的建议。这个解决方案是在固定的模板和固定的位置上工作。在我的upinionI中,不是一个好的解决方案,它这样做是为了简化答案,但我的主要想法是使用ajax更新textarea的内容,将select值放在上面。如果你能改进我的答案,或者提出更好的建议,我将不胜感激。我刚刚尝试过同样的方法,而且确实奏效了!问题是,我现在需要它在插入符号位置插入选定的值。但是你不必帮我,你帮得够多了!谢谢我会更新一下我正在做的事情。编辑:更新@幸运的是,我想问一下,文本区内的其余消息是否与以前一样?(不考虑select中选择的值),因为我认为您可以定义如下消息:
Dear\u name\u生日快乐
然后使用类似于
字符串的内容。替换(“\u name”,getSelectValue())
public void handleEvent(){

    StringBuilder strBuilder = new StringBuilder(mensagem.getStrMensagem());
    strBuilder.append(variavel);
    mensagem.setStrMensagem(strBuilder.toString());
    System.out.println(mensagem.getStrMensagem());
    System.out.println(strBuilder.toString());

}
    <h:form prependId="false" id="form">
        <h:selectOneMenu id="sel" label="Name: " value="#{testBean.selectValue}">
            <f:selectItem itemLabel="Choose" itemValue="" />
            <f:selectItem itemLabel="Joe" itemValue="Joe" />
            <f:selectItem itemLabel="Amy" itemValue="Amy" />
        </h:selectOneMenu>

        <h:commandButton type="button" value="Submit" id="btn" action="#{testBean.updateTextarea}">
            <!-- This sends the form with the "onclick" event to the backing bean to update the bean attributes, and then it updates the textarea -->
            <f:ajax execute="@form" event="click" render="txt" />
        </h:commandButton>

        <h:inputTextarea value="#{testBean.textareaValue}" id="txt" />
    </h:form>
//. . . 
private String selectValue;
private String textareaValue;

// getter and setter

public void updateTextarea() {
    setTextareaValue("Dear " + getSelectValue() + " happy birthday!");
}
//. . .