Mojara 2.1.21,Primefaces 3.5.11,Omnifaces 1.5我有一个用Java字符串保存的文本:

this is my text with markers {1} 
second row {2} ....

每个标记在HashMap中具有关联值(例如{1} => 23,{2} => 45) . 我想生成jsf组件树,其中每个标记将被替换为带有关联值的“p:inputText”字段,文本将替换为“h:outputText” . 如果用户在输入字段中更改了某些内容,则当用户单击“保存”按钮时,必须将其反映在辅助bean中 . 应保留文本格式 . 我怎么解决这个问题?输出.xhtml呈现的树(使用java动态创建或从某些.xhtml代码生成)应该是:

<h:form>
   <h:outputText value="this is my text with markers " />
   <p:inputText value="{mybean.value1}" />
   <h:outputText value="newline seconde row" />
   <p:inputText value={mybean.value2} />
   ....
   <p:button value="save" actionListener="#{mybean.save()}"/>
</h:form>

如何创建此组件树?如何将输入文本中的值绑定到辅助bean(因为所有值的数量都不固定)?

EDIT: 我的想法:在"text before, placeholder"对中拆分文本 . 使用c:forEach循环迭代并生成组件 .

<h:form>
   <c:forEach value="#{bean.pairs}" var="pair">
       <h:outputText value="#{pair.text}" />
       <c:if test="#{not empty pair.value}">
          <p:inputText value="#{pair.value}" />
       </c:if>
   </c:forEach>
   <p:commandButton value="save" />
</h:form>


class Pair {
   String text; 
   int placeholderNum; 
   int value;
   //Getter and setter
}

@SessionScoped @Named
class Bean {
   public List<Pair> getPairs () {  //compute pairs with a help of regex and split
       //from input text, and replace the values
   }

   public save() {
       //iterate over pairs and save the values in hashmap
   }

}