Fórum

Creating a form with JSF

thumbnail
Kyle Joseph Stiemann, modificado 8 Anos atrás.

RE: Creating a form with JSF

Liferay Master Postagens: 760 Data de Entrada: 14/01/13 Postagens Recentes
Hi Eric,

You may want to check out a JSF tutorial to help you to get started with JSF.

In order to solve your specific problem, I would recommend using h:dataTable. I don't know exactly what you need, but you could probably do something like this in your .xhtml:

<h:form>
	<h:datatable value="#{applicantModelBean.rows}" var="row">
		<h:column rowheader="true">
			<f:facet name="header"></f:facet>
			<h:outputtext value="#{row.name}" />
		</h:column>
		<h:column>
			<f:facet name="header">col1</f:facet>
			<h:selectbooleancheckbox value="#{row.col1checked}" />
		</h:column>
		<h:column>
			<f:facet name="header">col2</f:facet>
			<h:selectbooleancheckbox value="#{row.col2checked}" />
		</h:column>
		<h:column>
			<f:facet name="header">col3</f:facet>
			<h:selectbooleancheckbox value="#{row.col3checked}" />
		</h:column>
	</h:datatable>
	<h:commandbutton value="Submit" />
</h:form>

You will also need a row object such as a user or traveler. Here's a generic row example:

public class Row {

	private String name;
	private boolean col1checked;
	private boolean col2checked;
	private boolean col3checked;

	public Row(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isCol1checked() {
		return col1checked;
	}

	public void setCol1checked(boolean col1checked) {
		this.col1checked = col1checked;
	}

	public boolean isCol2checked() {
		return col2checked;
	}

	public void setCol2checked(boolean col2checked) {
		this.col2checked = col2checked;
	}

	public boolean isCol3checked() {
		return col3checked;
	}

	public void setCol3checked(boolean col3checked) {
		this.col3checked = col3checked;
	}
}

Finally you will need a backing bean with an appropriate scope (@SessionScoped is used for example, but it may not be appropriate for your project):

@ManagedBean(name = "applicantModelBean")
@SessionScoped
public class ApplicantModelBean implements Serializable {

	private List<row> rows;
	private Row row1;
	private Row row2;
	private Row row3;

	public ApplicantModelBean() {
		rows = new ArrayList<row>();
		row1 = new Row("row1");
		row2 = new Row("row2");
		row3 = new Row("row3");
		rows.add(row1);
		rows.add(row2);
		rows.add(row3);
	}

	public List<row> getRows() {
		return rows;
	}

	public void setRows(List<row> rows) {
		this.rows = rows;
	}
}
</row></row></row></row>

- Kyle
Abderrazek Gasmi, modificado 8 Anos atrás.

ui:repeat and h:selectBooleanCheckbox

New Member Mensagem: 1 Data de Entrada: 04/09/15 Postagens Recentes
Hi

to resolve problem of
ui:repeat with h:selectBooleanCheckbox
you can use a4j:repeat instead of ui:repeat

thinks
Gasmi