Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate JSF component tree from a String template
    primarykey
    data
    text
    <p>Mojara 2.1.21, Primefaces 3.5.11, Omnifaces 1.5 I have a text saved in Java String:</p> <pre><code>this is my text with markers {1} second row {2} .... </code></pre> <p>Each marker has associated value (ex. {1} => 23, {2} => 45) in a HashMap. I want to generate jsf component tree where each marker will be replaced with "p:inputText" fields with associated values and text will be replaced with "h:outputText". If user changed something in an input field, that must be reflected in a backing bean when user click "Save" button. The formatting of text should be preserved. How can I solve this problem? The output .xhtml-rendered tree (dynamicaly created with java or generated from some .xhtml code)should be: </p> <pre><code>&lt;h:form&gt; &lt;h:outputText value="this is my text with markers " /&gt; &lt;p:inputText value="{mybean.value1}" /&gt; &lt;h:outputText value="newline seconde row" /&gt; &lt;p:inputText value={mybean.value2} /&gt; .... &lt;p:button value="save" actionListener="#{mybean.save()}"/&gt; &lt;/h:form&gt; </code></pre> <p>How can I create this component tree ? How can I bind the values in input text to the backing bean (because the number of all values is not fixed) ?</p> <p><strong>EDIT:</strong> my idea: split text in "text before, placeholder" pairs. Iterate with c:forEach loop and generate the components.</p> <pre><code>&lt;h:form&gt; &lt;c:forEach value="#{bean.pairs}" var="pair"&gt; &lt;h:outputText value="#{pair.text}" /&gt; &lt;c:if test="#{not empty pair.value}"&gt; &lt;p:inputText value="#{pair.value}" /&gt; &lt;/c:if&gt; &lt;/c:forEach&gt; &lt;p:commandButton value="save" /&gt; &lt;/h:form&gt; class Pair { String text; int placeholderNum; int value; //Getter and setter } @SessionScoped @Named class Bean { public List&lt;Pair&gt; 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 } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload