Modify record using Struts2 - html

I have a table with a list of shows, my idea is to have a button that allows modifying each show:
...
<s:iterator value="%{listShow}" var="show">
<tr>
<td><s:property value="showId"></s:property></td>
<td><s:property value="showName"></s:property></td>
<td><s:property value="showDate"></s:property></td>
<td><s:property value="showPrice"></s:property></td>
<td><s:form action="goModify">
<s:submit value="Modify"></s:submit>
<s:hidden name="showId"></s:hidden>
<s:hidden name="showName"></s:hidden>
<s:hidden name="showDate"></s:hidden>
<s:hidden name="showPrice"></s:hidden>
</s:form></td>
</tr>
</s:iterator>
...
The only thing action "goModify" does is redirect to a modify.jsp file where I want to make the data changes:
<s:form action="modifyAction">
<s:textfield label="ID" name="showId" value="%{showId}"></s:textfield>
<s:textfield label="Show Name" name="showName" value="%{showName}></s:textfield>
<s:textfield label="Date" name="showDate" value="%{showDate}></s:textfield>
<s:textfield label="Price" name="showPrice"value="%{showPrice}></s:textfield>
<s:submit value="Modificar"></s:submit>
</s:form>
The problem that the filled fields do not appear to me.

You are only assigning a name to the hidden fields, not a value. You can use the attribute key instead of name. It will automatically generate HTML with the correct name and value.
<s:iterator value="%{listShow}" var="show">
<tr>
<td><s:property value="showId" /></td>
<td><s:property value="showName" /></td>
<td><s:property value="showDate" /></td>
<td><s:property value="showPrice" /></td>
<td>
<s:form action="goModify">
<s:submit value="Modify" />
<s:hidden key="showId" />
<s:hidden key="showName" />
<s:hidden key="showDate" />
<s:hidden key="showPrice" />
</s:form>
</td>
</tr>
</s:iterator>
If the action goModify does not store the parameters in the value stack (e. g. by storing them in attributes), you may have to change the JSP to access the request parameters directly.
<s:form action="modifyAction">
<s:textfield label="ID" name="showId" value="%{#parameters.showId}" />
<s:textfield label="Show Name" name="showName" value="%{#parameters.showName} />
<s:textfield label="Date" name="showDate" value="%{#parameters.showDate} />
<s:textfield label="Price" name="showPrice" value="%{#parameters.showPrice} />
<s:submit value="Modificar"></s:submit>
</s:form>
However, the best solution for the second JSP would also be to use key instead of name and value. But then you have to make sure to have the values on the value stack.

Related

Telerik Freezing header columns

From few days I have been trying to use freezing columns headers. I have followed knowledgebase of telerik reporting services. But still unable to get solutions.
<Table DataSourceName="sqlDataSource1" Width="3.531in" Height="0.48in" Left="0.4in" Top="0.4in" FreezeRowHeaders="False" FreezeColumnHeaders="True" Name="table1">
<Body>
<Cells>
<TableCell RowIndex="0" ColumnIndex="0" RowSpan="1" ColumnSpan="1">
<ReportItem>
<TextBox Width="1.177in" Height="0.24in" Left="1.8in" Top="0.2in" Value="= Fields.FirstName" Name="textBox7" StyleName="" />
</ReportItem>
</TableCell>
<TableCell RowIndex="0" ColumnIndex="1" RowSpan="1" ColumnSpan="1">
<ReportItem>
<TextBox Width="1.177in" Height="0.24in" Left="1.8in" Top="0.2in" Value="= Fields.InsertDate" Name="textBox2" StyleName="" />
</ReportItem>
</TableCell>
<TableCell RowIndex="0" ColumnIndex="2" RowSpan="1" ColumnSpan="1">
<ReportItem>
<TextBox Width="1.177in" Height="0.24in" Left="1.8in" Top="0.2in" Value="= Fields.LastName" Name="textBox4" StyleName="" />
</ReportItem>
</TableCell>
</Cells>
<Columns>
<Column Width="1.177in" />
<Column Width="1.177in" />
<Column Width="1.177in" />
</Columns>
<Rows>
<Row Height="0.24in" />
</Rows>
</Body>
<Corner />
<RowGroups>
<TableGroup Name="detailTableGroup">
<Groupings>
<Grouping />
</Groupings>
</TableGroup>
</RowGroups>
<ColumnGroups>
<TableGroup Name="tableGroup">
<ReportItem>
<TextBox Width="1.177in" Height="0.24in" Left="0in" Top="0in" Value="First Name" Name="textBox1" />
</ReportItem>
</TableGroup>
<TableGroup Name="tableGroup1">
<ReportItem>
<TextBox Width="1.177in" Height="0.24in" Left="0in" Top="0in" Value="Insert Date" Name="textBox3" />
</ReportItem>
</TableGroup>
<TableGroup Name="tableGroup2">
<ReportItem>
<TextBox Width="1.177in" Height="0.24in" Left="0in" Top="0in" Value="Last Name" Name="textBox5" />
</ReportItem>
</TableGroup>
</ColumnGroups>
</Table>
I am using above xml code for telerik reporting.
Thanks in advance
The configuration seems fine at first glance. Have you checked that the feature is supported (and makes sense) only for displaying in viewers in interactive mode?

how can i switch required element with selectOneRadio

i hava a register page and i need if i select item radio for example item one password required get true and if i select item two required get false
<p:selectOneRadio id="connection" value="#{UserBean.connection}" >
<f:selectItem itemValue="One" />
<f:selectItem itemValue="two" />
</p:selectOneRadio>
and i want something with this logic
<c:if test="#{UserBean.connection =='One'}" >
<p:password id="pwd" value="#{UserBean.pwd}" required="false" />
</c:if>
<c:if>
<p:password id="pwd" value="#{UserBean.pwd}" required="true" />
</c:if>
kind regards and thanks in advance :-)

Struts2 html checkbox not pre-checked

<body>
<h3>Register for a prize by completing this form.</h3>
<s:form action="register">
<s:textfield name="personBean.firstName" label="First name" />
<s:textfield name="personBean.lastName" label="Last name" />
<s:textfield name="personBean.email" label ="Email"/>
<s:textfield name="personBean.age" label="Age" />
<input type="checkbox" checked="checked" />
<s:submit/>
</s:form>
<input type="checkbox" checked="checked" />
</body>
I have a jsp with above content. The checkbox within the form is not checked whereas the checkbox outside form is pre-checked. I am mixing up plain html checkbox and non-html elements within a Struts2 form.
Here you have malformed html by putting input tag like that in your form.
To resolve it,you can use s:checkbox
<s:checkbox name="checkMe" fieldValue="true" label="Check Me for testing" value="true"/>

How Can i Update a Table (not datatable) with a Primefaces CommandButton

<h:form id="tableForm">
<table id="myTable">
<tr>
<th>HeaderOne</th>
<th>HeaderTwo</th>
<th>HeaderThree</th>
</tr>
<ui:repeat value="#{myBean.List}" var="row">
<tr class="myRows">
<td><input type="text" value="#{row.fieldOne} required="required" /></td>
<td><input type="text" value="#{row.fieldTwo} /></td>
<td><input type="text" value="#{row.fieldThree} /></td>
</tr>
</ui:repeat>
</table>
<p:commandButton id="myButton" value="Load" action="#{myBean.load}" process="#this" update="myTable" />
</h:form>
i want to load some stuff into my inputFields from my bean, but have one field that is required when i press save. So i have to set process to #this.
Afterwards i want my table to be updated. But i doesn't work.
What am i doing wrong?
try updating the form instead
<p:commandButton ... action="#{myBean.load}" process="#this" update="tableForm" />
since the table is not a jsf element but "pure" html, you can't use it's id in jsf elements
Schäbo answer is right (+1) but Primefaces also provides a p:fragment component so you may update only the region you want to:
<p:fragment id="myFragmentReloaded">
<table>
...
</table>
</p:fragment>
and then
<p:commandButton ... action="#{myBean.load}" process="#this" update="myFragmentReloaded" />

Using Omnifaces EL functions in composite component with Mojarra 2.2.5

After upgrading to JSF Mojarra 2.2.5, i get the following exception when using Omnifaces's el function formatNumber. This only occurs within a composite component. Normal Facelet is working fine.
javax.el.ELException: Function 'of:formatNumber' not found
this is my composite component:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:cc="http://xmlns.jcp.org/jsf/composite"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:of="http://omnifaces.org/functions">
<cc:interface>
<cc:attribute name="cart" required="true" type="org.ead.eeb.order.ShoppingCart" />
<cc:attribute name="allowCouponRemove" required="true" type="java.lang.Boolean" />
<cc:attribute name="removeCouponBean" type="java.lang.Object" />
<cc:attribute name="removeCouponAction" type="java.lang.String" />
<cc:attribute name="removeCouponProperty" type="java.lang.String" />
</cc:interface>
<cc:implementation>
<h4>Übersicht</h4>
<table class="table">
<tbody>
<c:forEach items="#{cc.attrs.cart.items}" var="item">
<tr>
<td><abbr title="#{item.description}">#{item.name}</abbr></td>
<td class="text-right">#{of:formatNumber(item.totalAmount, '#0.00')} €</td>
</tr>
</c:forEach>
<tr>
<td>Mehrwertsteuer (#{cc.attrs.cart.taxRatePercentage} %)</td>
<td class="text-right">#{of:formatNumber(cc.attrs.cart.totalTax, '#0.00')} €</td>
</tr>
</tbody>
<tfoot>
<tr class="active">
<td><strong>Gesamtbetrag</strong></td>
<td class="text-right"><strong>#{of:formatNumber(cc.attrs.cart.totalOrderAmount, '#0.00')} €</strong></td>
</tr>
</tfoot>
</table>
...
</cc:implementation>
thanks in advance for your help :)
Edit:
the problem occurs, if i use the value from cc.attrs.*. If I use the value directly as an attribute, everthing is working well. Any ideas?
Edit2:
A workaround is possible by the following code
<c:set var="test" value="#{cc.attrs.value}" />
#{of:formatNumber(test, '#0.00')}
but that's pretty ugly. I can't find my mistake.
The issue i created was marked as Wont't Fix, since there is a workaround:
Replacing all convenient inline el calls of type #{foo} with <h:outputText value="#{foo}"/>.
https://java.net/jira/browse/JAVASERVERFACES-3469
Very inconvenient and cumbersome. Many regressions from 2.2.4 -> 2.2.5.