how to hide table using wicket - wicket

I want to hide table based on conditions.I got error using this code.please help me to come out this error.
//IN Wicket :
<table class="jtrac jtrac-view" width="100%" wicket:id="request">
<tr>
<td ></td>
<td ></td>
</tr>
</table>
<table class="jtrac jtrac-view" width="100%" wicket:id="response">
<tr >
<td ></td>
<td ></td>
</tr>
</table>
I wrote java code like this.
WebMarkupContainer request = new WebMarkupContainer("request");
WebMarkupContainer response= new WebMarkupContainer("response");
add(request );
add(response);
if(time == null || time.equals("")) {
response.setVisible(false);
add(response);
}else {
request.setVisible(false);
add(request);
}

add(request());
add(response());
private WebMarkupContainer request() {
WebMarkupContainer r = new WebMarkupContainer("request") {
#Override
protected void onConfigure() {
super.onConfigure();
setVisible(StringUtils.isEmpty(time))
}
};
r.setOutputMarkupPlaceholderTag(true);
return r;
}
private WebMarkupContainer response() {
WebMarkupContainer r = new WebMarkupContainer("response") {
#Override
protected void onConfigure() {
super.onConfigure();
setVisible(StringUtils.isNotEmpty(time));
}
};
r.setOutputMarkupPlaceholderTag(true);
return r;
}
StringUtils is from Apache Commons: http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html

Related

Populating table with apache wicket

I need to dynamically poplulate a table like this. The problem is, it is not a simple table. It has the "rowspan" characteristics.
For a single entry there are multiple fields entries which are being stored in separate rows.
This is a little tricky to populate with Wicket. Any help , advises, suggestions would be great.
This is what the table looks like on the HTML page:
https://jsfiddle.net/sayrandhri/4ktmy6cn/2/
<table>
<tr>
<th>Name</th>
<th>Role</th>
<th>Company</th>
<th>Request</th>
<th>Change</th>
</tr>
<tr>
<td rowspan=2>ABC</td>
<td rowspan=2>User</td>
<td>Y</td>
<td>True</td>
<td>False</td>
</tr>
<tr>
<td>Telecom</td>
<td>True</td>
<td>False</td>
</tr>
<tr>
<td rowspan=3>XYZ </td>
<td rowspan=3>User</td>
<td>O </td>
<td>False</td>
<td>False</td>
</tr>
<tr>
<td>Q</td>
<td>True</td>
<td>True</td>
</tr>
<tr>
<td>R</td>
<td>False</td>
<td>False</td>
</tr>
</table>
You can try following approach:
HTML:
<table>
<tr>
<th>Name</th>
<th>Role</th>
<th>Company</th>
<th>Request</th>
<th>Change</th>
</tr>
<tbody wicket:id="userList">
<tr wicket:id="providerList">
<td wicket:id="userName"></td>
<td wicket:id="roleName"></td>
<td wicket:id="provider"></td>
<td wicket:id="request"></td>
<td wicket:id="change"></td>
</tr>
</tbody>
</table>
Java:
add(new ListView<User>("userList", new PropertyModel<>(this, "users")) {
#Override
protected void populateItem(ListItem<User> listItem) {
final User user = listItem.getModelObject();
listItem.add(new ListView<Provider>("providerList", user.getProviders()) {
#Override
protected void populateItem(ListItem<Provider> listItem) {
final Provider provider = listItem.getModelObject();
Label nameLabel = new Label("userName", user.getName());
Label roleNameLabel = new Label("roleName", user.getRoleName());
listItem.add(nameLabel);
listItem.add(roleNameLabel);
if (user.getProviders().indexOf(provider) == 0) {
AttributeAppender attributeAppender =
AttributeAppender.append("rowspan", user.getProviders().size());
nameLabel.add(attributeAppender);
roleNameLabel.add(attributeAppender);
} else {
nameLabel.setVisible(false);
roleNameLabel.setVisibilityAllowed(false);
}
listItem.add(new Label("provider", provider.getName()));
listItem.add(new Label("request", provider.isRequest()));
listItem.add(new Label("change", provider.isChange()));
}
});
}
});
Be advised that this way user without any providers wont show up on the list at all.
wicket:container solves this problem.
Your html file would look like this:
<wicket:container wicket:id="doubleRow">
<tr>
...
First Row components
...
</tr>
<tr>
...
Second Row components
...
</tr>
</wicket:container>
Assuming you are using a DataTable with Columns:
In the cell that spans several rows you set the rowspan Attribute with a Model. The value in that model will be increased as long as the value of that cell is not changing.
Once you detect a change in the content, you create a new Model with a rowspan value of 1 and assign that again to the current cell.
Something like this might do it, but I cannot test it at the moment:
private IModel<Integer> currentRowSpanModel = new Model<>(0);
...
new AbstractColumn<Object, String>(new Model<>("ColumnWithRowSpan")) {
#Override
public void populateItem(Item<ICellPopulator<Object>> cellItem, String componentId, IModel<Object> rowModel) {
if (/*Content of cell has changed compared to last row*/) {
// write the content to the cell and add the rowspan Attribute
cellItem.add(new Label(componentId, "Content"));
currentRowSpanModel = new Model<>(1);
cellItem.add(AttributeModifier.replace("rowspan", currentRowSpanModel));
} else {
// Hide cell with same content and instead increase rowspan
cellItem.add(new WebMarkupContainer(componentId));
cellItem.setVisible(false);
currentRowSpanModel.setObject(currentRowSpanModel.getObject()+1);
}
}
}

How to repeat a button in DataView

I can't get the button to appear on the page. Both of the labels appear fine just wondering how to get the button to show up too.
ListDataProvider listDataProvider = new ListDataProvider(users);
DataView dataView = new DataView<UserDetails>("row", listDataProvider) {
#Override
protected void populateItem(Item<UserDetails> item) {
UserDetails user = item.getModelObject();
RepeatingView repeatingView = new RepeatingView("dataRow");
repeatingView.add(new Label(repeatingView.newChildId(), user
.getUserName()));
repeatingView.add(new Label(repeatingView.newChildId(), user
.getAddress()));
repeatingView.add(new Button(repeatingView.newChildId()));
item.add(repeatingView);
}
};
dataView.setItemsPerPage(5);
add(dataView);
add(new PagingNavigator("pagingNavigator", dataView));
And my html is this:
<table>
<tr>
<th>Name</th><th>Address</th>
</tr>
<tr wicket:id = "row">
<td wicket:id="dataRow"></td>
</tr>
</table>
<div wicket:id="pagingNavigator"></div>

mvc ajax begin form and renderpartial validation open

ı am using a view in ajax begin form. ı search one thing and result is correct then alert not render the partial view. but it isnt render correct view a blank page and a see my partial view. thanks
my view
#using (Ajax.BeginForm("AjazKullanici", new AjaxOptions { UpdateTargetId = "trBilgiler", HttpMethod = "Post" }))
{
<tr>
<td style="width: 20%">
T.C. Kimlik No :
</td>
<th align="left">
#Html.TextBoxFor(model => model.TcNo)
#Html.ValidationMessageFor(model => model.TcNo)
<input type="submit" id="btnBilgiGetir" value="Bilgi Getir" class="Button" width="75px" />
</th>
</tr>
}
<tr id="trBilgiler">
#{Html.RenderPartial("BilgilerKullanici");}
</tr>
my controller
public ActionResult AjazKullanici()
{
ViewData["dropGizliSoru"] = _db.EHASTANEGIZLISORUs;
return View();
}
[HttpPost]
public PartialViewResult AjazKullanici(YeniKullaniciModel model)
{
if (model.TcNo != null)
{
var userKontrol = _db.KULLANICIBILGILERIs.Where(x => x.KULLANICIKOD == model.TcNo);
if (userKontrol.Any())
{
Response.Write("<script langauge='javascript'>alert('Girmiş Olduğunuz T.C. Kimlik Numarasına Ait Kullanıcı Kaydı Vardır.')</script>");
return PartialView();
}
else
{
return PartialView("BilgilerKullanici",model);
}
}
return PartialView();
}

ASP.NET Entity Framework Update Data

Referring to the following tutorial: ADO.NET Entity Framework Tutorial and Basics
I am trying to create the same code using a WEB application. I am able to fetch information, however my update button event doesn't save the changes. The CurrentPayroll object is null for some reason when the update button is pressed. I do select different Authors which sets the CurrentPayroll object. I tried using sessions, but that also does not work.
Here is the code:
PayrollView.aspx
<%# Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="PayrollView.aspx.cs" Inherits="SodiumHydroxide.Public.PayrollView" %>
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<table class="style1">
<tr>
<td class="style2">
Author
</td>
<td>
<asp:DropDownList ID="ddAuthor" runat="server" OnSelectedIndexChanged="ddAuthor_SelectedIndexChanged"
AutoPostBack="true" ViewStateMode="Enabled">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style2">
PayrollID
</td>
<td>
<asp:Label ID="lblPayRollID" runat="server" Text="000"></asp:Label>
</td>
</tr>
<tr>
<td class="style2">
Salary
</td>
<td>
<asp:TextBox ID="txtSalary" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2" colspan="2">
<asp:Button ID="btnFirst" runat="server" Text="<<" />
<asp:Button ID="btnPrevious" runat="server" Text="<" />
<asp:Button ID="btnNext" runat="server" Text=">" />
<asp:Button ID="btnLast" runat="server" Text=">>" />
</td>
</tr>
<tr>
<td class="style2" colspan="2">
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
<asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" />
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_Click" />
<asp:Label ID="lblFeedback" runat="server" ForeColor="Red"></asp:Label>
</td>
</tr>
</table>
</asp:Content>
PayrollView.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Objects;
namespace SodiumHydroxide.Public
{
public partial class PayrollView : System.Web.UI.Page
{
PublishingCompanyEntities publishContext;
Payroll CurrentPayroll;
protected void Page_Load(object sender, EventArgs e)
{
publishContext = new PublishingCompanyEntities();
if (!Page.IsPostBack)
{
try
{
this.ddAuthor.DataSource = publishContext.Author;
this.ddAuthor.DataTextField = "FirstName";
this.ddAuthor.DataValueField = "AuthorID";
this.ddAuthor.DataBind();
}
catch (ObjectDisposedException)
{
}
} // if (!Page.IsPostBack)
}
protected void ddAuthor_SelectedIndexChanged(object sender, EventArgs e)
{
int Selected = 0;
try
{
Selected = Convert.ToInt32(this.ddAuthor.SelectedItem.Value);
}
catch (InvalidCastException) { }
if (Selected > 0)
{
Author Authors = new Author();
Authors.AuthorID = Selected;
//Uses Linq-to-Entities
IQueryable<Payroll> payrollQuery =
from p in publishContext.Payroll
where p.Author.AuthorID == Authors.AuthorID
select p;
List<Payroll> SelectedPayroll = payrollQuery.ToList();
if (SelectedPayroll != null && SelectedPayroll.Count > 0)
{
CurrentPayroll = SelectedPayroll.First();
Session["CurrentPayroll"] = CurrentPayroll;
}
else
{
CurrentPayroll = null;
Session["CurrentPayroll"] = CurrentPayroll;
}
}
PopulateFields();
this.lblFeedback.Text = "ddAuthor_SelectedIndexChanged " + Selected.ToString();
}
private void PopulateFields()
{
if (CurrentPayroll != null)
{
this.lblPayRollID.Text = CurrentPayroll.PayrollID.ToString();
this.txtSalary.Text = CurrentPayroll.Salary.ToString();
this.btnAdd.Enabled = false;
this.btnDelete.Enabled = true;
this.btnUpdate.Enabled = true;
}
else
{
this.lblPayRollID.Text = "Not on payroll";
this.txtSalary.Text = "0";
this.btnAdd.Enabled = true;
this.btnDelete.Enabled = false;
this.btnUpdate.Enabled = false;
}
}
protected override void OnUnload(EventArgs e)
{
base.OnUnload(e);
}
protected void btnAdd_Click(object sender, EventArgs e)
{
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
// Payroll UpdatePayroll = (Payroll)Session["CurrentPayroll"];
CurrentPayroll.Salary = Convert.ToInt32(this.txtSalary.Text);
publishContext.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
}
protected void btnDelete_Click(object sender, EventArgs e)
{
}
}
}
Managed to sort it out. You need to detach the Payroll object. Create a new context, then attach the stored object to the new context.
publishContext.Detach(CurrentPayroll);
Here is the updated event:
protected void btnUpdate_Click(object sender, EventArgs e)
{
Payroll StoredPayroll = (Payroll)Session["CurrentPayroll"];
PublishingCompanyEntities UpdateContext = new PublishingCompanyEntities();
UpdateContext.Attach(StoredPayroll);
StoredPayroll.Salary = Convert.ToInt32(this.txtSalary.Text);
int AffectedRows = UpdateContext.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
this.lblFeedback.Text = "Affected Rows: " + AffectedRows.ToString();
}

GWT: uiBinder-based widget cant be instanced second time

I created a widget using GWT uiBinder. It works fine, till the moment when I want to instance it second time. After i call constructor second time it returns only raw description from XML and statements in constructor (rootElement.add( new HTML( "panel1" ), leftId );) are just don't work. It throws no error or warning.
Please help
Java class:
public class DashboardLayout extends Composite {
final String leftId = "boxLeft";
final String rightId = "boxRight";
interface DashboardLayoutUiBinder extends UiBinder<HTMLPanel, DashboardLayout> {
}
private static DashboardLayoutUiBinder ourUiBinder = GWT.create( DashboardLayoutUiBinder.class );
#UiField
HTMLPanel htmlPanel;
public DashboardLayout() {
HTMLPanel rootElement = ourUiBinder.createAndBindUi( this );
this.initWidget( rootElement );
rootElement.add( new HTML( "panel1" ), leftId );
rootElement.add( new HTML( "panel2" ), rightId );
}
}
XML descriprion:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'
>
<g:HTMLPanel ui:field="htmlPanel">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="40%" id="boxLeft" class="boxContextLeft">
</td>
<td width="60%" id="boxRight" class="boxContextRight">
</td>
</tr>
</table>
</g:HTMLPanel>
</ui:UiBinder>
Don't use id="myid" in widgets, as they will be global(which will screw you up) instead of scoped per instantiation of the widget; use ui:field="myid" and then create a corresponding UiField variable in the java class. This will allow the gwt compiler to obfuscate the id's so you don't get collisions between instantiations of the same widget.
DashboardLayout.java
public class DashboardLayout extends Composite {
interface DashboardLayoutUiBinder extends
UiBinder<HTMLPanel, DashboardLayout> {
}
private static DashboardLayoutUiBinder ourUiBinder = GWT
.create(DashboardLayoutUiBinder.class);
#UiField
HTMLPanel htmlPanel;
#UiField
HTML panel1;
#UiField
HTML panel2;
public DashboardLayout() {
HTMLPanel rootElement = ourUiBinder.createAndBindUi(this);
this.initWidget(rootElement);
// do stuff with panel1
panel1.setHTML("<blink>blink</blink>");
// do stuff with panel2
panel2.setHTML("<marquee>marquee</marquee>");
}
}
DashboardLayout.ui.xml
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:g='urn:import:com.google.gwt.user.client.ui'>
<g:HTMLPanel ui:field="htmlPanel">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="40%" class="boxContextLeft">
<g:HTML ui:field="panel1"></g:HTML>
</td>
<td width="60%" class="boxContextRight">
<g:HTML ui:field="panel2"></g:HTML>
</td>
</tr>
</table>
</g:HTMLPanel>
</ui:UiBinder>