JSF SelectOneMenu selected item - jsf

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>

Related

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

How to pass product TVs to SimpleCart's scGetCart snippet?

I need some TVs (weight, dimensions, etc) I've associated with my products to appear in the Cart page of my SimpleCart site.
Problem is I have no idea how to do this. I don't understand how the SimpleCart cart is built and there isn't documentation for this.
Would anyone know how I can show TVs associated with each product in the cart output chunk?
The cart snippet has the following code which gets data from the cart and puts it into Chunks:
$sc = $modx->getService('simplecart','SimpleCart',$modx->getOption('simplecart.core_path',null,$modx->getOption('core_path').'components/simplecart/').'model/simplecart/',$scriptProperties);
if (!($sc instanceof SimpleCart)) return '';
 
$controller = $sc->loadController('Cart');
$output = $controller->run($scriptProperties);
The output Chunk looks like:
<div id="simplecart">
<form action="[[~[[*id]]]]" method="post" id="form_cartoverview">
<input type="hidden" name="updatecart" value="true" />
<table>
<tr>
<th class="desc">[[%simplecart.cart.description]]</th>
<th class="price">[[%simplecart.cart.price]]</th>
<th class="quantity">[[%simplecart.cart.quantity]]</th>
[[+cart.total.vat_total:notempty=`<th class="quantity">[[%simplecart.cart.vat]]</th>`:isempty=``]]
<th class="subtotal">[[%simplecart.cart.subtotal]]</th>
<th> </th>
</tr>
[[+cart.wrapper]]
[[+cart.total.discount:notempty=`<tr class="total first discount">
<td colspan="[[+cart.total.vat_total:notempty=`3`:isempty=`2`]]"> </td>
<td class="label">[[%simplecart.cart.discount]]</td>
<td class="value">- [[+cart.total.discount_formatted]]</td>
<td class="extra">[[+cart.total.discount_percent:notempty=`([[+cart.total.discount_percent]]%)`:isempty=` `]]</td>
</tr>`:isempty=``]]
[[+cart.total.vat_total:notempty=`
<tr class="total [[+cart.total.discount:notempty=`second`:isempty=`first`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_ex_vat]]</td>
<td class="value">[[+cart.total.price_ex_vat_formatted]]</td>
<td class="extra"> </td>
</tr>
[[+cart.vat_rates]]
<tr class="total [[+cart.total.discount:notempty=`third`:isempty=`second`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_vat]]</td>
<td class="value">[[+cart.total.vat_total_formatted]]</td>
<td class="extra"> </td>
</tr>
<tr class="total [[+cart.total.discount:notempty=`fourth`:isempty=`third`]]">
<td colspan="3"> </td>
<td class="label">[[%simplecart.cart.total_in_vat]]</td>
<td class="value">[[+cart.total.price_formatted]]</td>
<td class="extra"> </td>
</tr>
`:isempty=`
<tr class="total [[+cart.total.discount:notempty=`second`:isempty=`first`]]">
<td colspan="2"> </td>
<td class="label">[[%simplecart.cart.total]]</td>
<td class="value">[[+cart.total.price_formatted]]</td>
<td class="extra"> </td>
</tr>
`]]
</table>
<div class="submit">
<input type="submit" value="[[%simplecart.cart.update]]" />
</div>
</form>
This does appear to be documented:
Product Options (TVs)
and to output them:
Modifying the Product Template
It appears that you would just output them normally [[*myProductOptions]]
Though, it appears that your template is using a placeholder, I would try
[[+cart.myProductOptions] as well. If all else fails you might try debugging the simplecart class and dump the array of product data before it populates the chunk, there might be a clue in there.
Found (through trial and error) you must use:
[[+product.tv.name_of_tv]]

JSF UIData doesn't render a UIColumn children

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

How to iterate a map on XHTML pages?

I have a list like below
List<Map<String,List<ActivitiesData>>>
When I tried to iterate map in xhtml page I am able to get the List<ActivitiesData> values but I am unable to get the key(String) from map
The code is like below.
<ui:repeat var="timelineDateMapObject" value="#{timelineBean.timelineList}">
<ui:repeat value="#{timelineDateMapObject.keySet().toArray()}" var="x">
<ui:repeat var="timelineData" value="#{timelineDateMapObject.get(x)}" varStatus="status">
<tr>
<td style="padding-right: 10px;padding-left: 20px;"> #{timelineData.hoursAndMiniuts}</td>
<td style="padding-right: 10px;padding-left: 20px;"> #{timelineData.type}</td>
</tr>
<tr>
<td style="padding-right: 10px;padding-left: 20px;">
<h:graphicImage style="height: 50px; width: 50px" value="#{timelineData.url}" />
</td>
<td style="padding-right: 10px;padding-left: 20px;">#{timelineData.text}</td>
</tr>
<tr>
<td height="25px"></td>
<td></td>
</tr>
</ui:repeat>
</ui:repeat>
</ui:repeat>
Anyone please tell me how can I display key from map?
Try this
<ui:repeat var="timelineDateMapObject" value="#{timelineBean.timelineList}">
<c:forEach items="#{timelineDateMapObject}" var="timelineData">
<tr>
<td style="padding-right: 10px;padding-left: 20px;"> #{timelineData.value.hoursAndMiniuts}</td>
<td style="padding-right: 10px;padding-left: 20px;"> #{timelineData.value.type}</td>
</tr>
<tr>
<td style="padding-right: 10px;padding-left: 20px;">
<h:graphicImage style="height: 50px; width: 50px" value="#{timelineData.value.url}" />
</td>
<td style="padding-right: 10px;padding-left: 20px;">#{timelineData.value.text}</td>
</tr>
<tr>
<td height="25px"></td>
<td></td>
</tr>
</c:forEach>
</ui:repeat>

How can i create this table example with Primefaces p:dataTable?

I have a table in JSF Page:
<table cellpadding="0" cellspacing="0" border="1" align="center">
<col width="300"/>
<col width="150"/>
<col width="150" span="3"/>
<thead>
<tr>
<th rowspan="3" > </th>
<th rowspan="3" >A</th>
<th colspan="3" >B</th>
</tr>
<tr>
<th colspan="2">C</th>
<th rowspan="2">D</th>
</tr>
<tr>
<th>E</th>
<th>F</th>
</tr>
</thead>
<tbody>
<c:forEach items="${indexbean.regions}" var="r">
<tr>
<td colspan="5" >#{r.region}</td>
</tr>
<c:forEach items="${indexbean.table_data}" var="s">
<c:if test="${s.reg eq r.region}">
<tr>
<td>#{s.rowname}</td>
<td>#{s.d1}</td>
<td>#{s.d2}</td>
<td>#{s.d3}</td>
<td>#{s.d4}</td>
</tr>
</c:if>
</c:forEach>
</c:forEach>
</tbody>
</table>
These codes work properly. But i want to use primefaces p:dataExporter (for download this table as Excel), that is why i must create this table with p:dataTable. I can't find solution what i can replace 2 forEach method in p:dataTable.
How can i create this table with Primefaces p:dataTable? Please, help me.

Resources