I'm trying to create a custom route like:search/result/city/p1/state/p2/zip/p3/min/p4/max/p5/bed/p6/bath/p7/cats/p8/dogs/p9/parking/p10 Where search is the controller and result the action p1-p10 are variables.
In Asp.Net MVC 2.0, at least in the beta, you could decoration your model classes with data annotation attributes and enable client side validation that leverages that criteria defined in your model data annotation attibutes. Is there anything similar for Java Spring MVC 3.0?
Is it possible to inject a component into the response pipeline that can inspect the model's annotated properties and render client side validation logic to complement the server side validation logic that is invoked prior to the controller handling the request?
Im facing problem when trying to apply data annotation. In my case im passing FormCollection in controller
[HttpPost]
public ActionResult Create(string Button, FormCollection collection)
{
if (ModelState.IsValid)
{
}
else
{
}
}
and in ModelState.IsValid condition always have true value. Although i have left some blank fields in View. Also EnableClientValidation() is also applied in View for client side validation but its not working. what may be the problem
Hi,
I am passing the email address as part of the url,
for ex. http://example.com/hello/[email protected]
but, when being passed to the application controller it is changed to " user%40hotmail.com ".
I can't seem to understand this special character escaping; confusion.
please help me explain the problem here, and also what can I do to fix it.
I am using python's "webapp" web application framework.
Is it possible to have an ASP.NET MVC route that uses subdomain information to determine its route? For example:
user1.domain.com goes to one place
user2.domain.com goes to another?
Or, can I make it so both of these go to the same controller/action with a username parameter?
I'm trying to understand Rails from the ground up. I want to learn how to manually create basic show-all/show-single/CRUD functionality in the framework.
I currently am working on the display-all functionality, but am stopped by an error when I try to request all items in the Products db
Here are the steps I've taken so far:
script/generate controller Products
script/generate model Products
rake db:migrate
modified products_controller.rb to add: def index() { @products = Product.all}
(error: uninitialized constant ProductsController::Product)
ideally, dump all orders in the view
What's the fix?
I am using zend. I am redirecting from one page to another by following method.
$this-_redirect('/module/controller/action');
But above method does not update my browser's address bar with new page URL. I want to change browser's address bar also when I redirect to another page.
Thanks.
Is it a leak if I have a view controller and allocate the view like this:
self.view = [[UIView alloc] initWithFrame:frame];
Do I need to do something like this:
UIView *v = [[UIView alloc] initWithFrame:frame];
self.view = v;
[v release];
I am new to CakePHP and want an admin panel on my custom CMS for a client. Is there any way other than just linking to an admin page to each controller that I can pull views from other controllers such as users and posts?
Hi, i'm a newbie to iphone development. I'm doing a navigation-based app, and I'm having trouble passing values to a new view.
@interface RootViewController : UITableViewController {
NSString *imgurl;
NSMutableArray *galleryArray;
}
@property (nonatomic, retain) NSString *imgurl;
@property (nonatomic, retain) NSMutableArray *galleryArray;
- (void)showAll;
@end
#import "RootViewController.h"
#import "ScrollView.h"
#import "Model.h"
#import "JSON/JSON.h"
@implementation RootViewController
@synthesize galleryArray, imgurl;
- (void)viewDidLoad {
UIBarButtonItem *showButton = [[[UIBarButtonItem alloc]
initWithTitle:NSLocalizedString(@"Show All", @"")
style:UIBarButtonItemStyleBordered
target:self
action:@selector(showAll)] autorelease];
self.navigationItem.rightBarButtonItem = showButton;
NSString *jsonString = [[Model sharedInstance] jsonFromURLString:@"http://www.ddbstaging.com/gerald/gallery.php"];
NSDictionary *resultDictionary = [jsonString JSONValue];
if (resultDictionary == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Webservice Down"
message:@"The webservice you are accessing is currently down. Please try again later."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
else {
galleryArray = [[NSMutableArray alloc] init];
galleryArray = [resultDictionary valueForKey:@"gallery"];
imgurl = (NSString *)[galleryArray objectAtIndex:0];
NSLog(@" -> %@", galleryArray);
NSLog(imgurl);
}
}
- (void)showAll {
NSLog(@" -> %@", galleryArray);
NSLog(imgurl);
ScrollView *controller = [[ScrollView alloc] initWithJSON:galleryArray];
[self.navigationController pushViewController:controller animated:YES];
}
The RootViewController startup and the json data loads up fine. I can see it from the first console trace. However, once I click on the Show All button, the app crashes. It doesn't even trace the galleryArray and imgurl properyly.
Maybe additional pairs of eyes can spot my mistakes. Any help is greatly appreciated!
[Session started at 2010-05-08 16:16:07 +0800.]
2010-05-08 16:16:07.242 Photos[5892:20b] -> (
)
GNU gdb 6.3.50-20050815 (Apple version gdb-967) (Tue Jul 14 02:11:58 UTC 2009)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 5892.
(gdb)
I receive an error when I change pages if I am impersonated as another user in Symfony2. It only happens when the route has additional parameters. There is no sign of route generation at the pointed line number.
Controller action
/**
* @Route("/member/{id}", name="member_page")
* @Template()
*/
public function memberAction($id)
Error
An exception has been thrown during the rendering of a template ("Some mandatory parameters are missing ("slug") to generate a URL for route "member_page".") in members.html.twig at line 2.
I'm trying to make this 2-player web game application using Spring MVC. I have session-scoped beans Player and application-scoped bean GameList, which creates and stores Game instances and passes them to Players. On player creates a game and gets its ID from GameList and other player sends ID to GameList and gets Game instance.
The Game instance has its players as attributes. Problem is that each player sees only himself instead of the other one.
Example of what each player sees:
First player (Alice) creates a game: Creator: Alice, Joiner: Empty
Second player (Bob) joins the game: Creator: Bob, Joiner: Bob
First player refreshes her browser Creator: Alice, Joiner: Alice
What I want them to see is Creator: Alice, Joiner: Bob. Easy way to achieve this is saving information about players instead of references to players, but the game object needs to call methods on its player objects, so this is not a solution.
I think it's because of aop:scoped-proxy of session-scoped Player bean. If I understand this, the Game object has reference to proxy, which refers to Player object of current session. Can Game instance save/access the other Player objects somehow?
beans in dispatcher-servlet.xml:
<bean id="userDao" class="authorization.UserDaoFakeImpl" />
<bean id="gameList" class="model.GameList" />
<bean name="/init/*" class="controller.InitController" >
<property name="gameList" ref="gameList" />
<property name="game" ref="game" />
<property name="player" ref="player" />
</bean>
<bean id="game" class="model.GameContainer" scope="session">
<aop:scoped-proxy/>
</bean>
<bean id="player" class="beans.Player" scope="session">
<aop:scoped-proxy/>
</bean>
methods in controller.InitController
private GameList gameList;
private GameContainer game;
private Player player;
public ModelAndView create(HttpServletRequest request,
HttpServletResponse response) throws Exception {
game.setGame(gameList.create(player));
return new ModelAndView("redirect:game");
}
public ModelAndView join(HttpServletRequest request,
HttpServletResponse response, GameId gameId) throws Exception {
game.setGame(gameList.join(player, gameId.getId()));
return new ModelAndView("redirect:game");
}
called methods in model.gameList
public Game create(Player creator) {
Integer code = generateCode();
Game game = new Game(creator, code);
games.put(code, game);
return game;
}
public Game join(Player joiner, Integer code) {
Game game = games.get(code);
if (game!=null) {
game.setJoiner(joiner);
}
return game;
}
I made a mistake early in development, and named one of my models with plural noun (Users instead of User). Is there an easy way to rename it and corresponding controller (similar to generating it with script/generate way)?
how can i deny access to call method. something like this
[HandleError]
[Authorize(Roles = "role1, role2")]
public class AdminController : Controller
{
[Deny(Roles = "role2")]
public ActionResult ResultPage(string message)
{
ViewData["message"] = message;
return View();
}
}
I'm presenting a modal view (AddSite) in my RootViewController and in my AddSite Controller I have a method that dismisses the modal view. How can my RootViewController know when AddSiteController called dismissModalViewControllerAnimated and disappeared?
Hi,
My basic app has five distinct screens. Three of those screens have TableView data, and I'd like to associate them with a Tab bar + Navigation controller.
My question is if using different navigation paradigms in a same app is a good idea? (Button click driven for the first two screens and then through Tab bars / navigation controllers).
Thanks,
Teja.
Hello,
I have something like this in my Spring Application:
public class Book{
public Book(){
sheets = new LinkedList<Sheet>();
}
protected List<Sheet> sheets;
//getter and setter
}
I add several Sheets to the sheet list and I print a form in a JSP like this:
<form:form modelAttribute="book" action="${dest_url}" method="POST">
<c:forEach items="${mybook.sheets}" var="sheet" varStatus="status">
<form:hidden path="sheet[${status.count -1}].header"/>
<form:hidden path="sheet[${status.count -1}].footer"/>
<form:hidden path="sheet[${status.count -1}].operador"/>
<form:hidden path="sheet[${status.count -1}].number"/>
<form:hidden path="sheet[${status.count -1}].lines"/>
</c:forEach>
...
</form:form>
I need to get back this list in the controller when the form is submitted. So in my controller I have a method with a parameter like this:
public String myMethod (@ModelAttribute("book") Book book, Model model){
...
}
The problem is that it doesn't fill the sheets list unless in the constructor of Book I add as much Sheet's as I want to get. The problem is that I don't know in advance the number of Sheets the book is going to have.
I think the problem is that in my method it instantiates Book which has a list of sheets with 0 elements. When it tries to access to sheets[0] the list is empty and it doen't add a Sheet. I've tried to create a getter method for the list with an index parameter (so it can create the element if it doesn't exists in the list like in Struts framework) like this one:
public Sheet getSheets(int index){
if(sheets.size() <= index){
Sheet sheet = new Sheet();
sheets.add(index, sheet);
}
Sheet sheetToReturn = sheets.get(index);
if(sheetToReturn == null){
sheetToReturn = new Sheet();
sheets.add(index, sheetToReturn);
}
return sheetToReturn;
}
but with this method the JSP doesn't work because sheets has an invalid getter.
What's the proper way of filling a list when you don't know the number of items in advanced?
Thanks
My iphone application is showing strange behavior when rotating: a gap appears between the navigation title and content view inside a tab bar view (details on how to reproduce are below). I've created a tiny test case that exhibits the same problem: a custom root UIViewController, which creates and displays a UITabBarController programmatically, which has two tabs: 1) plain UIViewController, and 2) UINavigationController created programmatically with a single plain UIViewController content view.
The complete code for the application is in the root controller's viewDidLoad (every "*VC" class is a totally vanilla UIViewController subclass with XIB for user interface from XCode, with only the view background color changed to clearly identify each view, nothing else).
Here's the viewDidLoad code, and the shouldAutorotateToInterfaceOrientation code, this code is the entire application basically:
- (void)viewDidLoad {
[super viewDidLoad];
FirstVC *fvc = [[FirstVC alloc] initWithNibName:@"FirstVC" bundle:nil];
NavContentsVC *ncvc = [[NavContentsVC alloc] initWithNibName:@"NavContentsVC" bundle:nil];
UINavigationController *svc = [[UINavigationController alloc] initWithRootViewController:ncvc];
NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:2];
[localControllersArray addObject:fvc];
[localControllersArray addObject:svc];
fvc.title = @"FirstVC-Title";
ncvc.title = @"NavContents-Title";
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.view.frame = CGRectMake(0, 0, 320, 460);
[tbc setViewControllers:localControllersArray];
[self.view addSubview:tbc.view];
[localControllersArray release];
[ncvc release];
[svc release];
[fvc release];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
Here's how to reproduce the problem:
1) start application
2) rotate device (happens in simulator, too) to landscape (UITabBar properly rotates)
3) click on tab 2
4) rotate device to portrait -- notice gap of root view controller's background color of about 10 pixels high beneath the Navigation title bar and the Navigation content view.
5) click tab 1
6) click tab 2
And the gap is gone! From my real application, I see that the gap remains during all VC push and pops while the NavigationController tab is active. Switching away to a different tab and back to the Nav tab clears up the gap.
What am I doing wrong? I'm running on SDK 3.1.3, this happens both on the simulator and on the device. Except for this particular sequence, everything seems to work fine. Help!
Here is an example of what i want to do
The Url will be as follow
http://www.example.com/en/us/directory/companies/view/4433225.html
Where is
en: is the lang
us: is the country
directory: is the module
companies: is the controller
view: is the action
4433225.html: is sort of parameter send to the action could be the company name like this company-name.html
I was wondering if there is an option to change the debugger url when I initialize the debugger. I want it to start off at http://localhost:xxxx/controller/view rather than just http://localhost:xxxx/.
I have a webpage with two radiobuttons and a dropdownlist as follows:
<div class="sectionheader">Course
<div class="dropdown"><%=Html.DropDownList("CourseSelection", Model.CourseList, new { @class = "dropdown" })%> </div>
<div class="radiobuttons"><label><%=Html.RadioButton("CourseType", "Advanced", false )%> Advanced </label></div>
<div class="radiobuttons"><label><%=Html.RadioButton("CourseType", "Beginner", true )%> Beginner </label></div>
</div>
The dropdownlist is strongly typed and populated with Model.CourseList (NB - on the first page load, 'Beginner' is the default selection and the dropdown shows the beginner course options accordingly)
What I want to be able to do is to update the DropDownList based on which radiobutton is selected i.e. if 'Advanced' selected then show one list of course options in dropdown, and if 'Beginner' selected then show another list of courses.
The code I would like to call sits within my Controller:
public JsonResult UpdateDropDown(string courseType)
{
IDropDownList dropdownlistRepository = new DropDownListRepository();
IEnumerable<SelectListItem> courseList = dropdownlistRepository.GetCourseList(courseType);
return Json(courseList);
}
Edit - Updated below to show latest position
Using examples provided in jQuery in Action, I now have the following jQuery code:
$('.radiobuttons input:radio').click(function()
{
var courseType = $(this).val(); //Get selected courseType from radiobutton
var dropdownList = $(".dropdown"); //Ref for dropdownlist
$.getJSON("/ByCourse/UpdateDropDown", { courseType: courseType }, function(data) {
$(dropdownList).loadSelect(data);
});
});
The loadSelect function is taken straight from the book and is as follows:
(function($) {
$.fn.emptySelect = function() {
return this.each(function() {
if (this.tagName == 'SELECT') this.options.length = 0;
});
}
$.fn.loadSelect = function(optionsDataArray) {
return this.emptySelect().each(function() {
if (this.tagName == 'SELECT') {
var selectElement = this;
$.each(optionsDataArray, function(index, optionData) {
var option = new Option(optionData.Text, optionData.Value);
if ($.browser.msie) {
selectElement.add(option);
}
else {
selectElement.add(option, null);
}
});
}
});
}
})(jQuery);
1 day+ later I still cannot get this to work. Assuming the jQuery code is correct then I can only think that the issue is with retrieving the actual data with $getJSON.
I have verified that JsonResult UpdateDropDown does actually retrieve valid data. What am I missing?
Assembly reference? (NB: I have MicrosoftAjax.js and MicrosoftMvcAjax.js in my head tags of the master page
Should JsonResult be ActionResult? (I have seen both used in samples on web)
Do I need to register route Controller/UpdateDropDown in Global.asax?
Any further guidance would be appreciated.
I don't understand the concept of delegation is used in XCode. When a new project is created, an app delegate and a view controller are created, but what does the app delegate do? How does main.m know to call the delegate?
I am using IIS 7 rewrite to redirect certain pages to https. It seems that my post from such a page fails because i have Request Verification token attribute on the controller. Is this expected behavior or do I have something configured incorrectly? what to do to get around this? works fine without the https redirect.
I have an index view that lists all of the tags for my Entry and Message models. I would like to only show the tags for Entries in this view. I'm using acts-as-taggable-on.
Tags Controller:
def index
@letter = params[:letter].blank? ? 'a' : params[:letter]
@tagged_entries = Tagging.find_all_by_taggable_type('Entry').map(&:taggable)
@title = "Tags"
if params[:letter] == '#'
@data = Tag.find(@tagged_entries, :conditions => ["name REGEXP ?",
"^[^a-z]"], :order => 'name', :select => "id, name")
else
@data = Tag.find(@tagged_entries, :conditions => ["name LIKE ?",
"#{params[:letter]}%"], :order => 'name', :select => "id, name")
end
respond_to do |format|
flash[:notice] = 'We are currently in Beta. You may experience errors.'
format.html
end
end
tags#index:
<% @data.each do |t| %>
<div class="tag"><%= link_to t.name.titleize, tag_path(t) %></div>
<% end %>
I want to show only the taggable type 'Entry' in the view.
Any ideas? Thank you for reading my question.
SECOND EDIT:
Tags Controller:
def index
@title = "Tags"
@letter = params[:letter].blank? ? 'a' : params[:letter]
@taggings = Tagging.find_all_by_taggable_type('Entry', :include => [:tag, :taggable])
@tags = @taggings.map(&:tag).sort_by(&:name).uniq
@tagged_entries = @taggings.map(&:taggable)#.sort_by(&:id)#or whatever
if params[:letter] == '#'
@data = Tag.find(@tags, :conditions => ["name REGEXP ?",
"^[^a-z]"], :order => 'name', :select => "id, name")
else
@data = Tag.find(@tags, :conditions => ["name LIKE ?",
"#{params[:letter]}%"], :order => 'name', :select => "id, name")
end
respond_to do |format|
format.html
end
end
tags#index:
<% @data.each do |t| %>
<div class="tag"><%= link_to t.name.titleize, tag_path(t) %></div>
<% end %>
Max Williams' code works except when I click on my alphabetical pagination links. The error I'm getting [after I clicked on the G link of the alphabetical pagination] reads:
Couldn't find all Tags with IDs (77,130,115,...) AND (name LIKE 'G%') (found 9 results, but was looking for 129)
Can anyone point me in the right direction?
How do I map something like domain.com/username? The problem is I think that the MVC routing looks for the controller to determine how it should handle the mapping request.
I am pretty new to ASP.NET MVC.
However, based on the tutorials so far, the routing mechanism seems rather rigid.