struts2 if condition with property or tiles-attribute doesnt work - iterator

i have problems with my if condition using struts 2.
I have a tiles-definition using a put-list-attribute with list-attributes as menuitems.
In my menu.jsp i iterate over the put-list to render all my menuitems.
Now i try to check if the value of my item contains a special character.
Here is my code:
tiles.xml
<definition name="start.menu" template="/WEB-INF/menu.jsp" >
<put-attribute name="title" value="Hauptmenu" />
<put-list-attribute name="webThemes" >
<add-list-attribute>
<add-attribute value="Test" id="name"/>
<add-attribute value="atest" />
</add-list-attribute>
<add-list-attribute>
<add-attribute value="System Test"/>
<add-attribute value="test" />
</add-list-attribute>
</put-list-attribute>
</definition>
menu.jsp
<%# taglib prefix="s" uri="/struts-tags" %>
<%# taglib uri="/tiles-jsp" prefix="tiles" %>
<%# taglib uri="/tiles-extras-jsp" prefix="tilesx" %>
<%-- Push tiles attributes in page context --%>
<tiles:importAttribute />
<tilesx:useAttribute id="list" name="webThemes" classname="java.util.List" />
<table class="menu" border="0px" width="100%" cellspacing="0px" cellpadding="0px" >
<s:iterator value="#attr.webThemes" var="item">
<s:if test="%{#item.value[1].contains('a')}">
<s:set var="link" value="111"/>
</s:if>
<s:else>
<s:set var="link" value="#item.value[1]"/>
</s:else>
<tr>
<td valign="top" >
<font size="-1">
<a href="<s:property value="#link"/>"
class="menu">
<s:property value="#item.value[0]" />
<s:property value="#item.value[1]" />
</a>
</font>
</td>
</tr>
</s:iterator>
But the condition is always false.
I tried different approaches but nothing worked:
<s:if test="%{#item.value[1].contains('a')}">
<s:if test="#item.value[1].contains('a')">
<s:if test='%{#item.value[1].contains("a")}'>
<s:set var="itemvalue" value="#item.value[1]"/>
<s:property value="itemvalue"/>
<s:if test='%{#itemvalue.contains("a")}'>
<s:if test='#itemvalue.contains("a")'>
<s:if test='%{#item.value[1] == "atest"}'>
So how can i get the condition working? What am i doing wrong?
Thanks!!!

Ok... i tried 2 days until i posted my question.
but after posting a found a working solution in an hour...:
<s:if test='(#item.value[1].value).startsWith("a")'>

Related

How to use KendoDatePicker within x-kendo-template in .NET Core

I have a popup editor template working for when I want to add/edit a row in my Kendo grid and it is bound to the model's properties. The issue is that I am unable to get Kendo widgets (e.g. datepicker or dropdownlist) to generate inside the kendo-template (primarily wanting to use taghelpers). Nor have I been able to use jQuery to convert inputs into kendo widgets on $(document).ready(). How can I do this?
My grid:
<kendo-grid name="accountsGrid" height="500" on-detail-init="onDetailInit">
<datasource type="DataSourceTagHelperType.Ajax" page-size="10">
<transport>
<read url="?handler=Accounts&id=#Model.Id" data="getAntiForgeryKeyValue" type="POST" />
<create url="?handler=CreateAccount&id=#Model.Id" data="getAntiForgeryKeyValue" type="POST" />
<update url="?handler=EditAccount&id=#Model.Id" data="getAntiForgeryKeyValue" type="POST" />
</transport>
<schema>
<model id="AccountId">
<fields>
<field name="LastUpdateDate" type="Date"></field>
</fields>
</model>
</schema>
</datasource>
<columns>
<column field="Id" hidden="true" />
<column field="AccountName"
title="Account Name"
header-html-attributes='HeaderHtmlAttribute(title:"Account Name")' />
<column field="LastUpdateDate"
title="Last Updated"
format="{0:MMMM dd, yyyy}"
header-html-attributes='HeaderHtmlAttribute(title:"Last Updated")' />
<column title="Actions"
header-html-attributes='HeaderHtmlAttribute(title:"Actions")'
html-attributes='new Dictionary<string, object> {["class"] = "center-cell" }'>
<commands>
<column-command name="edit" />
</commands>
</column>
</columns>
<toolbar>
<toolbar-button name="create" template="getTelerikButton('Add')" />
</toolbar>
<editable mode="popup" template-id="accountEditorTemplate" />
<pageable button-count="5" refresh="true" page-sizes="new int[] { 5, 10, 20 }">
</pageable>
<scrollable enabled="true" />
My Editor Template:
<script id="accountEditorTemplate" type="text/x-kendo-template">
<div class="row editor-padding">
#*Account Details*#
<div class="col-md-6 col-xs-12">
<h5 class="editorTemplateHeader">Account Details</h5>
<div class="k-edit-label">
<label for="AccountName">Account Name</label>
</div>
<div class="k-edit-field">
<input required type="text" class="k-input k-textbox" name="AccountName" validationmessage="Account Name is required" maxlength="8" />
</div>
<div class="k-edit-label">
<label for="Description">Description</label>
</div>
<div class="k-edit-field">
<input type="text" class="k-input k-textbox" name="Description" maxlength="100" />
</div>
<div class="k-edit-label">
<label for="ExpirationDate">Expiration Date</label>
</div>
<div class="k-edit-field">
#*I would like to do this, but nothing appears*#
<kendo-datepicker name="ExpirationDate"></kendo-datepicker>
</div>
</div>
</div>
I resolved the problem. It involved using data- syntax. Below is the solution:
<div class="k-edit-field">
<input required type="text"
name="ExpirationDate"
data-type="date"
data-bind="value:ExpirationDate"
data-role="datepicker"
validationmessage="Expiration Date is required" />
</div>

Count items in datasource or inside repeater

I found some other questions about this argument but I can't get anything to work.
I have a repeater with datasource, this is my repeater code:
<div class="container dafareoggi" id="divDaFareOggi">
<div runat="server" id="divSegnaposto"></div>
<asp:Repeater runat="server" ID="rptDaFareOggi" DataSourceID="SqlAttivitaDaFareOggi">
<ItemTemplate>
<div id="<%# Eval("id") %>">
<div class="div-titolo" title="<%# Eval("Titolo") %>"><%# Eval("Titolo") %></div>
<div class="div-testo" title="<%# Eval("Note") %>"><%# Eval("Note") %></div>
<div>
<table style="width: 100%;margin-top:0.5em;padding-right:0.2em;">
<tr>
<td style="width: 50%; text-align: left;">
<asp:ImageButton runat="server" ImageUrl="~/images/gabri.png" Width="2.3em" Height="2.3em" ToolTip='<%#Eval("tecnico")%>' Enabled="false" Visible='<%# IIf(Eval("idutente") = 8, True, False) %>'/>
<asp:ImageButton runat="server" ImageUrl="~/images/giuse.png" Width="2.3em" Height="2.3em" ToolTip='<%#Eval("tecnico")%>' Enabled="false" Visible='<%# IIf(Eval("idutente") = 2, True, False) %>'/>
<asp:ImageButton runat="server" ImageUrl="~/images/robi.png" Width="2.3em" Height="2.3em" ToolTip='<%#Eval("tecnico")%>' Enabled="false" Visible='<%# IIf(Eval("idutente") = 5, True, False) %>'/>
</td>
<td style="width: 50%; text-align: right; ">
<asp:LinkButton CommandName="delAttivita" CommandArgument='<%#Eval("ID")%>' runat="server" ID="lnkDelAtt" CausesValidation="False" OnClientClick="return confirm('Sei sicuro di voler eliminare questa attivita?');"><i class="fa fa-trash fa-lg" title="Elimina attività"></i></asp:LinkButton>
<asp:LinkButton CommandName="editAttivita" CommandArgument='<%#Eval("ID")%>' runat="server" ID="lnkEditAtt"><i class="fa fa-pencil-square fa-lg" title="Modifica attività"></i></asp:LinkButton>
</td>
</tr>
</table>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
In the repeater there is a place card div with id divSegnaposto (2nd row) and then a bunch of div may be loaded accordingly to data read from the db.
What I want is that when there are no data to load, so divSegnaposto is the only item, to show it and, vice versa, when there are 1 ore more other divs, to hide it.
I figure that I should count the number of items inside the repeater or rows inside datasouce (I'm using EF), so I tried different approach in repeater_databound_event, but for example repeater.items.count is always 0.
How can I achieve the goal?
I ended up using a linq query that gets the same as the sqldatasource at itembound event and then I check if it's empty or not and show\hide the placecard accordingly. I don't like it too much because makes me mad: I already have all the information I need inside the repeater or the sql data source, so I guess I thought there was an easier, less code-consuming way to do it. But all the answers I found are more complicated than just re-do the query in code behind...

Images are not displaying in asp.net webforms

I have image links of a website's images stored in my DB but when I show them on my asp page using repeater or data list which im building, it shows some where pics and somewhere just boxes and no
image, can anyone help me?
here is my datalist code to show products but some images are being shown and some are like broken icons and empty box having no image, and i have image links of a website which i am displaying in
data list and i have checked all links as well on web they work perfectly fine but don't show anything in my data list web form,is this a styling issue or binding?
code of Data list is given below
<div style=" border:inset; margin-left:100px; display:inline-block;">
<asp:DataList ID="DataList1" runat="server" RepeatColumns="5" RepeatDirection="Horizontal">
<ItemTemplate>
<div class="span4" style="display:inline-block; border-top:1px; background-color:none;width:190px; height:440px; border:solid; border-width:1px; border-spacing:2px 4px; border-bottom:inset; border-top-width:1px;" runat="server"><br />
<div class="products" style="height:430px; width:189x; border:inset;border-style:none;border-spacing:2px 4px;">
<asp:Image ID="ImgId" runat="server" style=" height:160px; width:160px;" ImageUrl='<%#(DataBinder.Eval(Container.DataItem,"ImageLink")) %>' /> <br />
<h3 class="title" style="font-family:Pristina;font-size:medium;height:30px; margin-bottom:-15px;"> <b><%# Eval("Name") %></b><br /><br /><br /></h3>
<br />
<p class="price" style="font-family:Pristina;font-size:medium; height:30px;padding-top:40px; "><b>Price</b> <%# Eval("Price") %> <br /><br /><br /><br /><br /></p><br />
<br />
<b style="margin-bottom:-20px">www.shophive.com</b>
</div>
</div>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Top"/>
</asp:DataList>
</div>

<JSP> How to display one data from multiple row

I have a query that gives me 3 data under 1 parameter. Following is query.
Query
SELECT
VQ_CD
, FILE_NM
FROM
TB_POT_ECD_VQ_INFO
WHERE
PRCS_SNO = '1'
When I run the query, the data I get is..
PRCS_SNO VQ_CD FILE_NM
1 500K A
1 1000K B
1 2000K C
And in JSP page, I want to display all three data.
What I did in JSP is this.
Oh, table is being called encVqList.
JSP
<td class="typeFD bgN"">
<c:set var="V500K" value="" />
<c:forEach var="encVqList" items="${encVqList}" >
<input type="text" id="500K" name="500K" value="<c:out value="${encVqList.fileNm}" />"/>
</c:forEach>
<td class="typeFD bgN"">
<c:set var="V1000K" value="" />
<c:forEach var="encVqList" items="${encVqList}" >
<input type="text" id="1000K" name="1000K" value="<c:out value="${encVqList.fileNm}" />"/>
</c:forEach>
<td class="typeFD bgN"">
<c:set var="V2000K" value="" />
<c:forEach var="encVqList" items="${encVqList}" >
<input type="text" id="2000K" name="2000K" value="<c:out value="${encVqList.fileNm}" />"/>
</c:forEach>
And did the same thign for 1000K and 2000K. But it doesn't work.
I think I should distinguish each input box does not recognize which one since it has 3 data under 1 same parameter. So can anyone help?
<td class="typeFD bgN"">
<c:forEach var="encVqList" items="${encVqList}" >
<c:choose>
<c:when test="${encVqList.VQ_CD eq '500K'}">
<input type="text" id="500K" name="500K" value="<c:out value='${encVqList.fileNm}' />" />
</c:when>
<c:when test="${encVqList.VQ_CD eq 'V1000K'}">
<input type="text" id="1000K" name="1000K" value="<c:out value='${encVqList.fileNm}' />" />
</c:when>
<c:otherwise>
<input type="text" id="2000K" name="2000K" value="<c:out value='${encVqList.fileNm}' />" />
<c:otherwise>
</c:choose>
</c:forEach>
</td>

ModalPopupExtender: Dragging dialog box results in 'scrollleft is null or not an object' error

I am using the ModalPopupExtender control to display a modal popup dialog when a button is click. The problem is that dragging the dialog results in an 'scrollleft is null or not an object' error.
Here's a video demo
..and here is ALL the code:
If possible, I'd like to resolve this problem w/o resorting to modifying the AjaxToolkit scripts themselves.
<%# Page Language="VB" AutoEventWireup="false" CodeFile="MyModalSimple.aspx.vb" Inherits="MyModalSimple" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=70);
opacity: 0.7;
}
</style>
<link href="Default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function onOk() {
//form1.submit();
}
</script>
<script type="text/javascript">
var clientid;
function fnSetFocus(txtClientId) {
clientid = txtClientId;
setTimeout("fnFocus()", 1000);
}
function fnFocus() {
//debugger;
if (document.getElementById("pnlModal").style.display != "none")
eval("document.getElementById('" + clientid + "').focus()");
}
function fnClickOK(sender, e) {
__doPostBack(sender, e);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<br />
Clicking the button will bring up the modal dialog<br />
<br />
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<cc1:ModalPopupExtender ID="Button1_ModalPopupExtender" runat="server" TargetControlID="Button1"
PopupDragHandleControlID="programmaticPopupDragHandle" PopupControlID="pnlModal"
OkControlID="btnOK" CancelControlID="btnCancel" DropShadow="true" OnOkScript="onOk();"
BackgroundCssClass="modalBackground">
</cc1:ModalPopupExtender>
<br />
<asp:Panel ID="pnlModal" runat="server" Style="display: None" BackColor="#CCCCCC">
<asp:Panel runat="Server" ID="programmaticPopupDragHandle" Style="cursor: move; background-color: #DDDDDD;
border: solid 1px Gray; color: Black; text-align: center;">
Caption
</asp:Panel>
<br />
<table>
<tr>
<td>
<asp:Label ID="lblFirst" runat="server" Text="First"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtFirst" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblLast" runat="server" Text="Last"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtLast" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td align="right">
<asp:Button ID="btnOK" runat="server" Text="OK" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
<asp:Label ID="lblMessage" runat="server"></asp:Label>
<br />
<br />
</div>
</form>
</body>
</html>
Partial Class MyModalSimple
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Button1.Attributes.Add("onclick", "fnSetFocus('" + txtFirst.ClientID + "');")
btnOK.OnClientClick = String.Format("fnClickOK('{0}','{1}')", btnOK.UniqueID, "")
End If
End Sub
Protected Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
lblMessage.Text = "Hi, " & txtFirst.Text & " " & txtLast.Text
End Sub
End Class
Unfortunately this is a known bug in the DragPanelExtender. I would recommend dropping the modal extender all together if it's an option and you're comfortable with javascript.
With jQuery/jQuery UI for example, your page would look like:
<form id="form1" runat="server">
<br />
Clicking the button will bring up the modal dialog<br />
<br />
<div>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<div id="myModal" Style="display: None" background="#CCCCCC" title="Caption/Dialog Title">
<table>
<tr>
<td>
<asp:Label ID="lblFirst" runat="server" Text="First" />
</td>
<td>
<asp:TextBox ID="txtFirst" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblLast" runat="server" Text="Last" />
</td>
<td>
<asp:TextBox ID="txtLast" runat="server" />
</td>
</tr>
</table>
</div>
<asp:Label ID="lblMessage" runat="server"></asp:Label>
<br />
<br />
</div>
</form>
<script type="text/javascript">
$(function() {
$("#<%= Button1.ClientID %>").click() {
$("#myModal").dialog({ buttons: { "Ok": function() { $(this).dialog("close"); } } });
}
});
</script>
This is a whole different way of programming, but results in a much richer UI experience for the user. If you're willing to learn jQuery and how it hooks up, it's a really natural/fluid syntax that can add a great deal of power/flexibility to your web pages. Now keep in mind that I prefer jQuery but that there are many other javascript libraries available. You should at least browse around and see what looks the most comfortable if you're just getting started...it's possible since you're from a VB background (I'm from C#) that another libraries coding style/syntax is much more appealing.
Now if you're unwilling to go down that road and it's too unfamiliar, your only alternative as far as I can see is to do what you don't want to...compile the AJAX Control Toolkit yourself. If you want to go this route, grab the latest source from codeplex and modify the below section of Release\AjaxControlToolkit\Compat\DragDrop\DragDropScripts.js:
_drag: function(isInitialDrag) {
var ev = window._event;
var mousePosition = { x: ev.clientX, y: ev.clientY };
To this:
_drag: function(isInitialDrag) {
if (!this._activeDragVisual) return;
var ev = window._event;
var mousePosition = { x: ev.clientX, y: ev.clientY };
The _onScrollerTick operation in certain browsers bombs out and nulls the dragVisual function. Credit is due here: A post on the ASP.Net forums by freakyer led me down this debug path to figure out where it's breaking...but I see no other solution as there is an actual bug in certain browsers not-fixable without a script change and recompile.
I urge you to consider the jQuery/other framework path, there's a ton of community support and examples out there to help get you started. This question from a while back is worth a read if the framework options interest you at all.