Rectangle 27 8

You can do this with a custom filter:

$(document).ajaxError(function(event, jqxhr) {
    console.log(jqxhr.responseText);
});
[HttpPost]
[CustomHandleErrorAttribute]
public JsonResult Foo(bool isTrue)
{
    if (isTrue)
    {
        return Json(new { Foo = "Bar" });
    }
    throw new HttpException(404, "Oh noes...");
}

public class CustomHandleErrorAttribute : HandleErrorAttribute
{
    public override void OnException(ExceptionContext filterContext)
    {
        var exception = filterContext.Exception;
        var statusCode = new HttpException(null, exception).GetHttpCode();

        filterContext.Result = new JsonResult
        {
            JsonRequestBehavior = JsonRequestBehavior.AllowGet, //Not necessary for this example
            Data = new
            {
                error = true,
                message = filterContext.Exception.Message
            }
        };

        filterContext.ExceptionHandled = true;
        filterContext.HttpContext.Response.Clear();
        filterContext.HttpContext.Response.StatusCode = statusCode;  
        filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
    }
}

ASP.NET MVC Ajax Error returning view instead of ajax - Stack Overflow

ajax asp.net-mvc jquery error-handling
Rectangle 27 8

You can do this with a custom filter:

$(document).ajaxError(function(event, jqxhr) {
    console.log(jqxhr.responseText);
});
[HttpPost]
[CustomHandleErrorAttribute]
public JsonResult Foo(bool isTrue)
{
    if (isTrue)
    {
        return Json(new { Foo = "Bar" });
    }
    throw new HttpException(404, "Oh noes...");
}

public class CustomHandleErrorAttribute : HandleErrorAttribute
{
    public override void OnException(ExceptionContext filterContext)
    {
        var exception = filterContext.Exception;
        var statusCode = new HttpException(null, exception).GetHttpCode();

        filterContext.Result = new JsonResult
        {
            JsonRequestBehavior = JsonRequestBehavior.AllowGet, //Not necessary for this example
            Data = new
            {
                error = true,
                message = filterContext.Exception.Message
            }
        };

        filterContext.ExceptionHandled = true;
        filterContext.HttpContext.Response.Clear();
        filterContext.HttpContext.Response.StatusCode = statusCode;  
        filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
    }
}

ASP.NET MVC Ajax Error returning view instead of ajax - Stack Overflow

ajax asp.net-mvc jquery error-handling
Rectangle 27 4

You can achieve that with a custom filter:

The code for the standard select filter on ngtable says:

<select ng-options="data.id as data.title for data in column.data"
    ng-model="params.filter()[name]"
    ng-show="filter == 'select'"
    class="filter filter-select form-control" name="{{column.filterName}}">
</select>

When you call this data you pass: filter-data="names($column)" and ngtable takes care of getting the data for you. I don't know why this does not work with an external resource. I bet it has something to do with the $column and the promise, as you pointed out.

<select id="filterTest" class="form-control" 
    ng-model="tableParams.filter()['test']" 
    ng-options="e.id as e.title for e in externaldata">
</select>

You fetch this externaldata in your controller:

$scope.externaldata = Api.query(); // Your custom api call

It works perfectly, but I do have an id on my data, so no need of the name function.

Can you please help me with a similar question here?

javascript - How to populate select filters on ng-table from async cal...

javascript angularjs ngtable
Rectangle 27 4

You can achieve that with a custom filter:

The code for the standard select filter on ngtable says:

<select ng-options="data.id as data.title for data in column.data"
    ng-model="params.filter()[name]"
    ng-show="filter == 'select'"
    class="filter filter-select form-control" name="{{column.filterName}}">
</select>

When you call this data you pass: filter-data="names($column)" and ngtable takes care of getting the data for you. I don't know why this does not work with an external resource. I bet it has something to do with the $column and the promise, as you pointed out.

<select id="filterTest" class="form-control" 
    ng-model="tableParams.filter()['test']" 
    ng-options="e.id as e.title for e in externaldata">
</select>

You fetch this externaldata in your controller:

$scope.externaldata = Api.query(); // Your custom api call

It works perfectly, but I do have an id on my data, so no need of the name function.

Can you please help me with a similar question here?

javascript - How to populate select filters on ng-table from async cal...

javascript angularjs ngtable
Rectangle 27 2

In our case it turned out that the error happened because we have a custom filter in our application which does HttpServletResponse sendRedirect() to other url.

For some reason, the redirection is not closing the keep-alive status of the connection, hence the timeout exception.

We checked with Tomcat Docs and when we disabled the maxKeepAliveRequests by setting it's value to 1 and the error stopped showing up.

For now we do not have the actual solution to the error.

java - Tomcat 7.0.43 "INFO: Error parsing HTTP request header" - Stack...

java tomcat servlets tomcat7
Rectangle 27 5

You probably want to have a custom authorization filter. Here's an example: Custom filters in MVC. You can then apply this filter globally on app start (using RegisterGlobalFilters).

public class LegacyAuthorize : AuthorizeAttribute
{
  public override void OnAuthorization(HttpActionContext actionContext)
  {
    if (HttpContext.Current.Session["User"] == null)
      base.HandleUnauthorizedRequest(actionContext);
  }
}

Then in your global.asax you'd have something like this:

GlobalFilters.Filters.Add(new LegacyAuthorize());

Overriding the Authorize attribute can be dangerous especially if only validating session. Session Id is not re-generated, which can lead to session hijack via XSS etc. blog.securityps.com/2013/06/ and support.microsoft.com/en-us/kb/899918

c# - Custom Authentication and ASP.NET MVC - Stack Overflow

c# asp.net asp.net-mvc asp.net-mvc-4
Rectangle 27 31

You haven't been particularly descriptive with the errors you're seeing so I don't know if the following will help..

I had a problem originally when using the ui-select demo code as an example because they're using the propsFilter filter which is a custom filter they have written for the demo:

<ui-select-choices repeat="tag in all_tags | propsFilter: {name: $select.search}">

I am assuming you're not including this filter in your code which may be a reason you're experiencing a problem. You can resolve it by using angular's normal filter:

<ui-select-choices repeat="tag in all_tags | filter: {name: $select.search}">

Alternatively, if you have multiple properties to filter you can write the propsFilter filter to filter on OR rather than AND. If you use 'filter' to filter multiple properties it will try to match the search value across all of the properties.

app.filter('propsFilter', function() {
  return function(items, props) {
            var out = [];
                if (angular.isArray(items)) {
                  items.forEach(function(item) {
                        var itemMatches = false;

                        var keys = Object.keys(props);
                        for (var i = 0; i < keys.length; i++) {
                              var prop = keys[i];
                              var text = props[prop].toLowerCase();
                              if (item[prop].toString().toLowerCase().indexOf(text) !== -1) {
                                    itemMatches = true;
                                    break;
                                  }
                            }

                            if (itemMatches) {
                              out.push(item);
                            }
                      });
                } else {
                  // Let the output be the input untouched
                      out = items;
                }

                return out;
          };
    });

Thanks for pointing out that propsFilter is a custom method. That potentially saved me hours of head-scratching. I'm going to submit a PR to ui-select that states as much.

Hi, thank you for your explanation. I started using the code you provided but run into a bug. Turns out that there is a difference in what is posted here with the commit you reference: The inner for should be: for (var i = 0; i < keys.length; i++) to avoid getting into an infinite loop.

Ohhhhhhhhhh that custom propsFilter! Thank you! This is the end of hours and hours and hours of head-scratching!

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

javascript - AngularJs: How make ui-select working properly? - Stack O...

javascript html angularjs ui-select
Rectangle 27 4

It sounds to me like what you want here is a Custom Action Filter. You can override the OnActionExecuting method which means the logic is run before any action is called

public class EnsureLanguagePreferenceAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var langCookie = filterContext.HttpContext.Request.Cookies["LanguagePref"];
        if (langCookie == null)
        {
            // cookie doesn't exist, either pull preferred lang from user profile
            // or just setup a cookie with the default language
            langCookie = new HttpCookie("LanguagePref", "en-gb");
            filterContext.HttpContext.Request.Cookies.Add(langCookie);
        }
        // do something with langCookie
        base.OnActionExecuting(filterContext);
    }
}

Then register your attribute globally so it just becomes the default behaviour on every controller action

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new HandleErrorAttribute());
    filters.Add(new EnsureLanguagePreferenceAttribute());
}

I like this, clean and easy. I can even check filter names and authentication status

I think this is the best solution

Asp.Net MVC5 How to ensure that a cookie exists? - Stack Overflow

asp.net asp.net-mvc cookies asp.net-mvc-5 asp.net-identity
Rectangle 27 3

I was able to follow only the first half of your question. It's the one in which you have showed some code and the one with which I can help you. The second half was a complete mist for me.

So when you want to design a view think of what fields this view needs to display/edit. And design a view model for it:

public class ChangeProfileViewModel
{
    [Required]
    public string Address { get; set; }

    [Required]
    public string City { get; set; }
}

and then have your GET controller action that is supposed to render this view populate the view model:

@model ChangeProfileViewModel
@using (Html.BeginForm())
{
    @Html.EditorForModel()
    <button type="submit">OK</button>
}

and finally you have a POST controller action that will handle the submission of this form:

Now what we observe here is that in both our GET and POST actions we have repetitive mapping code between our domain model (CustomProfile) and our view model (ChangeProfileViewModel). To solve this issue I may recommend you using AutoMapper. It could simplify your GET action to:

public ActionResult ChangeProfile()
{
    CustomProfile profile = CustomProfile.GetUserProfile(User.Identity.Name);
    ChangeProfileViewModel model = Mapper.Map<CustomProfile, ChangeProfileViewModel>(profile);
    return View(model);
}

or with a custom action filter to even:

[AutoMap(typeof(CustomProfile), typeof(ChangeProfileViewModel))]
public ActionResult ChangeProfile()
{
    CustomProfile profile = CustomProfile.GetUserProfile(User.Identity.Name);
    return View(profile);
}

and your POST action to:

[HttpPost]
public ActionResult ChangeProfile(ChangeProfileViewModel model)
{
    if (!Model.IsValid)
    {
        // there were validation errors => redisplay the view
        return View(model);
    }

    // validation succeeded => process the results
    CustomProfile profile = CustomProfile.GetUserProfile();
    Mapper.Map<ChangeProfileViewModel, CustomProfile>(model, profile);
    profile.Save();
    return RedirectToAction("Profile");
}

What's important to know about view models is that you should always use them for each view and design them in such a way so that they contain only the specific information that this view needs to handle. Leave to the mapping layer handle the conversion between your domain entities and your view models.

Thank you for the quick reply. I sleep around this time, so I will have to try it out in the morning, but it looks like you have given me a much more well-rounded view of ViewModels. As far as the lack of comprehension within my original post, I wrote it in two sessions (one after I received a lengthy phone call), this probably through off my grove and I may revise. I will update when I have more time to focus on what you have provided me.

I was able to correctly auto-populate my fields. Thank you. However, I was unable to get AutoMapper to map between my two models (threw an 'exception') I'll likely get more into that when I return to this part of the project to refine things. Thank you once again.

asp.net mvc - How to auto-populate specific fields when using @Html.Ed...

asp.net-mvc razor auto-populate editorformodel
Rectangle 27 1

One possibility is to write a custom action filter which will execute after each action and populate the ProductColors property on your model:

public class PopulateProductColorsAttribute: ActionFilterAttribute
{
    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        var viewResult = filterContext.Result as ViewResultBase;
        if (viewResult == null)
        { 
            // the controller action didn't return a view result => no need to go any further
            return;
        }

        var model = viewResult.Model as SomeModel;
        if (model == null)
        {
            // The controller action didn't pass a model containing the ProductColors property => no need to go any further
            return;
        }

        // now populate the ProductColors property. Of course here you could do a db lookup or whatever
        model.ProductColors = new[]
        {
            new SelectListItem { Value = "Red", Text = "Red" },
            new SelectListItem { Value = "Green", Text = "Green" },
            new SelectListItem { Value = "Blue", Text = "Blue" },
        };
    }
}

and now all that's left is decorate all controller actions that need this with the custom action filter:

[PopulateProductColors]
public ActionResult Index()
{
    SomeModel model = ...
    return View(model);
}

[PopulateProductColors]
[HttpPost]
public ActionResult Index(SomeModel model)
{
    ...
}

or register it as a global action filter in which case it will apply to all your controller actions.

asp.net mvc 4 - SelectList for DB Value - Stack Overflow

asp.net-mvc-4 entity-framework-5
Rectangle 27 17

As the docs says, the custom authentication filter provides an authentication per-action, per-controller or globally.

An example use is changing the authentication for just few selected controllers. Suppose for example that your whole site uses Forms Authentication where principals are taken from forms cookies.

However, you have a selected controller that acts as OAuth2 Resource Server where requests come from Service Providers (servers) and there are no forms cookies, rather, an OAuth2 access token is provided by the service provider server.

This is where a custom authentication filter comes into play - its task is to translate the token to a principal for the lifetime of current request only, just for the only controller that acts as the resource server endpoint. You don't want the whole site to accept OAuth2 tokens, rather the one particular controller.

The reason to introduce authentication filters is to separate authentication from authorization, where:

  • authentication is for estabilishing a principal for current request
  • authorization is to verify whether or not the current principal is permitted to execute current request

This was not clearly separated before authentication filters were introduced. Personally, I used to use authorization filters for this, however having two separate layers of filters in this particular order (authentication first, then authorization) is just cleaner.

c# - Authentication filters in MVC 5 - Stack Overflow

c# asp.net asp.net-mvc asp.net-mvc-4 asp.net-mvc-5
Rectangle 27 3

First some technical background information: until the upcoming JSF 2.2, JSF doesn't natively support multipart/form-data requests. So the component library offering the file upload component has to come up with a custom Filter itself. This should properly parse multipart/form-data requests and store all the necessary regular data in the HTTP request parameter map and the uploaded file(s) as request attribute(s). This way JSF can continue using request.getParameter() for regular data the usual way and the component library itself can get the uploaded file(s) as request attribute.

In case of Seam's <s:fileUpload>, you need the org.jboss.seam.web.MultipartFilter to perform the multipart/form-data parsing job. I have never used Seam (nor ICEfaces), but Google shows me that you basically need either this in webapp's web.xml

<filter>
    <filter-name>Seam Multipart Filter</filter-name>
    <filter-class>org.jboss.seam.web.MultipartFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>Seam Multipart Filter</filter-name>
    <url-pattern>*.seam</url-pattern>
</filter-mapping>
components.xml
<web:multipart-filter url-pattern="*.seam" />

The ICEfaces component must have a similar Filter configured. The ICEfaces 3.x documentation is lacking (or my Google / icefaces.com search skills are bad), so I can't go in detail about this.

Important to keep in mind is that a HTTP request can be parsed only once (the client will send it only once, not multiple times) and thus you can't use the both multipart/form-data parsers simultaneously on the same request. The one which kicks in after the first one would get an empty request body which isn't parseable into anything sensible. So if you're using a component which is using the latter filter, then you wouldn't get anything in the model. Make sure that you haven't by accident or by experiment configured both.

Thanks for your suggestions - I already tried the Seam Multipart Filter stuff which did not work out, but after your comment I looked deeper into my Filter declarations and found out that disabling the Multipart Filter after adding it at least makes ICEfaces doing something - see Update in question.

To confirm, does your UploadBean really have the method fileUploadListener(FileEntryEvent event)? The exception is telling that this method is missing. Your EL expression is fine btw, the event will be automatically supplied. Given the fact that ICEfaces magically works with Seam's filter disabled, it look much like that it's implicitly and silently registering a file upload filter. If you'd prefer to use Seam's one, you might want to look in the ICEfaces documentation if that filter isn't disableable by some context parameter --so that you could if necessary test the Seam one.

Yes, it does. In all other cases in my app, the events are automatically filled in with the listener call, only the FileEntryEvent doesn't want to...e.g. if I call the listener with a parameter of null, it is called and the above message printed out, so at least the method is available somewhere. I think I'll search ICEfaces for the place where the event is raised and see where it goes to, maybe that will help...

Coming back to your question update about classloading issues; that might explain it. The FileEntryEvent class which is loaded by classloader X is not the same FileEntryEvent class which is loaded by classloader Y. It's very reasonable that EL has created the FileEntryEvent argument through classloader X and the managed bean class with the upload method is been loaded through classloader Y. This way the method signature will never match. Front-end libraries (ICEfaces/Seam/etc) doesn't belong in EAR/lib and must be in WEB-INF/lib. So if you fix that part, the upload will likely work.

In other words, you should not have duplicates of the same library in different places of the classpath. You mentioned that it didn't deploy when you remove it from EAR/lib. Do you get a concrete exception/error?

jsf - ICEfaces/Seam file upload component not uploading files - Stack ...

jsf jsf-2 seam icefaces
Rectangle 27 19

There are legitimate scenarios for using query_posts($query), for example:

Now why would you want to display it on a page instead of using an archive template?

Here's a simplified example code (which would be on your page template - e.g. page-page-of-posts.php):

/**
 * Template Name: Page of Posts
 */

while(have_posts()) { // original main loop - page content
  the_post();
  the_title(); // title of the page
  the_content(); // content of the page
  // etc...
}

// now we display list of our custom-post-type posts

// first obtain pagination parametres
$paged = 1;
if(get_query_var('paged')) {
  $paged = get_query_var('paged');
} elseif(get_query_var('page')) {
  $paged = get_query_var('page');
}

// query posts and replace the main query (page) with this one (so the pagination works)
query_posts(array('post_type' => 'my_post_type', 'post_status' => 'publish', 'paged' => $paged));

// pagination
next_posts_link();
previous_posts_link();

// loop
while(have_posts()) {
  the_post();
  the_title(); // your custom-post-type post's title
  the_content(); // // your custom-post-type post's content
}

wp_reset_query(); // sets the main query (global $wp_query) to the original page query (it obtains it from global $wp_the_query variable) and resets the post data

// So, now we can display the page-related content again (if we wish so)
while(have_posts()) { // original main loop - page content
  the_post();
  the_title(); // title of the page
  the_content(); // content of the page
  // etc...
}

Now, to be perfectly clear, we could avoid using query_posts() here too and use WP_Query instead - like so:

// ...

global $wp_query;
$wp_query = new WP_Query(array('your query vars here')); // sets the new custom query as a main query

// your custom-post-type loop here

wp_reset_query();

// ...

But, why would we do that when we have such a nice little function available for it?

Brian, thanks for that. I've been struggling to get pre_get_posts to work on a page in EXACTLY the scenario you describe: client needs to add custom fields/content to what otherwise would be an archive page, so a "page" needs to be created; client needs to see something to add to nav menu, as adding a custom link escapes them; etc. +1 from me!

That can also be done using "pre_get_posts". I did that to have a "static front page" listing my custom post types in a custom order and with a custom filter. This page is also paginated. Check out this question to see how it works: wordpress.stackexchange.com/questions/30851/ So in short, there is still no more legitimate scenario for using query_posts ;)

Because "It should be noted that using this to replace the main query on a page can increase page loading times, in worst case scenarios more than doubling the amount of work needed or more. While easy to use, the function is also prone to confusion and problems later on." Source codex.wordpress.org/Function_Reference/query_posts

THis answer is all kinds of wrong. You can create a "Page" in WP with the same URL as the Custom post type. EG if your CPT is Bananas, you can get a page named Bananas with the same URL. Then you'd end up with siteurl.com/bananas. As long as you have archive-bananas.php in your theme folder, then it will use the template and "override" that page instead. As stated in one of the other comments, using this "method" creates twice the workload for WP, thus should NOT ever be used.

wp-query query-posts get-posts pre-get-posts
Rectangle 27 19

There are legitimate scenarios for using query_posts($query), for example:

Now why would you want to display it on a page instead of using an archive template?

Here's a simplified example code (which would be on your page template - e.g. page-page-of-posts.php):

/**
 * Template Name: Page of Posts
 */

while(have_posts()) { // original main loop - page content
  the_post();
  the_title(); // title of the page
  the_content(); // content of the page
  // etc...
}

// now we display list of our custom-post-type posts

// first obtain pagination parametres
$paged = 1;
if(get_query_var('paged')) {
  $paged = get_query_var('paged');
} elseif(get_query_var('page')) {
  $paged = get_query_var('page');
}

// query posts and replace the main query (page) with this one (so the pagination works)
query_posts(array('post_type' => 'my_post_type', 'post_status' => 'publish', 'paged' => $paged));

// pagination
next_posts_link();
previous_posts_link();

// loop
while(have_posts()) {
  the_post();
  the_title(); // your custom-post-type post's title
  the_content(); // // your custom-post-type post's content
}

wp_reset_query(); // sets the main query (global $wp_query) to the original page query (it obtains it from global $wp_the_query variable) and resets the post data

// So, now we can display the page-related content again (if we wish so)
while(have_posts()) { // original main loop - page content
  the_post();
  the_title(); // title of the page
  the_content(); // content of the page
  // etc...
}

Now, to be perfectly clear, we could avoid using query_posts() here too and use WP_Query instead - like so:

// ...

global $wp_query;
$wp_query = new WP_Query(array('your query vars here')); // sets the new custom query as a main query

// your custom-post-type loop here

wp_reset_query();

// ...

But, why would we do that when we have such a nice little function available for it?

Brian, thanks for that. I've been struggling to get pre_get_posts to work on a page in EXACTLY the scenario you describe: client needs to add custom fields/content to what otherwise would be an archive page, so a "page" needs to be created; client needs to see something to add to nav menu, as adding a custom link escapes them; etc. +1 from me!

That can also be done using "pre_get_posts". I did that to have a "static front page" listing my custom post types in a custom order and with a custom filter. This page is also paginated. Check out this question to see how it works: wordpress.stackexchange.com/questions/30851/ So in short, there is still no more legitimate scenario for using query_posts ;)

Because "It should be noted that using this to replace the main query on a page can increase page loading times, in worst case scenarios more than doubling the amount of work needed or more. While easy to use, the function is also prone to confusion and problems later on." Source codex.wordpress.org/Function_Reference/query_posts

THis answer is all kinds of wrong. You can create a "Page" in WP with the same URL as the Custom post type. EG if your CPT is Bananas, you can get a page named Bananas with the same URL. Then you'd end up with siteurl.com/bananas. As long as you have archive-bananas.php in your theme folder, then it will use the template and "override" that page instead. As stated in one of the other comments, using this "method" creates twice the workload for WP, thus should NOT ever be used.

wp-query query-posts get-posts pre-get-posts
Rectangle 27 19

There are legitimate scenarios for using query_posts($query), for example:

Now why would you want to display it on a page instead of using an archive template?

Here's a simplified example code (which would be on your page template - e.g. page-page-of-posts.php):

/**
 * Template Name: Page of Posts
 */

while(have_posts()) { // original main loop - page content
  the_post();
  the_title(); // title of the page
  the_content(); // content of the page
  // etc...
}

// now we display list of our custom-post-type posts

// first obtain pagination parametres
$paged = 1;
if(get_query_var('paged')) {
  $paged = get_query_var('paged');
} elseif(get_query_var('page')) {
  $paged = get_query_var('page');
}

// query posts and replace the main query (page) with this one (so the pagination works)
query_posts(array('post_type' => 'my_post_type', 'post_status' => 'publish', 'paged' => $paged));

// pagination
next_posts_link();
previous_posts_link();

// loop
while(have_posts()) {
  the_post();
  the_title(); // your custom-post-type post's title
  the_content(); // // your custom-post-type post's content
}

wp_reset_query(); // sets the main query (global $wp_query) to the original page query (it obtains it from global $wp_the_query variable) and resets the post data

// So, now we can display the page-related content again (if we wish so)
while(have_posts()) { // original main loop - page content
  the_post();
  the_title(); // title of the page
  the_content(); // content of the page
  // etc...
}

Now, to be perfectly clear, we could avoid using query_posts() here too and use WP_Query instead - like so:

// ...

global $wp_query;
$wp_query = new WP_Query(array('your query vars here')); // sets the new custom query as a main query

// your custom-post-type loop here

wp_reset_query();

// ...

But, why would we do that when we have such a nice little function available for it?

Brian, thanks for that. I've been struggling to get pre_get_posts to work on a page in EXACTLY the scenario you describe: client needs to add custom fields/content to what otherwise would be an archive page, so a "page" needs to be created; client needs to see something to add to nav menu, as adding a custom link escapes them; etc. +1 from me!

That can also be done using "pre_get_posts". I did that to have a "static front page" listing my custom post types in a custom order and with a custom filter. This page is also paginated. Check out this question to see how it works: wordpress.stackexchange.com/questions/30851/ So in short, there is still no more legitimate scenario for using query_posts ;)

Because "It should be noted that using this to replace the main query on a page can increase page loading times, in worst case scenarios more than doubling the amount of work needed or more. While easy to use, the function is also prone to confusion and problems later on." Source codex.wordpress.org/Function_Reference/query_posts

THis answer is all kinds of wrong. You can create a "Page" in WP with the same URL as the Custom post type. EG if your CPT is Bananas, you can get a page named Bananas with the same URL. Then you'd end up with siteurl.com/bananas. As long as you have archive-bananas.php in your theme folder, then it will use the template and "override" that page instead. As stated in one of the other comments, using this "method" creates twice the workload for WP, thus should NOT ever be used.

wp-query query-posts get-posts pre-get-posts
Rectangle 27 1

You can create custom action filter and set this on controller like this:

...
[CustomActionFilter]
public class FilesController : Controller
{
    ...
}

and on this custom filter you can get action name like this:

public class 

CustomActionFilter : ActionFilterAttribute, IActionFilter
{
    void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)


    {
        // TODO: Add your acction filter's tasks here

        // Log Action Filter Call
        MusicStoreEntities storeDB = new MusicStoreEntities();

        ActionLog log = new ActionLog()
        {
            Controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName,
            Action = filterContext.ActionDescriptor.ActionName + " (Logged By: Custom 

Action Filter)",
            IP = filterContext.HttpContext.Request.UserHostAddress,
            DateTime = filterContext.HttpContext.Timestamp
        };

        storeDB.ActionLogs.Add(log);
        storeDB.SaveChanges();

        this.OnActionExecuting(filterContext);
    }
}

More details you can find here on Microsoft site or on this question.

c# - ASP.NET MVC pass a parameter from a view to a controller - Stack ...

c# asp.net asp.net-mvc
Rectangle 27 8

Right now you can do this with SVG filters. Since your interest lies in mixing colors, you might be interested in researching the following filter primitives: feBlend, feComposite, feColorMatrix and feComponentTransfer.

If you want to learn the easy way (Inkscape) see this blogpost. I can also recommend reading the Inkscape book and in particular how to do custom filters. Here's one page showing feBlend with similar results as in your basic effect example.

Update: here's the relevant svg file from the inkscape book, it should look like the image below in browsers that support svg filters (and the BackgroundImage filter input, note that Gecko doesn't support BackgroundImage and enable-background).

I had never even heard of those filters as part of the standard! Upon first glance I thought 'fe' might be some sort of vendor prefix, boy was I wrong. Thanks.

The problem with these examples is that they rely on "enable-background" - which doesn't work on either webkit or mozilla right now (don't know about opera). If you're going to do this using filters, I think you have to pull in images (or create color circles using lighting effects)

The examples perhaps use enable-background, but it's possible to avoid using that. Yes, Opera has had support for enable-background for a long time. IIRC IE10 also supports enable-background.

FYI - I've filed a bug against Chromium for enable-background support. If you have an example without enable-background, I'd love to see it. I haven't been able to figure this out myself

It's possible to use <feImage> that references some particular elements in the svg as a partial workaround (however, note that Firefox doesn't support that). This way you can composite/blend two or more arbitrary elements.

graphics - Using SVG for additive color mixing (additive blending) - S...

graphics colors svg transparency svg-filters
Rectangle 27 7

Option 2: Servlet filter in ROOT context

EDIT: These instructions are for JBoss AS6 as requested in the original question. AS7 has different configuration file syntax.

<!-- A HTTP/1.1 Connector on port 8081 -->
<Connector protocol="HTTP/1.1" port="8081" address="${jboss.bind.address}" 
   redirectPort="${jboss.web.https.port}" />

<!-- A HTTP/1.1 Connector on port 8082 -->
<Connector protocol="HTTP/1.1" port="8082" address="${jboss.bind.address}" 
   redirectPort="${jboss.web.https.port}" />

Observe the following messages in the log when server boots up:

11:56:23,639 INFO  [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8081
11:56:23,640 INFO  [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8082

Note: If you want to do it "properly" you should use placeholders instead of hardcoded numbers and edit $JBOSS_HOME/server/default/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml to define them. But, unless you need to manage ports via the management UI, it will be an overkill.

This is much harder. JBoss uses its own Tomcat engine that does not support multiple webapp roots (appBase attribute does not work). Thus it is impossible to configure two different directories for your connectors. It is possible to add virtual hosts and use jboss-web.xml in each app to configure which vhost it responds to, but that means your have to use different names in client URL-s.

You have two options here.

Host
$JBOSS_HOME/server/default/deploy/jbossweb.sar/server.xml
<Valve className="org.jboss.web.rewrite.RewriteValve" />
RewriteCond %{SERVER_PORT}  =8081
RewriteRule ^/(.*)$  /app1/$1 [L]

RewriteCond %{SERVER_PORT}  =8082
RewriteRule ^/(.*)$  /app2/$1 [L]
$JBOSS_HOME/server/default/conf/jboss.web/localhost/

Note2: Location of the rewrite.properties depends on the placement of the Valve tag in server.xml. The most intuitive placement is with other Valve elements. However it is valid directly under Engine as well. In this case rewrite.properties file needs to be moved up one directory.

Deploy a servlet filter to $JBOSS_HOME/server/default/deploy/ROOT.war/ that dispatches requests based on incoming port. You can either roll out your own custom filter implementation or use UrlRewriteFilter with a configuration that looks like this:

<rule>
  <condition type="port">8081</condition>
  <from>/(.*)</from>
  <to context="app1">/$1</to>
</rule>

<rule>
  <condition type="port">8082</condition>
  <from>/(.*)</from>
  <to context="app2">/$1</to>
</rule>

EDIT: Given the complexity of JBoss configuration you may also opt for an Apache based reverse proxy that sits in front of the app server.

There is also 3rd option, doing IP based virtual hosts. in this case connectors need to be bound to two different IP addresses and need useIPVHosts="true" From there on everything is the same as with ordinary virtual hosts with exception that you need to add <alias> with ip address of the connector as well.

server
$JBOSS_HOME
appclient  docs           jboss-modules.jar  standalone bin        domain         LICENSE.txt        version.txt bundles    JBossEULA.txt  modules            welcome-content

That directory structure looks like it comes from AS7. What exactly did you install? AS 6 or EAP 6? If it is EAP then it's based on JBoss AS 7 not AS 6. access.redhat.com/site/articles/112673 I'll leave it up to you to convert the detailed instructions I provided to the new configuration file format. Same ideas, different config file locations and format.

standalone/configuration/standalone.xml

java - How to run different apps on single JBoss AS 6 instance behind ...

java tomcat servlets jboss jboss6.x
Rectangle 27 7

Option 2: Servlet filter in ROOT context

EDIT: These instructions are for JBoss AS6 as requested in the original question. AS7 has different configuration file syntax.

<!-- A HTTP/1.1 Connector on port 8081 -->
<Connector protocol="HTTP/1.1" port="8081" address="${jboss.bind.address}" 
   redirectPort="${jboss.web.https.port}" />

<!-- A HTTP/1.1 Connector on port 8082 -->
<Connector protocol="HTTP/1.1" port="8082" address="${jboss.bind.address}" 
   redirectPort="${jboss.web.https.port}" />

Observe the following messages in the log when server boots up:

11:56:23,639 INFO  [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8081
11:56:23,640 INFO  [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8082

Note: If you want to do it "properly" you should use placeholders instead of hardcoded numbers and edit $JBOSS_HOME/server/default/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml to define them. But, unless you need to manage ports via the management UI, it will be an overkill.

This is much harder. JBoss uses its own Tomcat engine that does not support multiple webapp roots (appBase attribute does not work). Thus it is impossible to configure two different directories for your connectors. It is possible to add virtual hosts and use jboss-web.xml in each app to configure which vhost it responds to, but that means your have to use different names in client URL-s.

You have two options here.

Host
$JBOSS_HOME/server/default/deploy/jbossweb.sar/server.xml
<Valve className="org.jboss.web.rewrite.RewriteValve" />
RewriteCond %{SERVER_PORT}  =8081
RewriteRule ^/(.*)$  /app1/$1 [L]

RewriteCond %{SERVER_PORT}  =8082
RewriteRule ^/(.*)$  /app2/$1 [L]
$JBOSS_HOME/server/default/conf/jboss.web/localhost/

Note2: Location of the rewrite.properties depends on the placement of the Valve tag in server.xml. The most intuitive placement is with other Valve elements. However it is valid directly under Engine as well. In this case rewrite.properties file needs to be moved up one directory.

Deploy a servlet filter to $JBOSS_HOME/server/default/deploy/ROOT.war/ that dispatches requests based on incoming port. You can either roll out your own custom filter implementation or use UrlRewriteFilter with a configuration that looks like this:

<rule>
  <condition type="port">8081</condition>
  <from>/(.*)</from>
  <to context="app1">/$1</to>
</rule>

<rule>
  <condition type="port">8082</condition>
  <from>/(.*)</from>
  <to context="app2">/$1</to>
</rule>

EDIT: Given the complexity of JBoss configuration you may also opt for an Apache based reverse proxy that sits in front of the app server.

There is also 3rd option, doing IP based virtual hosts. in this case connectors need to be bound to two different IP addresses and need useIPVHosts="true" From there on everything is the same as with ordinary virtual hosts with exception that you need to add <alias> with ip address of the connector as well.

server
$JBOSS_HOME
appclient  docs           jboss-modules.jar  standalone bin        domain         LICENSE.txt        version.txt bundles    JBossEULA.txt  modules            welcome-content

That directory structure looks like it comes from AS7. What exactly did you install? AS 6 or EAP 6? If it is EAP then it's based on JBoss AS 7 not AS 6. access.redhat.com/site/articles/112673 I'll leave it up to you to convert the detailed instructions I provided to the new configuration file format. Same ideas, different config file locations and format.

standalone/configuration/standalone.xml

java - How to run different apps on single JBoss AS 6 instance behind ...

java tomcat servlets jboss jboss6.x
Rectangle 27 2

def genregex(n):
    nstr = str(n)
    same_digit = ''.join('[' + "0123456789"[int(d):] + ']' for d in nstr)
    return "\d{%d,}|%s" % (len(nstr) + 1, same_digit)

It's easy to modify to handle leading 0's if that occurs in your website. But this seems like the wrong approach.

You have a few other options in scrapy. You're probably using SgmlLinkExtractor, in which case the easiest thing is to pass your own function as the process_value keyword argument to do your custom filtering.

You can customize CrawlSpider quite a lot, but if it doesn't fit your task, you should check out BaseSpider

didn't notice this proces_value argument, seems to be just what i needed. Thanks!

generate python regex at runtime to match numbers from 'n' to infinite...

python regex scrapy