Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Nice question. BalusC's answer is - as always - complete and right. </p> <p>However, if your point is to create an application where gui is built dynamically, there is a way that might serve you better (depending on what you really want to achieve).</p> <p>JSF views are similar to Swing forms - they are just a bunch of JavaBeans(tm) glued together. The big difference is that when a field is bound to an EL expression, you do not use standard accessors, but rather a special method (setValueExpression).</p> <p>This means you can build your GUI from objects (the concrete classes can be found in javax.faces.component.html) in a pure programmatic way and then use binding attribute to show it on page. Something like:</p> <pre><code>&lt;h:form&gt; &lt;h:panelGrid binding="#{formBuilder.component}"/&gt; &lt;/h:form&gt; </code></pre> <p>And then in the managed formBuilder bean:</p> <pre><code>@PostConstruct public void init() { HtmlInputText hit = new HtmlInputText(); // properties are easy: hol.setStyle("border: 2px solid red"); // binding is a bit harder: hit.setValueExpression("value", expression("#{test.counter}", String.class)); HtmlOutcomeTargetLink hol = new HtmlOutcomeTargetLink(); hol.setValue("link leading to another view"); hol.setOutcome("whatever"); component = new UIPanel(); component.getChildren().add(hit); component.getChildren().add(hol); } private ValueExpression expression(String s, Class c){ return FacesContext.getCurrentInstance().getApplication().getExpressionFactory().createValueExpression( FacesContext.getCurrentInstance().getELContext(), s, c ); } </code></pre> <p>The example above builds a static panel, but it would be possible to:</p> <ul> <li>create an object model of your GUI</li> <li>map the model to database (with hibernate or another orm)</li> <li>write some kind of adapter or bridge to build JSF objects from your object model</li> <li>make a managed bean that receives the form id, grabs the relevant form from database, builds a JSF panel out of it and presents it as a property, ready to be bound.</li> </ul> <p>This way you could have just one static xhtml with a single tag and use it to present any number of dynamic forms.</p> <p>As I said, this method could be better than just storing files, but not necessarily. If you just want to save yourself the hassle of redeployment, this is a huge overkill (then again, you do NOT need to redeploy JSF applications just to change forms). If on the other hand your goal is to have something like user-defined and edited forms, having a good object model and storing it in a proper way could be a good idea.</p> <p>The bumps ahead would be:</p> <ul> <li>navigation (perhaps a custom navigation handler would suffice?)</li> <li>problems with generating plain html</li> <li>possibly some problems with lifecycle of view scoped forms</li> </ul>
    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.
    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