I am lost on this MVC project I am working on. I also read Brad Wilsons article.
http://bradwilson.typepad.com/blog/2010/01/input-validation-vs-model-validation-in-aspnet-mvc.html
I have this:
public class Employee
{
[Required]
public int ID { get; set; }
[Required]
public string FirstName { get; set; }
[Required]
public string LastName { get; set; }
}
and these in a controller:
public ActionResult Edit(int id)
{
var emp = GetEmployee();
return View(emp);
}
[HttpPost]
public ActionResult Edit(int id, Employee empBack)
{
var emp = GetEmployee();
if (TryUpdateModel(emp,new string[] { "LastName"})) {
Response.Write("success");
}
return View(emp);
}
public Employee GetEmployee()
{
return new Employee {
FirstName = "Tom",
LastName = "Jim",
ID = 3
};
}
and my view has the following:
<% using (Html.BeginForm()) {%>
<%= Html.ValidationSummary() %>
<fieldset>
<legend>Fields</legend>
<div class="editor-label">
<%= Html.LabelFor(model => model.FirstName) %>
</div>
<div class="editor-field">
<%= Html.DisplayFor(model => model.FirstName) %>
</div>
<div class="editor-label">
<%= Html.LabelFor(model => model.LastName) %>
</div>
<div class="editor-field">
<%= Html.TextBoxOrLabelFor(model => model.LastName, true)%>
<%= Html.ValidationMessageFor(model => model.LastName) %>
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
<% } %>
Note that the only field editable is the LastName. When I postback, I get back the original employee and try to update it with only the LastName property. But but I see on the page is the following error:
•The FirstName field is required.
This from what I understand, is because the TryUpdateModel failed. But why? I told it to update only the LastName property.
I am using MVC2 RTM
Thanks in advance.
I'm trying to use Dojo (1.3) checkBoxes to make columns appear/hide in a Dojo Grid that's displayed below the checkBoxes. I got that functionality to work fine, but I wanted to organize my checkBoxes a little better. So I tried putting them in a table. My dojo.addOnLoad function looks like this:
dojo.addOnLoad(function(){
var checkBoxes = [];
var container = dojo.byId('checkBoxContainer');
var table = dojo.doc.createElement("table");
var row1= dojo.doc.createElement("tr");
var row2= dojo.doc.createElement("tr");
var row3= dojo.doc.createElement("tr");
dojo.forEach(grid.layout.cells, function(cell, index){
//Add a new "td" element to one of the three rows
});
dojo.place(addRow, table);
dojo.place(removeRow, table);
dojo.place(findReplaceRow, table);
dojo.place(table, container);
});
What's frustrating is:
1) Using the Dojo debugger I can see that the HTML is being properly generated for the table.
2) I can take that HTML and put just the table in an empty HTML file and it renders the checkBoxes in the table just fine.
3) The page renders correctly in Firefox, just not IE6.
The HTML that is being generated looks like so:
<div id="checkBoxContainer">
<table>
<tr>
<td>
<div class="dijitReset dijitInline dijitCheckBox"
role="presentation" widgetid="dijit_form_CheckBox_0"
wairole="presentation">
<input class="dijitReset dijitCheckBoxInput"
id="dijit_form_CheckBox_0"
tabindex="0" type="checkbox"
name="" dojoattachevent=
"onmouseover:_onMouse,onmouseout:_onMouse,onclick:_onClick"
dojoattachpoint="focusNode" unselectable="on"
aria-pressed="false"/>
</div>
<label for="dijit_form_CheckBox_0">
Column 1
</label>
</td>
<td>
<div class="dijitReset dijitInline dijitCheckBox"
role="presentation" widgetid="dijit_form_CheckBox_1"
wairole="presentation">
<input class="dijitReset dijitCheckBoxInput"
id="dijit_form_CheckBox_1"
tabindex="0" type="checkbox"
name="" dojoattachevent=
"onmouseover:_onMouse,onmouseout:_onMouse,onclick:_onClick"
dojoattachpoint="focusNode" unselectable="on"
aria-pressed="false"/>
</div>
</td>
</tr>
<tr>
...
</tr>
</table>
</div>
I would have posted to the official DOJO forums, but it says they're deprecated and they're using a mailing list now. They said if a mailing list doesn't work for you, use stackoverflos.com. So, here I am! Thanks for any insight you can provide.
I'm gonna create a ListView in WPF like the below image
http://www.picfront.org/d/7xuv
I mean I wanna add an image beside of Gravatar label within Name column.
Would it be OK if you guided me ?
I have an ASP.net page which contains some controls.
I generate this controls by code, [Actually I have a method which uses a stringBuilder and add Serverside tag as flat string on it]
My page shows the content correctly but unfortunately my controls became like a Client-side control
For example I had a LoginView on my generated code which dosen't work, and also I had read some string from LocalResources which dosen't appear on the page
What Should I do to make my generating method correct
here is the code
protected string CreateSubSystem(string id, string roles, string AnonymousTemplateClass, string href, string rolesContentTemplateClass, string LoggedInTemplateClass)
{
StringBuilder sb = new StringBuilder();
sb.Append("<div class=\"SubSystemIconPlacement\" id=\"");
sb.Append(id);
sb.Append("\"><asp:LoginView runat=\"server\" ID=\"");
sb.Append(id);
sb.Append("\"><AnonymousTemplate><div class=\"");
sb.Append(AnonymousTemplateClass);
sb.Append("\"></div><asp:Label ID=\"lblDisabled");
sb.Append(id);
sb.Append("\" runat=\"server\" SkinID=\"OneColLabel\" meta:resourcekey=\"lbl");
sb.Append(id);
sb.Append("\" /></AnonymousTemplate><RoleGroups><asp:RoleGroup Roles=\"");
sb.Append(roles);
sb.Append("\"><ContentTemplate><a class=\"ImageLink\" href=\"");
sb.Append(href);
sb.Append("\"><div class=\"");
sb.Append(rolesContentTemplateClass);
sb.Append("\"></div></a><asp:HyperLink runat=\"server\" CssClass=\"SubSystemText\" ID=\"lnk");
sb.Append(id);
sb.Append(" NavigateUrl=\"~/");
sb.Append(href);
sb.Append(" \" meta:resourcekey=\"lbl");
sb.Append(id);
sb.Append("\" /></ContentTemplate></asp:RoleGroup></RoleGroups><LoggedInTemplate><div class=\"");
sb.Append(LoggedInTemplateClass);
sb.Append("\"></div><asp:Label runat=\"server\" SkinID=\"OneColLabel\" ID=\"lblDisabledLoggedIn");
sb.Append(id);
sb.Append("\" meta:resourcekey=\"lbl");
sb.Append(id);
sb.Append("\" /></LoggedInTemplate></asp:LoginView>");
sb.Append("</div>");
return sb.ToString();
}
I also use this method on page_PreRender event
I have just changed a compiler option from 4.0 to 4.2.
Now I get an error:
jump to case label crosses initialization of 'const char* selectorName'
It works fine in 4.0
Any ideas?
I'm not being able to make this line work with Tk
import os
while(1):
ping = os.popen('ping www.google.com -n 1')
result = ping.readlines()
msLine = result[-1].strip()
print msLine.split(' = ')[-1]
I'm trying to create a label and text = msLine.split... but everything freezes
I am stuck on how to create tags for each post on my site. I am not sure how to add the tags into database.
Currently...
I have 3 tables:
+---------------------+ +--------------------+ +---------------------+
| Tags | | Posting | | PostingTags |
+---------------------+ +--------------------+ +---------------------+
| + TagID | | + posting_id | | + posting_id |
+---------------------+ +--------------------+ +---------------------+
| + TagName | | + title | | + tagid |
+---------------------+ +--------------------+ +---------------------+
The Tags table is just the name of the tags(ex: 1 PHP, 2 MySQL,3 HTML)
The posting (ex: 1 What is PHP?, 2 What is CSS?, 3 What is HTML?)
The postingtags shows the relation between posting and tags.
When users type a posting, I insert the data into the "posting" table. It automatically inserts the posting_id for each post(posting_id is a primary key).
$title = mysqli_real_escape_string($dbc, trim($_POST['title']));
$query4 = "INSERT INTO posting (title) VALUES ('$title')";
mysqli_query($dbc, $query4);
HOWEVER, how do I insert the tags for each post?
When users are filling out the form, there is a checkbox area for all the tags available and they check off whatever tags they want. (I am not doing where users type in the tags they want just yet)
This shows each tag with a checkbox. When users check off each tag, it gets stored in an array called "postingtag[]".
<label class="styled">Select Tags:</label>
<?php
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query5 = "SELECT * FROM tags ORDER BY tagname";
$data5 = mysqli_query($dbc, $query5);
while ($row5 = mysqli_fetch_array($data5)) {
echo '<li><input type="checkbox" name="postingtag[]"
value="'.$row5['tagname'].'" ">'.$row5['tagname'].'</li>';
}
?>
My question is how do I insert the tags in the array ("postingtag") into my "postingtags" table?
Should I...
$postingtag = $_POST["postingtag"];
foreach($postingtag as $value){
$query5 = "INSERT INTO postingtags (posting_id, tagID)
VALUES (____, $value)";
mysqli_query($dbc, $query5);
}
1.In this query, how do I get the posting_id value of the post?
I am stuck on the logic here, so if someone can help me explain the next step, I would appreciate it!
Is there an easier way to insert tags?
I have a UITableView with cells containing variable-height UILabels. I am able to calculate the minimum height the label needs to be using sizeWithFont:constrainedToSize:lineBreakMode:, which works fine when the table view is first loaded. When I rotate the table view the cells become wider (meaning there are fewer lines required to display the content). Is there any way I can have the height of the cells redetermined by the UITableView during the orientation change animation or immediately before or after? Thank you.
I know soft shadows are not supported by the UILabel our of the box, on the iPhone. So what would be the best way to implement my own one?
EDIT: Obviously I will subclass the UILabel and draw in the -drawRect:
My question is, how do I get the contents of the label as graphics and draw around them, blur them etc...
Hi,
I need to read a complex model in an ordered way with eclipselink. The order is mandantory because it is a huge database and I want to have an output of a small portion of the database in a jface tableview. Trying to reorder it in the loading/quering thread takes too long and ordering it in the LabelProvider blocks the UI thread too much time, so I thought if Eclipselink could be used that way, that the database will order it, it might give me the performance I need. Unfortunately the object model can not be changed :-(
The model is something like:
@SuppressWarnings("serial")
@Entity
public class Thing implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private int id;
private String name;
@OneToMany(cascade=CascadeType.ALL)
@PrivateOwned
private List<Property> properties = new ArrayList<Property>();
...
// getter and setter following here
}
public class Property implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private int id;
@OneToOne
private Item item;
private String value;
...
// getter and setter following here
}
public class Item implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private int id;
private String name;
....
// getter and setter following here
}
// Code end
In the table view the y-axis is more or less created with the query
Query q = em.createQuery("SELECT m FROM Thing m ORDER BY m.name ASC");
using the "name" attribute from the Thing objects as label.
In the table view the x-axis is more or less created with the query
Query q = em.createQuery("SELECT m FROM Item m ORDER BY m.name ASC");
using the "name" attribute from the Item objects as label.
Each cell has the value
Things.getProperties().get[x].getValue()
Unfortunately the list "properties" is not ordered, so the combination of cell value and x-axis column number (x) is not necessarily correct. Therefore I need to order the list "properties" in the same way as I ordered the labeling of the x-axis.
And exactly this is the thing I dont know how it is done. So querying for the Thing objects should return the list "properties" "ORDER BY name ASC" but of the "Item"s objects. My ideas are something like having a query with two JOINs. Joing Things with Property and with Item but somehow I was unable to get it to work yet.
Thank you for your help and your ideas to solve this riddle.
I am using listview in tabwidget tab1 when my focus is on "Tab label" and i press arrow keys or track ball to go down focus directly jumps to the 5th row in the listview.
any idea whats going wrong ?
I have a reciever that works well, but I can't seem to show a proper UI, although the toast appears correctly. As far as I can tell, this is caused by Android requiring the class to extend Activity, however, the class already extends BroadcastReciever, so I can't do this.
So, I tried to do an Intent, but this failed too. There are no errors, but the screen doesn't show. Source code is below, and any help would be most appreciated.
Reciever
public class Reciever extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Alarm Recieved", Toast.LENGTH_LONG).show();
Intent i = new Intent();
i.setClass(context, AlarmRing.class);
}
}
AlarmRing
public class AlarmRing extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alarm);
MediaPlayer mp = MediaPlayer.create(getBaseContext(), R.raw.sweetchild);
mp.start();
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.comaad.andyroidalarm"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AndyRoidAlarm"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.comaad.andyroidalarm.Reciever" android:enabled="true">
<intent-filter>
<action android:name="com.comaad.andyroidalarm.Reciever"></action>
</intent-filter>
</receiver>
<activity android:name=".AlarmRing"></activity>
</application>
</manifest>
}
How can one move a label around in the hello world example using the on_mouse_motion function?
The docs aren't clicking for me.
on_mouse-motion
hello_world_example.py
Hi,
I have a UILabel tha contains a URL (ie www.google.com). Is there a way to display the label as URL so the User can tap on the URL for Safari to open it?
Same question I have for a mailto item (ie [email protected]) to open mail with a new email to that address
thanks in advance
Hi,
I have a flex datagrid with 4 columns.I have a comboBox with 4 checkboxes,containing the column names of datagrid as its label.I want the datagrid to display only those columns which are selected in combobox.Can anyone tell me how this filtering of columns in datagrid can be done?
Thanks in advance.
I'm working on using Find/Replace to change a bunch of labels to DataBound text.
Here's my regex
<asp:Label ID="lbl{\d*}" runat="server" />
Here's my replace
<%# Eval("\1")%>
Here's my Error
Unknown argument for ':' operator. Complete Regular Expression required in the search string.
How would I resolve this?
I'm trying to mimic the default emboss that automatically gets applied to navigationItem.title, as well as many other UIKit controls.
As seen in this screenshot's title ("Table Cells"):
I'm essentially trying to add 2 UILabels to the navigationItem.titleView, however the UILabels just show up as flatly drawn and it really just doesn't feel/look right :P
I've thought about playing with shadows, but that would only give the embossed look (if even that) on one side of the label.
Any ideas would be great!
Thanks
Hello,
I want to add a title to my graph that gives a short description or name about the plot. For example, I have a table with a list of products and my graph shows how much those products cost. There should be a label/annotation superimposed on the graph that gives the name of the product.
Hi, I am trying to convert some Perl into PHP using this guideline:
http://www.cs.wcupa.edu/~rkline/perl2php/#basedir
Basically I know next to nothing about these two languages. Please give me some simple English explanation of what each line does, I'll be more than happy. Thanks for reading :D
Perl CGI program:
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI ();
my %fruit_codes = (
apple => '2321.html',
banana => '1234.html',
coconut => '8889.html',
);
my $c = CGI->new;
my $fruit_parameter = $c->param('fruit_name');
my $iframe_document;
if (defined $fruit_parameter and exists $fruit_codes{$fruit_parameter}) {
$iframe_document = $fruit_codes{$fruit_parameter};
} else {
$iframe_document = 'sorry-no-such-fruit.html';
}
$c->header('application/xhtml+xml');
print <<"END_OF_HTML";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Fruits</title>
</head>
<body>
<form action="fruits.cgi">
<fieldset>
<label for="fruit">Name of the fruit:</label>
<input id="fruit" name="fruit_name" type="text" />
<input type="submit" />
</fieldset>
</form>
<iframe src="$iframe_document">
<a href="$iframe_document">resulting fruit</a>
</iframe>
</body>
</html>
END_OF_HTML
1;
I've got a problem using an ISQLQuery with an AddJoin. The entity I'm trying to return is RegionalFees, which has a composite-id which includes a Province instance. (This is the the instance being improperly loaded.)
Here's the mapping:
<class name="Project.RegionalFees, Project" table="tblRegionalFees">
<composite-id name="Id"
class="Project.RegionalFeesId, project"
unsaved-value="any" access="property">
<key-many-to-one class="Project.Province, Project"
name="Region" access="property" column="provinceId" not-found="exception" />
<key-property name="StartDate" access="property" column="startDate" type="DateTime" />
</composite-id>
<property name="SomeFee" column="someFee" type="Decimal" />
<property name="SomeOtherFee" column="someOtherFee" type="Decimal" />
<!-- Other unrelated stuff -->
</class>
<class name="Project.Province, Project" table="trefProvince" mutable="false">
<id name="Id" column="provinceId" type="Int64" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Code" column="code" access="nosetter.pascalcase-m-underscore" />
<property name="Label" column="label" access="nosetter.pascalcase-m-underscore" />
</class>
Here's my query method:
public IEnumerable<RegionalFees> GetRegionalFees()
{
// Using an ISQLQuery cause there doesn't appear to be an equivalent of
// the SQL HAVING clause, which would be optimal for loading this set
const String qryStr =
"SELECT * " +
"FROM tblRegionalFees INNER JOIN trefProvince " +
"ON tblRegionalFees.provinceId=trefProvince.provinceId " +
"WHERE EXISTS ( " +
"SELECT provinceId, MAX(startDate) AS MostRecentFeesDate " +
"FROM tblRegionalFees InnerRF " +
"WHERE tblRegionalFees.provinceId=InnerRF.provinceId " +
"AND startDate <= ? " +
"GROUP BY provinceId " +
"HAVING tblRegionalFees.startDate=MAX(startDate))";
var qry = NHibernateSessionManager.Instance.GetSession().CreateSQLQuery(qryStr);
qry.SetDateTime(0, DateTime.Now);
qry.AddEntity("RegFees", typeof(RegionalFees));
qry.AddJoin("Region", "RegFees.Id.Region");
return qry.List<RegionalFees>();
}
The odd behavior here is that when I call GetRegionalFees (whose goal is to load just the most recent fee instances per region), it all loads fine if the Province instance is a proxy. If, however, Province is not loaded as a transparent proxy, the Province instance which is part of RegionalFees' RegionalFeesId property has null Code and Region values, although the Id value is set correctly.
It looks to me like I have a problem in how I'm joining the Province class - since if it's lazy loaded the id is set from tblRegionalFees, and it gets loaded independently afterwards - but I haven't been able to figure out the solution.
I have worked with globalization settings in the past but not within the .NET environment, which is the topic of this question. What I am seeing is most certainly due to knowledge I have yet to learn so I would appreciate illumination on the following.
Setup:
My default language setting is English (en-us specifically). I added a second language (Danish) on my development system (WinXP) and then opened the language bar so I could select either at will.
I selected Danish on the language bar then opened Notepad and found the language reverted to English on the language bar. I understand that the language setting is per application, so it seemed that Notepad set the default back to English. (I found that strange since Windows and thus Notepad is used all over the world.) Closing Notepad returned the setting on the language bar to Danish. I then launched my open custom WinForm application--which I know does not set the language--and it also reverted from English to Danish when opened, then back to Danish when terminated!
Question #1A: How do I get my WinForm application upon launch to inherit the current setting of the language bar? My experiment seems to indicate that each application starts with the system default and requires the user to manually change it once the app is running--this would seem to be a major inconvenience for anyone that wants to work with more than one language!
Question #1B: If one must, in fact, set the language manually in a multi-language scenario, how do I change my default system language (e.g. to Danish) so I can test my app's launch in another language?
I added a display of the current language in my application for this next experiment. Specifically I set a MouseEnter handler on a label that set its tooltip to CultureInfo.CurrentCulture.Name so each time I mouse over I thought I should see the current language setting. Since setting the language before I launch my app did not work, I launched it then set the language to Danish. I found that some things (like typing in a TextBox) did honor this Danish setting. But mousing over the instrumented label still showed en-us!
Question #2A: Why does CultureInfo.CurrentCulture.Name not reflect the change from my language bar while other parts of my app seem to recognize the change? (Trying CultureInfo.CurrentUICulture.Name produced the same result.)
Question #2B: Is there an event that fires upon changes on the language bar so I could recognize within my app when the language setting changes?
Hi,
I am having a requirement, where I need to have a pie-chart, i need text around pie-chart , the text should be a hyperlink.
Ex: we have 3 three fields A,B,C. A's ratio is 30%, B's ratio is 40%, c's ratio is 30%
So pie chart gets divided into 3 parts, outside the graph , we should get the label A(in A's area only), when we point on , tool tip should say
"A's ratio is 30 %'.
I am working in .Net 3.5, VS 2008, using MS chart control(added explicitly by executing MSChart.exe.
Thanks in Advance
Ram
I'm writing a slideshow program with Tkinter, but I don't know how to change the background color to black instead of the standard light gray. How can this be done?
import os, sys
import Tkinter
import Image, ImageTk
import time
root = Tkinter.Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.overrideredirect(1)
root.geometry("%dx%d+0+0" % (w, h))
root.focus_set()
root.bind("<Escape>", lambda e: e.widget.quit())
image = Image.open(image_path+f)
tkpi = ImageTk.PhotoImage(image)
label_image = Tkinter.Label(root, image=tkpi)
label_image.place(x=0,y=0,width=w,height=h)
root.mainloop(0)