0

In a previous web app I had made, I had used a String stored in my Managed bean to store a table in HTML, and returned it using a textOutput using JSF. I was wondering if this is possible with the HTML being returned containing JSF tags as well. For example:

My Managed Bean:

@ManagedBean(name = "account")
@ViewScoped
public class Account{

String subForm = "";

/* getters and setters */

public String login()
{   
    boolean a = true;

    subForm = "<div id='userdivcor' class='form-inline has-success'>"
    + "<h:inputText id='corruser' type='text' value='#{account.username}'/>"
    + "</div>";

    return "loginError.xhtml";

}

My .xhtml file:

//some code leading to my form
<h:form id='form' method='post' onsubmit='return fullCheck()'>
    <h:outputText id="htmlStuffTwo" value="#{account.subForm}" escape="false"/> 
</h:form>
//remainder of code

Using h:outputText, could I render my returned String value without any errors? Currently, I am trying this on a larger scale, but when the text goes to render, my value is something crazy like:

 "hdOMomYGEH3QfwJfNhPPECOG2Pv3gt/2F1n7dFGGp6ItPlhzDREjEJTSax3NjvsVDdiBZQsB"

Just curious, please let me know!

1 Answer 1

1

No; JSF tags are interpreted on the server, but the content of a h:outputText is sent to the browser.

It is also worth noting that your current approach must disable HTML escaping to work, which is a security vulnerability if your table also contains user-supplied data.

The usual way is to have the tabular data in the backing bean, and use iterating jsf components such as a h:datatable (or its equivalent from whatever component library you are using), ui:repeat, or c:foreach to render the table.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.