0

I have this piece a code in a XHTML document associate to myView bean.

<p:outputtext value="#{myView.getDynamicContent()}" />

The method getDynamicContent() returns text that sometimes includes another PrimeFaces tag as for example <p:inputMask>.

When the first <p.outputtext> is evaluated, it prints all is returned by method as text and it's not evaluated!

Can I solve this problem or is it not possible? In case it isn't possible, I thought about replace all <p:inputMask> with <input> tag. In this case how can I recover the value inserted into input tag in the Java view code?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Pascal NoPascensor
  • 171
  • 1
  • 1
  • 14
  • 1
    Why don't you just use XHTML to dynamically create components? Does this answer your http://xyproblem.info? http://stackoverflow.com/q/3510614 – BalusC Aug 25 '16 at 19:34
  • How can i create components dynamically? Can you explain me how create a rendered tag starting from a String returned from that method? – Pascal NoPascensor Aug 25 '16 at 20:08
  • That's explained in detail in the given link. Your attempt is technically flawed and would require an unnecessarily overcomplicated solution of basically reinventing another JSF framework on top of JSF itself. – BalusC Aug 25 '16 at 20:19
  • Worth checking out: http://www.primefaces.org/showcase-ext/views/dynaForm.jsf – Jasper de Vries Aug 25 '16 at 21:53
  • @BalusC the link you posted doesn't fit my needs: in that case the position of an input tag is fixed (can change the presence or the absence). I try to explain it better: suppose that my method returns (Some textother text), at this point i can't apply that solution. Same if the method returns more input tags – Pascal NoPascensor Aug 26 '16 at 06:23
  • I perfectly understood what you want. Did you understand me? **Your attempt is not possible**. As said, your attempt is technically flawed and would require an unnecessarily overcomplicated solution of basically reinventing another JSF framework on top of JSF itself. It doesn't make sense. You're basically missing the whole point of JSF. – BalusC Aug 26 '16 at 06:26

1 Answers1

0

What you are trying to do is not the best thing. The tags that you add to your original xhtml page are not just converted to HTML markup straight through. First for each of the jsf tag you get a component created which is added to the component tree. And the expressions are evaluated only after the tree is complete. And your expression can not change the component tree because it will be just evaluated into 'value' field of the component object. And only on the last Render Response phase the value will be added to the HTML markup. Like BalusC already noted it will be netter if you to create your dynamic components markup using c:if c:when tags instead of generating your markup using java code in the backing bean. If you will insist on your solution an answer to your last question is that you can always access the values from inputs that were submitted with the form using HttpServletRequest object directly. You can always get it always from the FacesContext.

trims
  • 453
  • 4
  • 9