问:
Distinct() returns duplicates with a user-defined type
I'm trying to write a Linq query which returns an array of objects, with unique values in their constructors.  For integer types, Distinct returns only one copy of each value, but when I try creating my list of objects, things fall apart.  I suspect it's a problem with the equality operator for my class, but when I set a breakpoint, it's never hit.

Filtering out the duplicate int in a sub-expression solves the problem, and also saves me from constructing objects that will be immediately discarded, but I'm curious why this version doesn't work.

UPDATE: 11:04 PM  Several folks have pointed out that MyType doesn't override GetHashCode().  I'm afraid I oversimplified the example.  The original MyType does indeed implement it.  I've added it below, modified only to put the hash code in a temp variable before returning it.

Running through the debugger, I see that all five invocations of GetHashCode return a different value. And since MyType only inherits from Object, this is presumably the same behavior Object would exhibit.

Would I be correct then to conclude that the hash should instead be based on the contents of Value?  This was my first attempt at overriding operators, and at the time, it didn't appear that GetHashCode needed to be particularly fancy.  (This is the first time one of my equality checks didn't seem to work properly.)

```<code>class Program
{
    static void Main(string[] args)
    {
        int[] list = { 1, 3, 4, 4, 5 };
        int[] list2 =
            (from value in list
             select value).Distinct().ToArray();    // One copy of each value.
        MyType[] distinct =
            (from value in list
             select new MyType(value)).Distinct().ToArray(); // Two objects created with 4.

        Array.ForEach(distinct, value => Console.WriteLine(value));
    }
}

class MyType
{
    public int Value { get; private set; }

    public MyType(int arg)
    {
        Value = arg;
    }

    public override int GetHashCode()
    {
        int retval = base.GetHashCode();
        return retval;
    }

    public override bool Equals(object obj)
    {
        if (obj == null)
            return false;

        MyType rhs = obj as MyType;
        if ((Object)rhs == null)
            return false;

        return this == rhs;
    }

    public static bool operator ==(MyType lhs, MyType rhs)
    {
        bool result;

        if ((Object)lhs != null && (Object)rhs != null)
            result = lhs.Value == rhs.Value;
        else
            result = (Object)lhs == (Object)rhs;

        return result;
    }

    public static bool operator !=(MyType lhs, MyType rhs)
    {
        return !(lhs == rhs);
    }
}
</code>```

答:
Your suspicion is correct,it is the equality which currently just checks the object references. Even your implementation does not do anything extra, change it to this:</p>

```<code>public override bool Equals(object obj)
{
    if (obj == null)
        return false;

    MyType rhs = obj as MyType;
    if ((Object)rhs == null)
        return false;

    return this.Value == rhs.Value;
}
</code>```

Body:
I'm trying to write a Linq query which returns an array of objects, with unique values in their constructors.  For integer types, Distinct returns only one copy of each value, but when I try creating my list of objects, things fall apart.  I suspect it's a problem with the equality operator for my class, but when I set a breakpoint, it's never hit.

Filtering out the duplicate int in a sub-expression solves the problem, and also saves me from constructing objects that will be immediately discarded, but I'm curious why this version doesn't work.

UPDATE: 11:04 PM  Several folks have pointed out that MyType doesn't override GetHashCode().  I'm afraid I oversimplified the example.  The original MyType does indeed implement it.  I've added it below, modified only to put the hash code in a temp variable before returning it.

Running through the debugger, I see that all five invocations of GetHashCode return a different value. And since MyType only inherits from Object, this is presumably the same behavior Object would exhibit.

Would I be correct then to conclude that the hash should instead be based on the contents of Value?  This was my first attempt at overriding operators, and at the time, it didn't appear that GetHashCode needed to be particularly fancy.  (This is the first time one of my equality checks didn't seem to work properly.)

class Program
{
    static void Main(string[] args)
    {
        int[] list = { 1, 3, 4, 4, 5 };
        int[] list2 =
            (from value in list
             select value).Distinct().ToArray();    // One copy of each value.
        MyType[] distinct =
            (from value in list
             select new MyType(value)).Distinct().ToArray(); // Two objects created with 4.

        Array.ForEach(distinct, value => Console.WriteLine(value));
    }
}

class MyType
{
    public int Value { get; private set; }

    public MyType(int arg)
    {
        Value = arg;
    }

    public override int GetHashCode()
    {
        int retval = base.GetHashCode();
        return retval;
    }

    public override bool Equals(object obj)
    {
        if (obj == null)
            return false;

        MyType rhs = obj as MyType;
        if ((Object)rhs == null)
            return false;

        return this == rhs;
    }

    public static bool operator ==(MyType lhs, MyType rhs)
    {
        bool result;

        if ((Object)lhs != null && (Object)rhs != null)
            result = lhs.Value == rhs.Value;
        else
            result = (Object)lhs == (Object)rhs;

        return result;
    }

    public static bool operator !=(MyType lhs, MyType rhs)
    {
        return !(lhs == rhs);
    }
}

Body:
Your suspicion is correct,it is the equality which currently just checks the object references. Even your implementation does not do anything extra, change it to this:

public override bool Equals(object obj)
{
    if (obj == null)
        return false;

    MyType rhs = obj as MyType;
    if ((Object)rhs == null)
        return false;

    return this.Value == rhs.Value;
}


来源: stackexchange

问:
WPF: change style of progressbar
How can I change the style of a progressbar in WPF?
On Windows 10 it's a straight bar, but in win 7 it's splitted in many small blocks. I want to have the bar straight as on win 10, when the application is used on win 7</p>

答:
I just lookng for a property like 'ugly-block-spacing' which I can set. Or do I have really define the whole style new?

Yes, I am afraid you will have to re-define the entire ControlTemplate from scratch. You cannot override only a part of a ControlTemplate:

WPF: Is there a way to override part of a ControlTemplate without redefining the whole style?

But you could copy the default ControlTemplate by right-clicking on a ProgressBar in design mode in Visual Studio on a Windows 10 computer, edit it as per your requirements and then use style i your application instead of the default one.

ContentLicense: CC BY-SA 3.0

Title: WPF: change style of progressbar


问:
Do invalid Google AMP pages still show up in search results?
Despite reading the AMP documentation and scouring message boards, I'm still unclear what happens to an AMP page if it fails validation. It certainly won't appear in the AMP stories carousel -- but will invalid AMP pages still be indexed by Google and appear in regular ol' search results? Or will only the "full" version specified in rel="canonical" appear?

I ask because there are some times when I actually want a page to fail AMP validation (for example, if I'm putting an interactive map that includes inline JavaScript on a page). In that case, I only want Google to index the full version, not a broken, half-functional AMP version.

答:
Invalid AMPs won't show up in Google Search at all, neither in the top stories carousel nor the 'normal' search results.

In case you're intentionally publishing invalid AMPs, I recommend removing the AMP attribute from . In this case your pages will continue to work, but won't be recognized as AMP.

However, you can easily embed interactive maps via iframe, here is a sample for Google Maps.

Body:
Invalid AMPs won't show up in Google Search at all, neither in the top stories carousel nor the 'normal' search results.

In case you're intentionally publishing invalid AMPs, I recommend removing the AMP attribute from <html amp>. In this case your pages will continue to work, but won't be recognized as AMP.

However, you can easily embed interactive maps via iframe, here is a sample for Google Maps.


问:
Regex: match words between certain characters, but not between other certain characters (in .NET)
I want to match all the words in brackets, including brackets, which are not between simple quotation marks (in .NET):

```<code>"[field1] = 'id1'" -> match "[field1]"
"[field1] = '[field2]'" -> match "[field1]"
"[ field1 ] = '[ field2 ]'" -> match "[ field1 ]"
"[ field1 ] = '[ field2 ] field3'" -> match "[ field1 ]"
"[field1] = ' [field2] ' And [field3] = '[field4] '' [field5]'" -> match "[field1]" and "[field3]"
</code>```

Any suggestion would be greatly appreciated!

答:
When you need to match things "which are not between" other things, you may think to negative lookaround:

```<code>(?<!' *)\[[^\]]*\](?! *')
</code>```

The matched group is $0.
If I am not wrong, .NET regexps allow you to use non-fixed width expressions inside lookaround (but be aware that it is very expensive), so the regex above should do the job.

In other languages this is not allowed, but there is a workaround called "possessive quantifier" (*+):

```<code>(?<!') *+(\[[^\]]*\]) *+(?!')
</code>```

The matched group is $1.
This works in all the languages in which negative lookaround and possessive quantifier are permitted (example).
About the meaning of *+, I suggest you my answer on the topic.

But maybe the computationally simplest expression is:

```<code>[^'] *+(\[[^\]]*\]) *+[^']
</code>```

The matched group is $1.

Update

This is a kind of heuristics:

```<code>(?<=^[^'\n\r]*(('[^'\n\r]*){2})*)\[[^\]]*\]
</code>```

Or, maybe faster:

```<code>\[[^\]]*\](?=[^'\n\r]*(('[^'\n\r]*){2})*$)
</code>```

The matched group is $0. Use it with multiline mode (m flag).

It will work if apexes inside the fields are not allowed.

Body:
I want to match all the words in brackets, including brackets, which are not between simple quotation marks (in .NET):

"[field1] = 'id1'" -> match "[field1]"
"[field1] = '[field2]'" -> match "[field1]"
"[ field1 ] = '[ field2 ]'" -> match "[ field1 ]"
"[ field1 ] = '[ field2 ] field3'" -> match "[ field1 ]"
"[field1] = ' [field2] ' And [field3] = '[field4] '' [field5]'" -> match "[field1]" and "[field3]"

Any suggestion would be greatly appreciated!

Body:
When you need to match things "which are not between" other things, you may think to negative lookaround:

(?<!' *)\[[^\]]*\](?! *')

The matched group is $0.
If I am not wrong, .NET regexps allow you to use non-fixed width expressions inside lookaround (but be aware that it is very expensive), so the regex above should do the job.

In other languages this is not allowed, but there is a workaround called "possessive quantifier" (*+):

(?<!') *+(\[[^\]]*\]) *+(?!')

The matched group is $1.
This works in all the languages in which negative lookaround and possessive quantifier are permitted (example).
About the meaning of *+, I suggest you my answer on the topic.

But maybe the computationally simplest expression is:

[^'] *+(\[[^\]]*\]) *+[^']

The matched group is $1.

Update

This is a kind of heuristics:

(?<=^[^'\n\r]*(('[^'\n\r]*){2})*)\[[^\]]*\]

Or, maybe faster:

\[[^\]]*\](?=[^'\n\r]*(('[^'\n\r]*){2})*$)

The matched group is $0. Use it with multiline mode (m flag).

It will work if apexes inside the fields are not allowed.


问:
How to delete a link between a GitHub repository and the previous name of the repository?
On GitHub I have a funtoo-config repository and it links to gentoo-config (which was its previous name), is there a way to delete the gentoo-config link so that I am free to create a new repository named gentoo-config?

答: Merely had to ask the GitHub staff to do this for me via the contact form. 'tis fixed now. </p>


答: I think MyType needs to implement IEquatable for this to work.</p>

ContentLicense: CC BY-SA 2.5

Title: Distinct() returns duplicates with a user-defined type


问:
JQuery percentage calculation
I`m trying to calculate and output the percentage via JQuery from two numbers that was calculated, but it fails

And didn`t worked, the HTML output is completely blank, any tips how can we show percentage from 2 numbers that was generated ?

//Edited

I tried the val as well but it didn`t worked..

I will attach snippet

$(document).ready(function() {
  $('#print-area').click(function() {
    window.print();
  });
  calcSumWatt('n');
  calcKWhDay('n');
  calcYearly('n');
  calcDepreciation('n');
  calcSumWatt('c');
  calcKWhDay('c');
  calcYearly('c');
  calcDepreciation('c');
  calcPercentage('c');

  $("input").keyup(function() {
    if ($.isNumeric($(this).val())) {
      if ($(this).attr('id') == 'c-numlamp' || $(this).attr('id') == 'n-numlamp') {
        var group = $(this).attr('id').substring(0, 1);
        if (group == 'n') {
          $('#c-numlamp').val($(this).val());
        } else {
          $('#n-numlamp').val($(this).val());
        }
      }
      if ($(this).attr('class') == 'hoursPerDay') {
        var group = $(this).attr('id').substring(0, 1);
        if (group == 'n') {
          $('#c-hours').val($(this).val());
        } else {
          $('#n-hours').val($(this).val());
        }
      }
      var group = $(this).attr('id').substring(0, 1);

      if ($(this).attr('class') == 'sumWatt') {
        calcSumWatt('n');
        calcSumWatt('c');
      } else if ($(this).attr('class') == 'hoursPerDay') {
        calcKWhDay('n');
        calcKWhDay('c');
      } else if ($(this).attr('class') == 'daysPerYear') {
        calcYearly(group);
      } else if ($(this).attr('class') == 'totalAmount') {
        calcDepreciation();
      }
    }
  });
});

function calcSumWatt(group) {

  if ($('#' + group + '-numlamp').val() && $('#' + group + '-wattlamp').val()) {
    $('#' + group + '-watts').text($('#' + group + '-numlamp').val() * $('#' + group + '-wattlamp').val());
    calcKWhDay(group);
  }

}

function calcKWhDay(group) {

  if ($('#' + group + '-watts').text() && $('#' + group + '-hours').val()) {
    $('#' + group + '-watts-day').text($('#' + group + '-watts').text() * $('#' + group + '-hours').val());
    calcDailyCons(group);
  }

}

function calcDailyCons(group) {
  var price = Number($('#' + group + '-watts-price').text().replace(/[^0-9\.]+/g, "").replace(".", ",") / 100);
  $('#' + group + '-watts-consumtion').text((($('#' + group + '-watts-day').text() * price * 30) / 1000).toFixed(2).replace(".", ",") + ' €');
  calcYearly(group);
}

function calcYearly(group) {
  if ($('#' + group + '-watts-consumtion').text() && $('#' + group + '-days').val()) {
    $('#' + group + '-yearlyCost').text(($('#' + group + '-watts-consumtion').text().replace(/[^0-9\.]+/g, "") * 12 / 100).toFixed(2).replace(".", ",") + ' €');
    calcProfits();
  }
}

function calcProfits() {
  if ($('#c-yearlyCost').text() && $('#n-yearlyCost').text()) {
    $('#y-yearly-profit').text((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100)).toFixed(2).replace(".", ",") + ' €');
    calcDepreciation();
  }
}

function calcDepreciation() {
  if ($('#d-watt').val() && $('#n-numlamp').val()) {
    var months = Math.ceil(($('#d-watt').val() * $('#n-numlamp').val() * 12 * 100) / $('#y-yearly-profit').text().replace(/[^0-9\.]+/g, ""));
    $('#d-months').text(months);
  }
}

function calcPercentage() {
  if ($('#c-yearlyCost').text() && $('#n-yearlyCost').text()) {
    $('#calcpercentage').val(Math.ceil((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 / $('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 * 100)).toFixed(2)) + ' %');
    calcDepreciation();
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="current" class="half">
  <div class="title_big">
    <p>Current status</p>
  </div>
  <div class="input-container">
    <div class="one-forth">
      <p class="plain">Count of watt</p>
      <input type="text" class="sumWatt" id="c-numlamp" value="5">
    </div>
    <div class="one-forth">
      <p class="plain">Current watt</p>
      <input type="text" class="sumWatt" id="c-wattlamp" value="50">
    </div>
    <div class="one-forth">
      <p class="plain">Hours</p>
      <input type="text" class="hoursPerDay" id="c-hours" value="10">
    </div>
    <div class="one-forth">
      <input type="text" class="daysPerYear" id="c-days" value="365" readonly>
    </div>
  </div>
  <div class="full">
    <table>
      <tr>
        <td class="three-forths">Total</td>
        <td class="one-forth" id="c-watts"></td>
      </tr>
      <tr>
        <td class="three-forths">Current Consumtion</td>
        <td class="one-forth" id="c-watts-day"></td>
      </tr>
      <tr>
        <td class="three-forths">Cost</td>
        <td class="one-forth" id="c-watts-price">0,13</td>
      </tr>
      <tr>
        <td class="three-forths">Current</td>
        <td class="one-forth" id="c-watts-consumtion"></td>
      </tr>
    </table>
  </div>
</div>

<div id="new" class="half">
  <div class="title_big">
    <p>New</p>
  </div>
  <div class="input-container">
    <div class="one-forth">
      <p class="plain">New Count</p>
      <input type="text" class="sumWatt" id="n-numlamp" value="5">
    </div>
    <div class="one-forth">
      <p class="plain">Each Consumption</p>
      <input type="text" class="sumWatt" id="n-wattlamp" value="5">
    </div>
    <div class="one-forth">
      <p class="plain">Hours</p>
      <input type="text" class="hoursPerDay" id="n-hours" value="10">
    </div>
    <div class="one-forth">
      <input type="text" class="daysPerYear" id="n-days" value="365" readonly>
    </div>
  </div>
  <div class="full">
    <table>
      <tr>
        <td class="three-forths">NEW</td>
        <td class="one-forth" id="n-watts"></td>
      </tr>
      <tr>
        <td class="three-forths">Daily</td>
        <td class="one-forth" id="n-watts-day"></td>
      </tr>
      <tr>
        <td class="three-forths">Current</td>
        <td class="one-forth" id="n-watts-price">0,13</td>
      </tr>
      <tr>
        <td class="three-forths">Months</td>
        <td class="one-forth" id="n-watts-consumtion"></td>
      </tr>
    </table>
  </div>
</div>

<div id="sum" class="full">
  <div class="two-thirds">
    <div class="title_big">
      <p>Calculation</p>
    </div>
    <table>
      <tr style="border-bottom: none;">
        <td class="three-forths"></td>
        <td class="one-forth" id="y-monthly-profit"> </td>
      </tr>
      <tr>
        <td class="three-forths">Current</td>
        <td class="one-forth" id="c-yearlyCost"></td>
      </tr>
      <tr>
        <td class="three-forths">Will be</td>
        <td class="one-forth" id="n-yearlyCost"></td>
      </tr>
      <tr>
        <td class="three-forths">Every Year</td>
        <td class="one-forth" id="y-yearly-profit"></td>
      </tr>
      <br>

      <tr>
        <td class="three-forths">Percent</td>
        <td class="one-forth" id="calcpercentage"></td>
      </tr>

    </table>
  </div>
</div></code>```

答:
Now you are just asigning like a JavaScript variable, you should not do that with a selector. To be able to append some value/text to an HTML element you have to use text() or html() methods. Also, I think that the concatenation with the % symbol should be outside the Math.ceil().

So change this:

```<code>$('#calcpercentage') = Math.ceil((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 / $('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 * 100)).toFixed(2) + ' %');
</code>```

to this:

```<code>$('#calcpercentage').html(Math.ceil((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 / $('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 * 100)).toFixed(2)) + ' %');
</code>```

If $('#calcpercentage') element is an input you will have to use val() instead of html() like this:

```<code>$('#calcpercentage').val(Math.ceil((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 / $('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 * 100)).toFixed(2))  + ' %');
</code>```

Working snippet:

$(document).ready(function() {
  $('#print-area').click(function() {
    window.print();
  });
  calcSumWatt('n');
  calcKWhDay('n');
  calcYearly('n');
  calcDepreciation('n');
  calcSumWatt('c');
  calcKWhDay('c');
  calcYearly('c');
  calcDepreciation('c');
  calcPercentage('c');

  $("input").keyup(function() {
  calcPercentage('c');
    if ($.isNumeric($(this).val())) {
      if ($(this).attr('id') == 'c-numlamp' || $(this).attr('id') == 'n-numlamp') {
        var group = $(this).attr('id').substring(0, 1);
        if (group == 'n') {
          $('#c-numlamp').val($(this).val());
        } else {
          $('#n-numlamp').val($(this).val());
        }
      }
      if ($(this).attr('class') == 'hoursPerDay') {
        var group = $(this).attr('id').substring(0, 1);
        if (group == 'n') {
          $('#c-hours').val($(this).val());
        } else {
          $('#n-hours').val($(this).val());
        }
      }
      var group = $(this).attr('id').substring(0, 1);

      if ($(this).attr('class') == 'sumWatt') {
        calcSumWatt('n');
        calcSumWatt('c');
      } else if ($(this).attr('class') == 'hoursPerDay') {
        calcKWhDay('n');
        calcKWhDay('c');
      } else if ($(this).attr('class') == 'daysPerYear') {
        calcYearly(group);
      } else if ($(this).attr('class') == 'totalAmount') {
        calcDepreciation();
      }
    }
  });
});

function calcSumWatt(group) {

  if ($('#' + group + '-numlamp').val() && $('#' + group + '-wattlamp').val()) {
    $('#' + group + '-watts').text($('#' + group + '-numlamp').val() * $('#' + group + '-wattlamp').val());
    calcKWhDay(group);
  }

}

function calcKWhDay(group) {

  if ($('#' + group + '-watts').text() && $('#' + group + '-hours').val()) {
    $('#' + group + '-watts-day').text($('#' + group + '-watts').text() * $('#' + group + '-hours').val());
    calcDailyCons(group);
  }

}

function calcDailyCons(group) {
  var price = Number($('#' + group + '-watts-price').text().replace(/[^0-9\.]+/g, "").replace(".", ",") / 100);
  $('#' + group + '-watts-consumtion').text((($('#' + group + '-watts-day').text() * price * 30) / 1000).toFixed(2).replace(".", ",") + ' €');
  calcYearly(group);
}

function calcYearly(group) {
  if ($('#' + group + '-watts-consumtion').text() && $('#' + group + '-days').val()) {
    $('#' + group + '-yearlyCost').text(($('#' + group + '-watts-consumtion').text().replace(/[^0-9\.]+/g, "") * 12 / 100).toFixed(2).replace(".", ",") + ' €');
    calcProfits();
  }
}

function calcProfits() {
  if ($('#c-yearlyCost').text() && $('#n-yearlyCost').text()) {
    $('#y-yearly-profit').text((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100)).toFixed(2).replace(".", ",") + ' €');
    calcDepreciation();
  }
}

function calcDepreciation() {
  if ($('#d-watt').val() && $('#n-numlamp').val()) {
    var months = Math.ceil(($('#d-watt').val() * $('#n-numlamp').val() * 12 * 100) / $('#y-yearly-profit').text().replace(/[^0-9\.]+/g, ""));
    $('#d-months').text(months);
  }
}

function calcPercentage() {
  if ($('#c-yearlyCost').text() && $('#n-yearlyCost').text()) {
    $('#calcpercentage').html(Math.ceil((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 / $('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 * 100)).toFixed(2)) + ' %');
    calcDepreciation();
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="current" class="half">
  <div class="title_big">
    <p>Current status</p>
  </div>
  <div class="input-container">
    <div class="one-forth">
      <p class="plain">Count of watt</p>
      <input type="text" class="sumWatt" id="c-numlamp" value="5">
    </div>
    <div class="one-forth">
      <p class="plain">Current watt</p>
      <input type="text" class="sumWatt" id="c-wattlamp" value="50">
    </div>
    <div class="one-forth">
      <p class="plain">Hours</p>
      <input type="text" class="hoursPerDay" id="c-hours" value="10">
    </div>
    <div class="one-forth">
      <input type="text" class="daysPerYear" id="c-days" value="365" readonly>
    </div>
  </div>
  <div class="full">
    <table>
      <tr>
        <td class="three-forths">Total</td>
        <td class="one-forth" id="c-watts"></td>
      </tr>
      <tr>
        <td class="three-forths">Current Consumtion</td>
        <td class="one-forth" id="c-watts-day"></td>
      </tr>
      <tr>
        <td class="three-forths">Cost</td>
        <td class="one-forth" id="c-watts-price">0,13</td>
      </tr>
      <tr>
        <td class="three-forths">Current</td>
        <td class="one-forth" id="c-watts-consumtion"></td>
      </tr>
    </table>
  </div>
</div>

<div id="new" class="half">
  <div class="title_big">
    <p>New</p>
  </div>
  <div class="input-container">
    <div class="one-forth">
      <p class="plain">New Count</p>
      <input type="text" class="sumWatt" id="n-numlamp" value="5">
    </div>
    <div class="one-forth">
      <p class="plain">Each Consumption</p>
      <input type="text" class="sumWatt" id="n-wattlamp" value="5">
    </div>
    <div class="one-forth">
      <p class="plain">Hours</p>
      <input type="text" class="hoursPerDay" id="n-hours" value="10">
    </div>
    <div class="one-forth">
      <input type="text" class="daysPerYear" id="n-days" value="365" readonly>
    </div>
  </div>
  <div class="full">
    <table>
      <tr>
        <td class="three-forths">NEW</td>
        <td class="one-forth" id="n-watts"></td>
      </tr>
      <tr>
        <td class="three-forths">Daily</td>
        <td class="one-forth" id="n-watts-day"></td>
      </tr>
      <tr>
        <td class="three-forths">Current</td>
        <td class="one-forth" id="n-watts-price">0,13</td>
      </tr>
      <tr>
        <td class="three-forths">Months</td>
        <td class="one-forth" id="n-watts-consumtion"></td>
      </tr>
    </table>
  </div>
</div>

<div id="sum" class="full">
  <div class="two-thirds">
    <div class="title_big">
      <p>Calculation</p>
    </div>
    <table>
      <tr style="border-bottom: none;">
        <td class="three-forths"></td>
        <td class="one-forth" id="y-monthly-profit"> </td>
      </tr>
      <tr>
        <td class="three-forths">Current</td>
        <td class="one-forth" id="c-yearlyCost"></td>
      </tr>
      <tr>
        <td class="three-forths">Will be</td>
        <td class="one-forth" id="n-yearlyCost"></td>
      </tr>
      <tr>
        <td class="three-forths">Every Year</td>
        <td class="one-forth" id="y-yearly-profit"></td>
      </tr>
      <br>

      <tr>
        <td class="three-forths">Percent</td>
        <td class="one-forth" id="calcpercentage"></td>
      </tr>

    </table>
  </div>
</div></code>```

Title: JQuery percentage calculation

Body:
I`m trying to calculate and output the percentage via JQuery from two numbers that was calculated, but it fails

And didn`t worked, the HTML output is completely blank, any tips how can we show percentage from 2 numbers that was generated ?

//Edited

I tried the val as well but it didn`t worked..

I will attach snippet

$(document).ready(function() {
  $('#print-area').click(function() {
    window.print();
  });
  calcSumWatt('n');
  calcKWhDay('n');
  calcYearly('n');
  calcDepreciation('n');
  calcSumWatt('c');
  calcKWhDay('c');
  calcYearly('c');
  calcDepreciation('c');
  calcPercentage('c');

  $("input").keyup(function() {
    if ($.isNumeric($(this).val())) {
      if ($(this).attr('id') == 'c-numlamp' || $(this).attr('id') == 'n-numlamp') {
        var group = $(this).attr('id').substring(0, 1);
        if (group == 'n') {
          $('#c-numlamp').val($(this).val());
        } else {
          $('#n-numlamp').val($(this).val());
        }
      }
      if ($(this).attr('class') == 'hoursPerDay') {
        var group = $(this).attr('id').substring(0, 1);
        if (group == 'n') {
          $('#c-hours').val($(this).val());
        } else {
          $('#n-hours').val($(this).val());
        }
      }
      var group = $(this).attr('id').substring(0, 1);

      if ($(this).attr('class') == 'sumWatt') {
        calcSumWatt('n');
        calcSumWatt('c');
      } else if ($(this).attr('class') == 'hoursPerDay') {
        calcKWhDay('n');
        calcKWhDay('c');
      } else if ($(this).attr('class') == 'daysPerYear') {
        calcYearly(group);
      } else if ($(this).attr('class') == 'totalAmount') {
        calcDepreciation();
      }
    }
  });
});

function calcSumWatt(group) {

  if ($('#' + group + '-numlamp').val() && $('#' + group + '-wattlamp').val()) {
    $('#' + group + '-watts').text($('#' + group + '-numlamp').val() * $('#' + group + '-wattlamp').val());
    calcKWhDay(group);
  }

}

function calcKWhDay(group) {

  if ($('#' + group + '-watts').text() && $('#' + group + '-hours').val()) {
    $('#' + group + '-watts-day').text($('#' + group + '-watts').text() * $('#' + group + '-hours').val());
    calcDailyCons(group);
  }

}

function calcDailyCons(group) {
  var price = Number($('#' + group + '-watts-price').text().replace(/[^0-9\.]+/g, "").replace(".", ",") / 100);
  $('#' + group + '-watts-consumtion').text((($('#' + group + '-watts-day').text() * price * 30) / 1000).toFixed(2).replace(".", ",") + ' €');
  calcYearly(group);
}

function calcYearly(group) {
  if ($('#' + group + '-watts-consumtion').text() && $('#' + group + '-days').val()) {
    $('#' + group + '-yearlyCost').text(($('#' + group + '-watts-consumtion').text().replace(/[^0-9\.]+/g, "") * 12 / 100).toFixed(2).replace(".", ",") + ' €');
    calcProfits();
  }
}

function calcProfits() {
  if ($('#c-yearlyCost').text() && $('#n-yearlyCost').text()) {
    $('#y-yearly-profit').text((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100)).toFixed(2).replace(".", ",") + ' €');
    calcDepreciation();
  }
}

function calcDepreciation() {
  if ($('#d-watt').val() && $('#n-numlamp').val()) {
    var months = Math.ceil(($('#d-watt').val() * $('#n-numlamp').val() * 12 * 100) / $('#y-yearly-profit').text().replace(/[^0-9\.]+/g, ""));
    $('#d-months').text(months);
  }
}

function calcPercentage() {
  if ($('#c-yearlyCost').text() && $('#n-yearlyCost').text()) {
    $('#calcpercentage').val(Math.ceil((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 / $('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 * 100)).toFixed(2)) + ' %');
    calcDepreciation();
  }
}

Current status

Count of watt

      <input type="text" class="sumWatt" id="c-numlamp" value="5">

Current watt

      <input type="text" class="sumWatt" id="c-wattlamp" value="50">

Hours

      <input type="text" class="hoursPerDay" id="c-hours" value="10">

      <input type="text" class="daysPerYear" id="c-days" value="365" readonly>

        Total

        Current Consumtion

        Cost
        0,13

        Current

New

New Count

      <input type="text" class="sumWatt" id="n-numlamp" value="5">

Each Consumption

      <input type="text" class="sumWatt" id="n-wattlamp" value="5">

Hours

      <input type="text" class="hoursPerDay" id="n-hours" value="10">

      <input type="text" class="daysPerYear" id="n-days" value="365" readonly>

        NEW

        Daily

        Current
        0,13

        Months

Calculation

        Current

        Will be

        Every Year

        Percent

Body:
Now you are just asigning like a JavaScript variable, you should not do that with a selector. To be able to append some value/text to an HTML element you have to use text() or html() methods. Also, I think that the concatenation with the % symbol should be outside the Math.ceil().

So change this:

$('#calcpercentage') = Math.ceil((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 / $('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 * 100)).toFixed(2) + ' %');

to this:

$('#calcpercentage').html(Math.ceil((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 / $('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 * 100)).toFixed(2)) + ' %');

If $('#calcpercentage') element is an input you will have to use val() instead of html() like this:

$('#calcpercentage').val(Math.ceil((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 / $('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 * 100)).toFixed(2))  + ' %');

Working snippet:

$(document).ready(function() {
  $('#print-area').click(function() {
    window.print();
  });
  calcSumWatt('n');
  calcKWhDay('n');
  calcYearly('n');
  calcDepreciation('n');
  calcSumWatt('c');
  calcKWhDay('c');
  calcYearly('c');
  calcDepreciation('c');
  calcPercentage('c');

  $("input").keyup(function() {
  calcPercentage('c');
    if ($.isNumeric($(this).val())) {
      if ($(this).attr('id') == 'c-numlamp' || $(this).attr('id') == 'n-numlamp') {
        var group = $(this).attr('id').substring(0, 1);
        if (group == 'n') {
          $('#c-numlamp').val($(this).val());
        } else {
          $('#n-numlamp').val($(this).val());
        }
      }
      if ($(this).attr('class') == 'hoursPerDay') {
        var group = $(this).attr('id').substring(0, 1);
        if (group == 'n') {
          $('#c-hours').val($(this).val());
        } else {
          $('#n-hours').val($(this).val());
        }
      }
      var group = $(this).attr('id').substring(0, 1);

      if ($(this).attr('class') == 'sumWatt') {
        calcSumWatt('n');
        calcSumWatt('c');
      } else if ($(this).attr('class') == 'hoursPerDay') {
        calcKWhDay('n');
        calcKWhDay('c');
      } else if ($(this).attr('class') == 'daysPerYear') {
        calcYearly(group);
      } else if ($(this).attr('class') == 'totalAmount') {
        calcDepreciation();
      }
    }
  });
});

function calcSumWatt(group) {

  if ($('#' + group + '-numlamp').val() && $('#' + group + '-wattlamp').val()) {
    $('#' + group + '-watts').text($('#' + group + '-numlamp').val() * $('#' + group + '-wattlamp').val());
    calcKWhDay(group);
  }

}

function calcKWhDay(group) {

  if ($('#' + group + '-watts').text() && $('#' + group + '-hours').val()) {
    $('#' + group + '-watts-day').text($('#' + group + '-watts').text() * $('#' + group + '-hours').val());
    calcDailyCons(group);
  }

}

function calcDailyCons(group) {
  var price = Number($('#' + group + '-watts-price').text().replace(/[^0-9\.]+/g, "").replace(".", ",") / 100);
  $('#' + group + '-watts-consumtion').text((($('#' + group + '-watts-day').text() * price * 30) / 1000).toFixed(2).replace(".", ",") + ' €');
  calcYearly(group);
}

function calcYearly(group) {
  if ($('#' + group + '-watts-consumtion').text() && $('#' + group + '-days').val()) {
    $('#' + group + '-yearlyCost').text(($('#' + group + '-watts-consumtion').text().replace(/[^0-9\.]+/g, "") * 12 / 100).toFixed(2).replace(".", ",") + ' €');
    calcProfits();
  }
}

function calcProfits() {
  if ($('#c-yearlyCost').text() && $('#n-yearlyCost').text()) {
    $('#y-yearly-profit').text((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100)).toFixed(2).replace(".", ",") + ' €');
    calcDepreciation();
  }
}

function calcDepreciation() {
  if ($('#d-watt').val() && $('#n-numlamp').val()) {
    var months = Math.ceil(($('#d-watt').val() * $('#n-numlamp').val() * 12 * 100) / $('#y-yearly-profit').text().replace(/[^0-9\.]+/g, ""));
    $('#d-months').text(months);
  }
}

function calcPercentage() {
  if ($('#c-yearlyCost').text() && $('#n-yearlyCost').text()) {
    $('#calcpercentage').html(Math.ceil((($('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 - $('#n-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 / $('#c-yearlyCost').text().replace(/[^0-9\.]+/g, "") / 100 * 100)).toFixed(2)) + ' %');
    calcDepreciation();
  }
}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="current" class="half">
  <div class="title_big">
    <p>Current status</p>
  </div>
  <div class="input-container">
    <div class="one-forth">
      <p class="plain">Count of watt</p>
      <input type="text" class="sumWatt" id="c-numlamp" value="5">
    </div>
    <div class="one-forth">
      <p class="plain">Current watt</p>
      <input type="text" class="sumWatt" id="c-wattlamp" value="50">
    </div>
    <div class="one-forth">
      <p class="plain">Hours</p>
      <input type="text" class="hoursPerDay" id="c-hours" value="10">
    </div>
    <div class="one-forth">
      <input type="text" class="daysPerYear" id="c-days" value="365" readonly>
    </div>
  </div>
  <div class="full">
    <table>
      <tr>
        <td class="three-forths">Total</td>
        <td class="one-forth" id="c-watts"></td>
      </tr>
      <tr>
        <td class="three-forths">Current Consumtion</td>
        <td class="one-forth" id="c-watts-day"></td>
      </tr>
      <tr>
        <td class="three-forths">Cost</td>
        <td class="one-forth" id="c-watts-price">0,13</td>
      </tr>
      <tr>
        <td class="three-forths">Current</td>
        <td class="one-forth" id="c-watts-consumtion"></td>
      </tr>
    </table>
  </div>
</div>

<div id="new" class="half">
  <div class="title_big">
    <p>New</p>
  </div>
  <div class="input-container">
    <div class="one-forth">
      <p class="plain">New Count</p>
      <input type="text" class="sumWatt" id="n-numlamp" value="5">
    </div>
    <div class="one-forth">
      <p class="plain">Each Consumption</p>
      <input type="text" class="sumWatt" id="n-wattlamp" value="5">
    </div>
    <div class="one-forth">
      <p class="plain">Hours</p>
      <input type="text" class="hoursPerDay" id="n-hours" value="10">
    </div>
    <div class="one-forth">
      <input type="text" class="daysPerYear" id="n-days" value="365" readonly>
    </div>
  </div>
  <div class="full">
    <table>
      <tr>
        <td class="three-forths">NEW</td>
        <td class="one-forth" id="n-watts"></td>
      </tr>
      <tr>
        <td class="three-forths">Daily</td>
        <td class="one-forth" id="n-watts-day"></td>
      </tr>
      <tr>
        <td class="three-forths">Current</td>
        <td class="one-forth" id="n-watts-price">0,13</td>
      </tr>
      <tr>
        <td class="three-forths">Months</td>
        <td class="one-forth" id="n-watts-consumtion"></td>
      </tr>
    </table>
  </div>
</div>

<div id="sum" class="full">
  <div class="two-thirds">
    <div class="title_big">
      <p>Calculation</p>
    </div>
    <table>
      <tr style="border-bottom: none;">
        <td class="three-forths"></td>
        <td class="one-forth" id="y-monthly-profit"> </td>
      </tr>
      <tr>
        <td class="three-forths">Current</td>
        <td class="one-forth" id="c-yearlyCost"></td>
      </tr>
      <tr>
        <td class="three-forths">Will be</td>
        <td class="one-forth" id="n-yearlyCost"></td>
      </tr>
      <tr>
        <td class="three-forths">Every Year</td>
        <td class="one-forth" id="y-yearly-profit"></td>
      </tr>
      <br>

      <tr>
        <td class="three-forths">Percent</td>
        <td class="one-forth" id="calcpercentage"></td>
      </tr>

    </table>
  </div>
</div>


问:
Replicate a VLOOKUP, using nested ifelse
What is the operator for 'Equals' in the below question ?</p>

```<code>S1$CountryNo <- ifelse(S1$Country = 'UNITED KINGDOM' , 1 , ifelse(S1$Country = 'FRANCE' , 2 , 3)
</code>```

答:
If you have a long list of counties you could also consider a lookup vector:</p>

```<code>S1 <- data.frame(CountryNo = c("UNITED KINGDOM", "FRANCE", "DENMARK"))

# Lookup vector
lookup <- c("UNITED KINGDOM" = 1, "FRANCE" = 2)

# Replace known countries - unknown (DENMARK) will be NA
S1$CountryNo <- lookup[S1$CountryNo]

# Replace NA countries with 3
S1[is.na(S1$CountryNo), "CountryNo"] <- 3
</code>```

Body:
What is the operator for 'Equals' in the below question ?

S1$CountryNo <- ifelse(S1$Country = 'UNITED KINGDOM' , 1 , ifelse(S1$Country = 'FRANCE' , 2 , 3)

Body:
If you have a long list of counties you could also consider a lookup vector:

S1 <- data.frame(CountryNo = c("UNITED KINGDOM", "FRANCE", "DENMARK"))

# Lookup vector
lookup <- c("UNITED KINGDOM" = 1, "FRANCE" = 2)

# Replace known countries - unknown (DENMARK) will be NA
S1$CountryNo <- lookup[S1$CountryNo]

# Replace NA countries with 3
S1[is.na(S1$CountryNo), "CountryNo"] <- 3


问:
Are the decimal places in a CSS width respected?
Something I've been wondering for a while whilst doing CSS design.

Are decimal places in CSS widths respected? Or are they rounded?

.percentage {
  width: 49.5%;
}
```
<p>or</p>
<pre class="lang-css prettyprint-override"><code>.pixel {
  width: 122.5px;
}
</code>```

答:
The width will be rounded to an integer number of pixels.

I don't know if every browser will round it the same way though. They all seem to have a different strategy when rounding sub-pixel percentages. If you're interested in the details of sub-pixel rounding in different browsers, there's an excellent article on ElastiCSS.

edit: I tested @Skilldrick's demo in some browsers for the sake of curiosity. When using fractional pixel values (not percentages, they work as suggested in the article I linked) IE9p7 and FF4b7 seem to round to the nearest pixel, while Opera 11b, Chrome 9.0.587.0 and Safari 5.0.3 truncate the decimal places. Not that I hoped that they had something in common after all...

ContentLicense: CC BY-SA 4.0

Body:
Something I've been wondering for a while whilst doing CSS design.

Are decimal places in CSS widths respected? Or are they rounded?

.percentage {
  width: 49.5%;
}

or

.pixel {
  width: 122.5px;
}


问:
OPC UA Read string[] data type by nodes with path
This is a example.

```<code>Node Path = "Tool/Manager/Name"
</code>```

Node data Type = "string" and data is "Jone"

When I use nodesToRead.Add(new NodeId(path, 6)); Is work!

But, if I change the node data to string[]{"Jone","Peter","Himari"}

When I use nodesToRead.Add(new NodeId(path, 6)), It return a System.string[]. and I need to use some methods to get string[0] data.

How can I read the "Jone" by only node path without do some methods to get "Jone"?

This is used Softing(Software) to read my server. It read an array type. {AA,NN,CC}

I want to know how to read each elements by set Browse Name?

Example: only read "AA" by set Browse Name?.

enter image description here

Because the Siemens OPC Server can read read each elements by set Browse Name.

It's Browse Name can set like AxisNameList[u1,1] to read the array{1},and It Configuration Browse only one node like "AxisNameList" Node.

if i publish this path "AxisNameList", it will by request array[0] data.

if i publish this path "AxisNameList[u1,1]", it will by request array[1] data.

If i want to achieve this function, How do i modify my OPC UA Server?

答:
OPC UA Specification Part4

5.10.2 Read Service
Parameters of Read Service is defined as following

Read Service Parameters

The type of nodesToRead[] is ReadValueId,
which is defined as following

ReadValueId DataType

indexRange is the parameter you need.

So, OPC UA supports reading a single element of an array.
But i don't known if your SDK support it.

here is the datatype of readparameters in the sdk i used.

```<code>struct ReadParameters
{
     double MaxAge;
     OpcUa::TimestampsToReturn TimestampsToReturn;
     std::vector<OpcUa::ReadValueId> AttributesToRead;

     ReadParameters();
};
struct ReadValueId
{
     OpcUa::NodeId NodeId;
     OpcUa::AttributeId AttributeId;
     std::string IndexRange;
     OpcUa::QualifiedName DataEncoding;
};
</code>```

Body:
This is a example.

Node Path = "Tool/Manager/Name"

Node data Type = "string" and data is "Jone"

When I use nodesToRead.Add(new NodeId(path, 6)); Is work!

But, if I change the node data to string[]{"Jone","Peter","Himari"}

When I use nodesToRead.Add(new NodeId(path, 6)), It return a System.string[]. and I need to use some methods to get string[0] data.

How can I read the "Jone" by only node path without do some methods to get "Jone"?

This is used Softing(Software) to read my server. It read an array type. {AA,NN,CC}

I want to know how to read each elements by set Browse Name?

Example: only read "AA" by set Browse Name?.

enter image description here

Because the Siemens OPC Server can read read each elements by set Browse Name.

It's Browse Name can set like AxisNameList[u1,1] to read the array{1},and It Configuration Browse only one node like "AxisNameList" Node.

if i publish this path "AxisNameList", it will by request array[0] data.

if i publish this path "AxisNameList[u1,1]", it will by request array[1] data.

If i want to achieve this function, How do i modify my OPC UA Server?

Body:
OPC UA Specification Part4

5.10.2 Read Service
Parameters of Read Service is defined as following

Read Service Parameters

The type of nodesToRead[] is ReadValueId,
which is defined as following

ReadValueId DataType

indexRange is the parameter you need.

So, OPC UA supports reading a single element of an array.
But i don't known if your SDK support it.

here is the datatype of readparameters in the sdk i used.

struct ReadParameters
{
     double MaxAge;
     OpcUa::TimestampsToReturn TimestampsToReturn;
     std::vector<OpcUa::ReadValueId> AttributesToRead;

     ReadParameters();
};
struct ReadValueId
{
     OpcUa::NodeId NodeId;
     OpcUa::AttributeId AttributeId;
     std::string IndexRange;
     OpcUa::QualifiedName DataEncoding;
};


问:
AnjularJs integration with Spring boot
I need to call index() method in java class. But I tried this way it is not working.

It is going up to console.log('coming here....'); in controller.js, after that http path is not recognizing.

```<code>@RestController
public class DatumBoxShedule {

    @Autowired
    private DatumService datumService;

    @RequestMapping(value = "/loadIndex", produces = MediaType.APPLICATION_JSON_VALUE,  method = RequestMethod.GET)
    public String index() throws IOException {

    }
}
</code>```

controller.js

```<code>app.controller('datumBoxShedule', function($scope, $http) {
    $scope.newTodo = {};

    $scope.loadIndex = function(){
         console.log('coming here....');
        $http.get('loadIndex')
        .success(function(data, status, headers, config) {
            $scope.todos = data;
         })
        .error(function(data, status, headers, config) {
              alert('Error loading DatumBoxShedule');
        });
    };

    $scope.loadIndex();
});
</code>```

答:
Is the Angular project part of the Spring project?

Are other mappings working (in other words: is the REST-Service running)?
If not: do you have an embedded container like Tomcat in your depenedencies?

For example, you could add the dependency for Tomcat to your project:

```<code><dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
</code>```

Title: AnjularJs integration with Spring boot

Body:
I need to call index() method in java class. But I tried this way it is not working.

It is going up to console.log('coming here....'); in controller.js, after that http path is not recognizing.

@RestController
public class DatumBoxShedule {

    @Autowired
    private DatumService datumService;

    @RequestMapping(value = "/loadIndex", produces = MediaType.APPLICATION_JSON_VALUE,  method = RequestMethod.GET)
    public String index() throws IOException {

    }
}

controller.js

app.controller('datumBoxShedule', function($scope, $http) {
    $scope.newTodo = {};

    $scope.loadIndex = function(){
         console.log('coming here....');
        $http.get('loadIndex')
        .success(function(data, status, headers, config) {
            $scope.todos = data;
         })
        .error(function(data, status, headers, config) {
              alert('Error loading DatumBoxShedule');
        });
    };

    $scope.loadIndex();
});

Body:
Is the Angular project part of the Spring project?

Are other mappings working (in other words: is the REST-Service running)?
If not: do you have an embedded container like Tomcat in your depenedencies?

For example, you could add the dependency for Tomcat to your project:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>


问:
Creating Azure storage container fails when deploying on weblogic 12c
I have a very simple spring boot project for testing that successfully creates a container in an existing Azure Storage Account when running standalone. But when deployed in a WebLogic 12c server it fails with an error I can't find on the internet.

The proyect has a Controller, an Application, a weblogic.xml and the pom.xml, nothing more. when running it locally works perfectly, creating a container with the connection string of the account (with de account key) and the name of the container.

Here is the code of the Controller class:

```<code>package com.example;

import java.io.IOException;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.microsoft.azure.storage.CloudStorageAccount;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.blob.CloudBlobClient;
import com.microsoft.azure.storage.blob.CloudBlobContainer;

@RestController
public class DemoController {

    @RequestMapping(value = "/createAzureContainer", method = RequestMethod.GET)
    void createAzureContainer()
            throws URISyntaxException, StorageException, IOException, InvalidKeyException {

        CloudStorageAccount storageAccount =
                CloudStorageAccount.parse("DefaultEndpointsProtocol=https;" +
                        "AccountName=[accountName];AccountKey=[accountKey]");
        CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
        CloudBlobContainer container = blobClient.getContainerReference("[containerName]");
        container.createIfNotExists();
        container.downloadAttributes();
    }
}
</code>```

And the code of the Application class:

```<code>package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.WebApplicationInitializer;

@ComponentScan
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer
        implements WebApplicationInitializer {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(DemoApplication.class);
    }
}
</code>```

This is the weblogic.xml, located in src/main/webapp/WEB-INF:

```<code><?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:context-root>demo</wls:context-root>
    <wls:container-descriptor>
        <wls:prefer-application-packages>
        <wls:package-name>org.slf4j.*</wls:package-name>
        <wls:package-name>org.springframework.*</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>
</code>```

And finally the pom.xml:

```<code><?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>demo</name>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-storage</artifactId>
            <version>5.0.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>false</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
</code>```

With this anyone with an Azure Storage Account can try to run standalone and create containers. But when deploying to a WebLogic 12c the following line:

```<code>        container.createIfNotExists();
</code>```

fails with the following exception, which sounds to me like the problem you may have when uploading a blob, but can't find any reference about it in the internet searching about containers:

```<code>com.microsoft.azure.storage.StorageException: The server encountered an unknown failure: Length Required
    at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:101) ~[azure-storage-5.0.0.jar:na]
    at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:305) ~[azure-storage-5.0.0.jar:na]
    at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:175) ~[azure-storage-5.0.0.jar:na]
    at com.microsoft.azure.storage.blob.CloudBlobContainer.create(CloudBlobContainer.java:261) ~[azure-storage-5.0.0.jar:na]
    at com.microsoft.azure.storage.blob.CloudBlobContainer.createIfNotExists(CloudBlobContainer.java:385) ~[azure-storage-5.0.0.jar:na]
    at com.microsoft.azure.storage.blob.CloudBlobContainer.createIfNotExists(CloudBlobContainer.java:326) ~[azure-storage-5.0.0.jar:na]
    at com.example.DemoController.createAzureContainer(DemoController.java:66) ~[_wl_cls_gen.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) ~[javax.servlet.javax.servlet-api.jar:3.1.0]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet.javax.servlet-api.jar:3.1.0]
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:115) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter.access$000(ErrorPageFilter.java:59) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:90) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:108) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3683) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3649) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326) [com.oracle.weblogic.security.subject.jar:12.2.1.2]
    at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197) [com.oracle.weblogic.security.subject.jar:12.2.1.2]
    at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2433) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2281) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2259) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1691) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1651) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:270) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348) [com.bea.core.utils.full.jar:12.2.1.2]
    at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333) [com.bea.core.utils.full.jar:12.2.1.2]
    at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54) [com.oracle.weblogic.work.jar:12.2.1.2]
    at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41) [com.bea.core.weblogic.workmanager.jar:12.2.1.2]
    at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:640) [com.bea.core.weblogic.workmanager.jar:12.2.1.2]
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:406) [com.bea.core.weblogic.workmanager.jar:12.2.1.2]
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:346) [com.bea.core.weblogic.workmanager.jar:12.2.1.2]
</code>```

Any help will be really appreciated, thanks for your time.

答:
According to your error information & Azure Storage offical error codes, the issue was caused by missing Content-Length header, please see below.

You can try to use Fiddler to check the error code 411 & response to make sure the issue reason when the exception happened.

Per my exception, I think WebLogic server caused the missing Content-Length header issue. I searched and discovered WebLogic server use some strategies for backward-compatibility to use own implementation for some standard like JAX-RS, JAX-PRC, etc.

So I think you can try to refer to Oracle offical document Invoking Web Services from Client Applications and WebLogic Server & Fusion Middleware Developing and Securing RESTful Web Services for Oracle WebLogic Server 12.1.3 to resolve the issue.

Some solutions I think may help resolving it.

According to the document 1, trying to add the code below.

```<code>// Setup the global JAX-RPC service factory
System.setProperty( "javax.xml.rpc.ServiceFactory", "weblogic.webservice.core.rpc.ServiceFactoryImpl");
</code>```

Try to Configuring the Web Application to Use Jersey 2.5.1 (JAX-RS 2.0 RI).

Try to refer to Developing RESTful Web Service Clients to change or setup for your code.

Hope it helps.

Body:
I have a very simple spring boot project for testing that successfully creates a container in an existing Azure Storage Account when running standalone. But when deployed in a WebLogic 12c server it fails with an error I can't find on the internet.

The proyect has a Controller, an Application, a weblogic.xml and the pom.xml, nothing more. when running it locally works perfectly, creating a container with the connection string of the account (with de account key) and the name of the container.

Here is the code of the Controller class:

package com.example;

import java.io.IOException;
import java.net.URISyntaxException;
import java.security.InvalidKeyException;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.microsoft.azure.storage.CloudStorageAccount;
import com.microsoft.azure.storage.StorageException;
import com.microsoft.azure.storage.blob.CloudBlobClient;
import com.microsoft.azure.storage.blob.CloudBlobContainer;

@RestController
public class DemoController {

    @RequestMapping(value = "/createAzureContainer", method = RequestMethod.GET)
    void createAzureContainer()
            throws URISyntaxException, StorageException, IOException, InvalidKeyException {

        CloudStorageAccount storageAccount =
                CloudStorageAccount.parse("DefaultEndpointsProtocol=https;" +
                        "AccountName=[accountName];AccountKey=[accountKey]");
        CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
        CloudBlobContainer container = blobClient.getContainerReference("[containerName]");
        container.createIfNotExists();
        container.downloadAttributes();
    }
}

And the code of the Application class:

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.WebApplicationInitializer;

@ComponentScan
@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer
        implements WebApplicationInitializer {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(DemoApplication.class);
    }
}

This is the weblogic.xml, located in src/main/webapp/WEB-INF:

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <wls:context-root>demo</wls:context-root>
    <wls:container-descriptor>
        <wls:prefer-application-packages>
        <wls:package-name>org.slf4j.*</wls:package-name>
        <wls:package-name>org.springframework.*</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>

And finally the pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>demo</name>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.2.RELEASE</version>
        <relativePath/>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-storage</artifactId>
            <version>5.0.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>false</addDefaultImplementationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

With this anyone with an Azure Storage Account can try to run standalone and create containers. But when deploying to a WebLogic 12c the following line:

        container.createIfNotExists();

fails with the following exception, which sounds to me like the problem you may have when uploading a blob, but can't find any reference about it in the internet searching about containers:

com.microsoft.azure.storage.StorageException: The server encountered an unknown failure: Length Required
    at com.microsoft.azure.storage.StorageException.translateException(StorageException.java:101) ~[azure-storage-5.0.0.jar:na]
    at com.microsoft.azure.storage.core.StorageRequest.materializeException(StorageRequest.java:305) ~[azure-storage-5.0.0.jar:na]
    at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:175) ~[azure-storage-5.0.0.jar:na]
    at com.microsoft.azure.storage.blob.CloudBlobContainer.create(CloudBlobContainer.java:261) ~[azure-storage-5.0.0.jar:na]
    at com.microsoft.azure.storage.blob.CloudBlobContainer.createIfNotExists(CloudBlobContainer.java:385) ~[azure-storage-5.0.0.jar:na]
    at com.microsoft.azure.storage.blob.CloudBlobContainer.createIfNotExists(CloudBlobContainer.java:326) ~[azure-storage-5.0.0.jar:na]
    at com.example.DemoController.createAzureContainer(DemoController.java:66) ~[_wl_cls_gen.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) ~[javax.servlet.javax.servlet-api.jar:3.1.0]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet.javax.servlet-api.jar:3.1.0]
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25) ~[com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:115) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter.access$000(ErrorPageFilter.java:59) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:90) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:108) [spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
    at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3683) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3649) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326) [com.oracle.weblogic.security.subject.jar:12.2.1.2]
    at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197) [com.oracle.weblogic.security.subject.jar:12.2.1.2]
    at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2433) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2281) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2259) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1691) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1651) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:270) [com.oracle.weblogic.servlet.jar:12.2.1.2]
    at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348) [com.bea.core.utils.full.jar:12.2.1.2]
    at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333) [com.bea.core.utils.full.jar:12.2.1.2]
    at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54) [com.oracle.weblogic.work.jar:12.2.1.2]
    at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41) [com.bea.core.weblogic.workmanager.jar:12.2.1.2]
    at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:640) [com.bea.core.weblogic.workmanager.jar:12.2.1.2]
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:406) [com.bea.core.weblogic.workmanager.jar:12.2.1.2]
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:346) [com.bea.core.weblogic.workmanager.jar:12.2.1.2]

Any help will be really appreciated, thanks for your time.

Body:
According to your error information & Azure Storage offical error codes, the issue was caused by missing Content-Length header, please see below.

You can try to use Fiddler to check the error code 411 & response to make sure the issue reason when the exception happened.

Per my exception, I think WebLogic server caused the missing Content-Length header issue. I searched and discovered WebLogic server use some strategies for backward-compatibility to use own implementation for some standard like JAX-RS, JAX-PRC, etc.

So I think you can try to refer to Oracle offical document Invoking Web Services from Client Applications and WebLogic Server & Fusion Middleware Developing and Securing RESTful Web Services for Oracle WebLogic Server 12.1.3 to resolve the issue.

Some solutions I think may help resolving it.

According to the document 1, trying to add the code below.

// Setup the global JAX-RPC service factory
System.setProperty( "javax.xml.rpc.ServiceFactory", "weblogic.webservice.core.rpc.ServiceFactoryImpl");

Try to Configuring the Web Application to Use Jersey 2.5.1 (JAX-RS 2.0 RI).

Try to refer to Developing RESTful Web Service Clients to change or setup for your code.

Hope it helps.


问:
Hide legends in Chartjs
I want to hide legends in Chart.js in label and tooltips.

I am using v2.5.0

I am trying this way but its not hiding legend in tooltips

```<code><canvas id="myChart" width="400" height="250"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
<script>
window.onload = function(e){
    var ctx = document.getElementById("myChart").getContext("2d");
    var data = {
        labels: ["January", "February", "March", "April", "May", "June1", "July"],
        datasets: [
            {
                fill: false,
                lineTension: 0.3,
                pointRadius: 15,
                pointHitRadius: 15,
                pointHoverRadius: 15,
                data: [65, 59, 80, 81, 56, 55, 40],
                spanGaps: false,
            }
        ]
    };
    var options={
        legend: {
            display: false
        },
        tooltips: {
            callbacks: {
               label: function(tooltipItem, data) {
                      return tooltipItem.yLabel;
               }
            }
        }
    };
    var myLineChart = new Chart(ctx, {
        type: 'line',
        data: data,
        options: options
    });
}
</script>
</code>```

jsfiddle

I have also tried in global values like this

```<code>    Chart.defaults.global.legend= false;
</code>```

But legends are still shown in tooltips, Please see and suggest any possible way to do this.

Thanks

答:
I found the solution by adding displayColors:false in tooltips option like this

```<code>    tooltips: {
        displayColors:false,
        callbacks: {
           label: function(tooltipItem) {
                  return tooltipItem.yLabel;
           }
        }
    }
</code>```

Now the legend are not shown, I hope it helps someone with similar issue.

Title: Hide legends in Chartjs

Body:
I want to hide legends in Chart.js in label and tooltips.

I am using v2.5.0

I am trying this way but its not hiding legend in tooltips

<canvas id="myChart" width="400" height="250"></canvas>

jsfiddle

I have also tried in global values like this

    Chart.defaults.global.legend= false;

But legends are still shown in tooltips, Please see and suggest any possible way to do this.

Thanks

Body:
I found the solution by adding displayColors:false in tooltips option like this

    tooltips: {
        displayColors:false,
        callbacks: {
           label: function(tooltipItem) {
                  return tooltipItem.yLabel;
           }
        }
    }

Now the legend are not shown, I hope it helps someone with similar issue.


问:
filter by price based on product category
I am developing site in WordPress using woo-commerce

I want to achieve the functionality that on single page price will be displayed by counting 50% discount on single product page

I had implemented the below code, it is working nicely on the simple products but not working on variable product

Please help me how can I achieve the custom price filtering on variable product
OR suggest me which filter to used to variable products

```<code>add_filter('woocommerce_get_price', 'custom_price_WPA111772', 10, 2);

function custom_price_WPA111772($price, $product) {
    global $product;
    $pid = get_the_ID();
    $user = wp_get_current_user();
    if(!is_user_logged_in()) return $price;

        if( has_term( 'sale', 'product_cat' ,$product->ID) || has_term( 'Gift Ideas', 'product_cat' ,$product->ID))
        {
            $price = $price;
        }
        else
        {
            $price = $price * 50 / 100;
        }
    return $price;
}
</code>```

答:
I got the answer why my variable product is not showing custom price
i added this in function.php and its works
add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);</p>

```<code>function custom_variation_price( $price, $product ) {

    foreach($product->get_available_variations() as $pav){
        $def=true;
        foreach($product->get_variation_default_attributes() as $defkey=>$defval){
            if($pav['attributes']['attribute_'.$defkey]!=$defval){
                $def=false;
            }
        }
        if($def){
            $price = $pav['display_price'];
        }
    }
    return woocommerce_price($price);

}
</code>```

Body:
I am developing site in WordPress using woo-commerce

I want to achieve the functionality that on single page price will be displayed by counting 50% discount on single product page

I had implemented the below code, it is working nicely on the simple products but not working on variable product

Please help me how can I achieve the custom price filtering on variable product
OR suggest me which filter to used to variable products

add_filter('woocommerce_get_price', 'custom_price_WPA111772', 10, 2);

function custom_price_WPA111772($price, $product) {
    global $product;
    $pid = get_the_ID();
    $user = wp_get_current_user();
    if(!is_user_logged_in()) return $price;

        if( has_term( 'sale', 'product_cat' ,$product->ID) || has_term( 'Gift Ideas', 'product_cat' ,$product->ID))
        {
            $price = $price;
        }
        else
        {
            $price = $price * 50 / 100;
        }
    return $price;
}

Body:
I got the answer why my variable product is not showing custom price
i added this in function.php and its works
add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);

function custom_variation_price( $price, $product ) {

    foreach($product->get_available_variations() as $pav){
        $def=true;
        foreach($product->get_variation_default_attributes() as $defkey=>$defval){
            if($pav['attributes']['attribute_'.$defkey]!=$defval){
                $def=false;
            }
        }
        if($def){
            $price = $pav['display_price'];
        }
    }
    return woocommerce_price($price);

}


问:
Load selected/active tab content in view pager
I'm having a view pager in an application which is dynamically populated based on content available on server i.e tabs in view pager is variable. To do this I have created a single fragment which is binds to each tabs inside view pager.

I have populated viewpager like this:

```<code>
    List lstFragments = lstFragments = new ArrayList();
    lstFragments.add(DetailsFragment.newInstance(cat.getId(), subcategoryId, cat.getName(), subcategoryName, subcategoryIconUrl));
    DetailsTabsAdapter pageAdapter = new DetailsTabsAdapter(getChildFragmentManager(), lstFragments);

    viewPager.setAdapter(pageAdapter);

</code>```

By default viewpager has property that its load content for one previous and one next fragment, but I don't want this.

What I want to achieve:

Load content of only selected/active tab.

At the same time once content is loaded for that tab I don't want to
load it again from server if user comes back.

How to achieve above functionality?

What I have did to achieve this:

I have loaded content from server in fragment's public View
onCreateView() lifecycle event. Content is loading fine but it
loads content for other tab as well.

Then I tried viewPager.setOffscreenPageLimit(0). But it also not working.

Please help me out to resolve this.
Thanks

答:
For Issue 1

You need to implement public void setUserVisibleHint(boolean isVisibleToUser) like below:

```<code>
boolean isDataLoaded = false;

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);

        if (isVisibleToUser && !isDataLoaded ) {

            loadData();//Load data from server here
            isDataLoaded = true;
        }
    }

</code>```

Above code will load data only when your fragment will be visible to user and isDataLoaded flag ensure that content is loaded once per fragment lifecycle.

For issue 2

You need to store data you want to show to user as global within that fragment in your case DetailsFragment and check its value before loading it from server. May be you can do like below code.

```<code>
boolean isDataLoaded = false;

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);

        if (isVisibleToUser && !isDataLoaded ) {

            loadData();//Load data from server here
            isDataLoaded = true;
        }
        else if(isDataLoaded && yourData != null)
        {
            //Load your data from cache or existing global instance here
        }
    }
</code>```

Body:
I'm having a view pager in an application which is dynamically populated based on content available on server i.e tabs in view pager is variable. To do this I have created a single fragment which is binds to each tabs inside view pager.

I have populated viewpager like this:

    List lstFragments = lstFragments = new ArrayList();
    lstFragments.add(DetailsFragment.newInstance(cat.getId(), subcategoryId, cat.getName(), subcategoryName, subcategoryIconUrl));
    DetailsTabsAdapter pageAdapter = new DetailsTabsAdapter(getChildFragmentManager(), lstFragments);

    viewPager.setAdapter(pageAdapter);

By default viewpager has property that its load content for one previous and one next fragment, but I don't want this.

What I want to achieve:

Load content of only selected/active tab.

At the same time once content is loaded for that tab I don't want to
load it again from server if user comes back.

How to achieve above functionality?

What I have did to achieve this:

I have loaded content from server in fragment's public View
onCreateView() lifecycle event. Content is loading fine but it
loads content for other tab as well.

Then I tried viewPager.setOffscreenPageLimit(0). But it also not working.

Please help me out to resolve this.
Thanks

Body:
For Issue 1

You need to implement public void setUserVisibleHint(boolean isVisibleToUser) like below:

boolean isDataLoaded = false;

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);

        if (isVisibleToUser && !isDataLoaded ) {

            loadData();//Load data from server here
            isDataLoaded = true;
        }
    }

Above code will load data only when your fragment will be visible to user and isDataLoaded flag ensure that content is loaded once per fragment lifecycle.

For issue 2

You need to store data you want to show to user as global within that fragment in your case DetailsFragment and check its value before loading it from server. May be you can do like below code.

boolean isDataLoaded = false;

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);

        if (isVisibleToUser && !isDataLoaded ) {

            loadData();//Load data from server here
            isDataLoaded = true;
        }
        else if(isDataLoaded && yourData != null)
        {
            //Load your data from cache or existing global instance here
        }
    }