【问题标题】:Java JSF h:inputTextarea and output Textarea on same page?Java JSF h:inputTextarea和同一页面上的输出Textarea?
【发布时间】:2014-11-11 20:14:03
【问题描述】:

我的代码如下所示:

<h:form>
<h:inputTextarea value="#{spintax.content}" cols="30" rows="10" />
<h:commandButton value="Submit" action="spinned" />
</h:form>

它需要一些内容,对其进行更改并在 spinned.xhtml 页面上作为 outputText 给出响应。我也想做同样的事情,但我需要它保持在同一页面上并作为 Textarea(而不是 outputText)输出。输出文本区域应在 inputTextarea 下。可能吗 ?因此,您将一些内容放在文本区域并在其下的相同文本区域获得响应。

【问题讨论】:

    标签: html jsf


    【解决方案1】:

    是的,这是可能的。有几种方法可以实现它。我会展示两个:

    • &lt;h:form&gt; 之外有&lt;h:inputTextarea&gt;

      <h:form>
          <h:inputTextarea value="#{spintax.content}" cols="30" rows="10" />
          <h:commandButton value="Submit" action="spinned" />
      </h:form>
      <h:inputTextarea value="#{spintax.output}" cols="30" rows="10" />
      
    • 使用托管 bean 处理数据和 ajax:

      Facelets 代码:

      <h:form>
          <h:inputTextarea id="itaContent" value="#{spintax.content}" cols="30" rows="10" />
          <h:commandButton value="Submit" action="#{spintax.process}">
              <f:ajax render="itaOutput" execute="itaContent" />
          </h:commandButton>
          <h:inputTextArea id="itaOutput" value="#{spintax.content}" />
      </h:form>
      

      托管 bean 代码:

      @ViewScoped
      @ManagedBean
      public class Spintax {
          private String content;
          //proper getter/setter
          public void process() {
              //process the content if needed...
              //otherwise, do nothing
          }
      }
      

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-01
      • 2012-06-04
      • 1970-01-01
      • 2015-11-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多