JSF UIData doesn't render a UIColumn children - jsf

I try understand how JSF UIData () works programaticaly in JSF. I have following code:
UIInput input = new UIInput();
UIInput input2 = new UIInput();
UIOutput header = new UIOutput();
header.setValue("Header");
UIColumn column = new UIColumn();
column.setHeader(header);
column.getChildren().add(input);
column.getChildren().add(input2);
UIData table = new UIData();
table.getChildren().add(column);
this code render html like:
<table>
<thead>
<tr>
<th scope="col">Header</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
where is my two inputs?? i expect something like:
.....
<tbody>
<tr>
<td>
<input type="text" />
</td>
</tr>
<tr>
<td>
<input type="text" />
</td>
</tr>
</tbody>
......

i know what i do wrong. I have to set a collection of UIData for rows of table. When i set
UIData table = new UIData();
ArrayList list = new ArrayList();
list.add("A");
list.add("B");
table.setValue(list);
than i get two rows with my inputs

Related

How to get values dynamically from a collection in a model in Razor Pages?

I'm trying to render lists of elements dynamically in ASPNETCore Razor Pages but I can't find the way to show the values of properties using Display Helper. M
<table class="table datatable">
<thead>
<tr>
#foreach (var item in Model.GetFieldNamesForList())
{
<th>
#Html.DisplayName(item)
</th>
}
<th></th>
</tr>
</thead>
<tbody>
#foreach (var item in Model.School) {
<tr>
#foreach (var propertyName in Model.GetFieldNamesForList())
{
<td>
// How to use #Html.Display using item from Model.School and the propertyName
</td>
}
<td>
<a asp-page="./Edit" asp-route-id="#item.Id" class="btn btn-primary btn-sm"><i class="material-icons md-16">edit</i></a>
<a asp-page="./Details" asp-route-id="#item.Id" class="btn btn-primary btn-sm"><i class="material-icons md-16">visibility</i></a>
<button action="submit" asp-page-handler="Delete" asp-route-id="#item.Id" class="btn btn-danger btn-sm"><i class="material-icons md-16">delete</i></button>
</td>
</tr>
}
</tbody>
</table>
In the meantime, I use reflection directly, but I would prefer use the Display method from helpers.
#item.GetType().GetProperty(propertyName).GetValue(item, null)

JSF selectBooleanCheckbox always checked

Good afternoon in my timezone.
<ui:repeat id="situacoes-edit-list" var="situacao" varStatus="loop" value="#{cc.attrs.managedBean.situacoesEditDTO}">
<tr id="sitEdit#{situacao.situacaoId}" class="situations">
<td colspan = "2">#{situacao.situacaoNome}</td>
</tr>
<ui:repeat id="justificacoes-list" var="justificacao" varStatus="innerLoop" value="#{situacao.justificacoes}">
<tr id="jusEdit#{justificacao.justificacaoId}" class="justifications">
<td>
<h:selectBooleanCheckbox binding="#{chkJust}" id="chk-just-#{chkJust.clientId}" value="#{justificacao.selected}" />
</td>
<td>#{justificacao.selected}</td>
</tr>
</ui:repeat>
</ui:repeat>
In the Bean the the get and set methods are the follow:
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
The resulting HTML
<tr id="jusEdit6" class="justifications">
<td><input id="container-edit-form:intervencaoJustificacoes:situacoes-edit-list:0:justificacoes-list:0:chk-just-j_id3" type="checkbox" name="container-edit-form:intervencaoJustificacoes:situacoes-edit-list:0:justificacoes-list:0:chk-just-j_id3" checked="checked" />
</td>
<td>false</td>
</tr>
<tr id="jusEdit2" class="justifications">
<td><input id="container-edit-form:intervencaoJustificacoes:situacoes-edit-list:0:justificacoes-list:1:chk-just-j_id3" type="checkbox" name="container-edit-form:intervencaoJustificacoes:situacoes-edit-list:0:justificacoes-list:1:chk-just-j_id3" checked="checked" />
</td>
<td>true</td>
</tr>
As you see the <td>#{justificacao.selected}</td> returns the correct value but the value="#{justificacao.selected}" does not produce the correct behaviour.
Why is this happening ?
I am using Mojarra 2.0.1
Thanks in advance
Best regards

Edit in view page or index.cshtml in MVC

I am using MVC 5 and Entity framework 6 (Database First) in my application.
I need to update "value" field in View page\index.cshtml.
Is it possible to use #Html.EditorFor to edit Value field for each Item on single button click?
Here is the code in index.cshtml
<table>
<tr>
<th>
Number
</th>
<th>
Name
</th>
<th>
Value
</th>
<th>
Description
</th>
</tr>
foreach (var item in Model) {
<tr>
<td>
#Html.DisplayFor(modelItem => item.number)
</td>
<td>
#Html.DisplayFor(modelItem => item.name)
</td>
<td>
#Html.EditorFor(modelItem => item.value)
#*#Html.ValidationMessageFor(modelItem => item.value) *#
</td>
<td>
#Html.DisplayFor(modelItem => item.description)
</td>
#* <td>
#Html.ActionLink("Edit", "Edit", new { id=item.id })
</td>*#
</tr>
</table>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
On clicking Save button I should update the data in Value field for any number of rows.
It's done in Database First so action for Edit,View,Details are included in Controller.
You'll have to put everything in a to post the details to the server, then you can manage the posted elements. You'll post a list of itens. Maybe this will help you: How can I post a list of items in MVC

Iterating Hashmap in jsp and Showing Data in Dynamically Generated Table

I am having hashmap in jsp.
I want to print all the values that hashmap contains in a table. The table should generated dynamically and after 3 columns next values should be displayed in next row and so on..Using jstl or any tag library.
So if hashmap contains 6 values then HTML generated should be:
<table>
<tr>
<td> val1 </td>
<td> val2 </td>
<td> val3 </td>
</tr>
<tr>
<td> val1 </td>
<td> val2 </td>
<td> val3 </td>
</tr>
</table>
If hashmap contains 8 values then HTML generated should be:
<table>
<tr>
<td> val1 </td>
<td> val2 </td>
<td> val3 </td>
</tr>
<tr>
<td> val4 </td>
<td> val5 </td>
<td> val6 </td>
</tr>
<tr>
<td> val7 </td>
<td> val8 </td>
</tr>
</table>
So as per number of values the number of rows should get added to table. How do I do that in jsp... either using jstl tags or any custom tag library?
Simply add the following java code in your jsp
<table>
<%
int count=0;
Iterator itr = yourMap.iterator();
while(itr.hasNext()) {
String key = itr.next();
if(count ==0) {
%>
<tr>
<% } %>
<td><% =yourMap.get(key) %></td>
<%
count ++;
if(count ==3 ) {
count =0;
%>
</tr>
<%>
}
</table>
Here I am assuing your map is <String,String> and please import relevant classes for map and iterator. Any JSP tutorial can tell you how o do that

JSF SelectOneMenu selected item

I can't get the selected item from a SelectOneMenu. I supply an ArrayList to the menu and want the user to select one of it. I put the menu into a form, so I have a commandButton which I intended to use to perform the selection. This implementation gives me this error : Cannot convert user3 of type class java.lang.String to class java.util.ArrayList when I select from the menu "user3", so it actually performs the selection correctly. The error refers to this line
<h:selectOneMenu value="#{user.myUsers}"
Here is the part of my xhtml which generates the selectOneMenu.
<h:panelGrid columns="3">
<h:form>
<h:selectOneMenu value="#{user.myUsers}">
<f:selectItems value="#{user.myUsers }"/>
</h:selectOneMenu>
<h:commandButton value="#{msgs.remove_user}" action="#{user.select }" ></h:commandButton>
</h:form>
<h:outputText value="#{ user.select}"></h:outputText>
</h:panelGrid>
And here is my UserBean:
#ManagedBean(name="user")
#SessionScoped
public class UserBean implements Serializable {
private String selected;
public ArrayList<String> getMyUsers()throws Exception
{
ArrayList<String> ret;
MySQLConnection conn = new MySQLConnection();
try{
ret = conn.getMyUsers(name);
}finally
{
conn.closeConnection();
}
return ret;
}
public String getSelect() throws Exception
{
if (this.selected==null) return this.getMyUsers().get(0);
return this.selected;
}
public void setSelect(String s)
{
this.selected = s;
}
}
Your arraylist is mapped to
<f:selectItems value="#{user.myUsers}"/>,
and after selection you are trying to put the selected value to the same list:
<h:selectOneMenu value="#{user.myUsers}">
You should have some object (or string in your case) in your managed bean linked with your view and fill it by selected item of myUsers. For example:
private String selectedUser; // + appropriate getter and setter
and <h:selectOneMenu> should look like:
<h:selectOneMenu value="#{user.selectedUser}">
selected item sould be stored in selectedUser to the end of jsf lifecycle
<table class="tableClass" id="productDescriptionTable">
<thead>
<tr class="trPDClass">
<th class="thPDClass"></th>
<th class="thPDClass">Feature</th>
<th class="thPDClass">SubFeature</th>
`enter code here`<th class="thPDClass">Type</th>
<th class="thPDClass">Sub-Feature Value</th>
`enter code here`<th class="thPDClass">Is Active</th>
<th class="thPDClass">Deleted</th>
</tr>
</thead>
<tbody>
<tr class="trPDClass">
<td class="tdPDClass" style="width: 30;" ><input type="checkbox" /></td>
<td class="tdPDClass"><input type="text" id="0PDfeature" name="PDfeature" /></td>
<td class="tdPDClass"><input type="text" id="0PDsubFeature" name="PDsubFeature" /></td>
<td class="tdPDClass"><input type="text" id="0PDtype" name="PDtype" /></td>
<td class="tdPDClass">
<div id="0PDsubFeatureValueDiv" name="PDsubFeatureValueDiv"></div>
</td>
<td class="tdPDClass">
<table class="radioClass">
<tr>
<td width="24%"><input type="radio" name="PDisActive" id="PDisActiveY" value="Y" /></td>
<td width="40%">Yes</td>
<td width="20%"><input type="radio" name="PDisActive" id="PDisActiveN" value="N" /></td>
<td width="16%">No</td>
</tr>
</table>
</td>
<td class="tdPDClass">
<table class="radioClass">
<tr>
<td width="24%"><input type="radio" name="PDdeleted" id="0PDdeletedY" value="Y" /></td>
<td width="40%">Yes</td>
<td width="20%"><input type="radio" name="PDdeleted" id="0PDdeletedN" value="N" /></td>
<td width="16%">No</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>

Resources