2110

Different components in same column in datatable in JSF 2.0

Question:

Is it possible to have different types of components in a single column in a data table using JSF 2.0?

My requirement is that based on the label column value, the value column will have an input text or select list accordingly.

Currently I'm trying to do this via a backing bean. I have the label, value and type of component (e.g. "selectlist") in an arraylist.

When I'm iterating this list in a data table, how do I check the type and depending on the outcome create either an input or select list?

Answer1:

Use the rendered attribute with a test that uses whatever it is you use to distinguish between an input and a select list.

E.g.

<pre class="lang-xml prettyprint-override"><h:dataTable value="#{yourBacking.yourList} var="item"> <h:column> <h:inputText value="#{item.value}" rendered="#{item.type == 'input'}" /> <h:selectOneMenu value="#{item.value}" rendered="#{item.type == 'selectlist'}"> <f:selectItems value="#{item.values}" /> </h:selectOneMenu> </h:column> </h:dataTable>

Recommend

  • Setting default selected value of selectlist inside an editor template
  • Pass @Html.DropDownList selection using @Html.ActionLink with ViewModel to Controller
  • Asp.net mvc dropdown list using ViewBag
  • How to execute javascript method from server side?
  • How to reset the selected index dropdown value in html?
  • Why “propdp” code snippet doesn't use the nameof operator for the name of the registered proper
  • Singleton Alternative - is it equivalent?
  • How to call BeanFactoryPostProcessor.postProcessBeanFactory method when use Spring with XML configur
  • JPA CDI Injecting DAO into an Entity
  • What is the likely cause of a net::ERR_CONNECTION_ABORTED when uploading a file to Spring
  • Display validation errors inside
  • xcode don't localize specific strings
  • How can I enlarge video fullscreen without the affected interface project in as3?
  • Swift: Switch statement fallthrough behavior
  • Typescript - Unable to get 'import' statement to function
  • Disabling Alt-F4 on a Win Forms NotifyIcon
  • How do I change content of ComboFieldEditor?
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • java.lang.NoClassDefFoundError: com.parse.Parse$Configuration$Builder on below Lollipop versions
  • Updating server-side rendering client-side
  • MySQL WHERE-condition in procedure ignored
  • Which linear programming package should I use for high numbers of constraints and “warm starts” [clo
  • what is the difference between the asp.net mvc application and asp.net web application
  • ORA-29908: missing primary invocation for ancillary operator
  • Web-crawler for facebook in python
  • How to get next/previous record number?
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • Matrix multiplication with MKL
  • trying to dynamically update Highchart column chart but series undefined
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How do you join a server to an Active Directory (domain)?
  • How do I configure my settings file to work with unit tests?
  • Turn off referential integrity in Derby? is it possible?
  • How does Linux kernel interrupt the application?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Add sale price programmatically to product variations
  • Binding checkboxes to object values in AngularJs
  • Unable to use reactive element in my shiny app
  • java string with new operator and a literal
  • How do I use LINQ to get all the Items that have a particular SubItem?