Strus2 Message Resource Files: keys with same substring - properties

ArticleDto.java
public class ArticleDto {
...
private CategoryDto categoryDto;
...
}
CategoryDto.java
public class CategoryDto {
...
private Long id;
...
}
global_en.properties
...
categoryDto.id=ID
...
...
articleDto.categoryDto.id=Category
...
new_article.jsp
<s:form action="addArticle">
<s:select key="articleDto.categoryDto.id" />
<s:textfield key="articleDto.title" />
<s:submit />
</s:form>
In the resulting HTML I get the wrong label for "articleDto.categoryDto.id".
I get "ID" instead of the desired "Category".
I seems like of the key "articleDto.categoryDto.id" it first match the subString "categoryDto.id".
If I remove the "categoryDto.id=ID" entry from the .properties file, it get the corrent value "Category".
Shouldn't be "articleDto.categoryDto.id" higher priority instead of "categoryDto.id"?

I solved this adding "bundle" at the beginning of all the entries in global_en.properties:
...
bundle.categoryDto.id=ID
...
...
bundle.articleDto.categoryDto.id=Category
...
and than in the form:
<s:select name="bundle.articleDto.categoryDto.id" />
Solved, but still dont know why struts2 wasn't able to recognize the previous solution.
The problem is in getText(). It searches in the value stack that contains also action variable. And in the action I have an ArticleDto, with getter and setter.
If I remove the getter, all goes fine. This getter seems to go in some strange conflict.

Related

Trying to take some data from my file called "listing-card" which is is saved in the component folder

#foreach($listings as $listing)
<x-listing-card :listing="$listings" />
#endforeach
the listing card is in the component file
I was expecting to get results from 'listing-card' blade file. but I got this error
enter image description here
without a better understanding of your code, the first thing I see is the :listing=$listings
I would think you would want the individual item $listing from your foreach.
Secondly, The error states it can not find the class. Be wary of kabob-case vs CamelCase. It has bitten me a few times
Edit/Update addressing comment below:
You will have to go and look at your component blade file to check on your exact naming convention you are using. For example you have a class named SiteInfo and in the render section you would have it return something like : return view('components/site-info');
Your file and class being used will be SiteInfo.blade.php and the class in it will be: class SiteInfo extends Component
example:
#foreach($listings as $listing)
<x-listing-card :listing="$listing" />
#endforeach
Your Class file would be something similar to:
class Listing-card extends Component
{
public $listing;
}
/**
* Create a new component instance.
*
*
*/
public function __construct($listing)
{
$this->listing = $listing;
}
/**
* Get the view / contents that represent the component.
*
* #return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.listing-card');
}
}
You might have to enable some logging at key points in your app and pull data. The laravel log /storage/logs/laravel.log is invaluable in find your mistakes.

RazorPages anchor tag helper with multiple parameters

Here's the RazorPages page I'm trying to make a link to:
#page "{ReportId:int}/{SicCode:alpha?}"
This works
<a asp-page="/ReportSics" asp-route-ReportId="3">rs1</a>
it produces
rs1
But this produces a blank href.
<a asp-page="/ReportSics" asp-route-ReportId="3" asp-route-SicCode="10">rss2</a>
That is: the tag helper works with one parameter but not with two.
Why?
Is it possible to make it work?
(I have another page with the same #page but with the second parameter not optional and it appears to be impossible to create a link to it.)
Furthermore, requesting Page/2/M works, but Page/2/12 returns 404. Why? (The second parameter is a string that can sometimes be a number, but it always treated as a string.)
From the learn.microsoft.com webpage asp-all-route-data offers the following:
asp-all-route-data
The asp-all-route-data attribute supports the creation of a dictionary of key-value pairs. The key is the parameter name, and the value is the parameter value.
In the following example, a dictionary is initialized and passed to a Razor view. Alternatively, the data could be passed in with your model.
#{
var parms = new Dictionary<string, string>
{
{ "speakerId", "11" },
{ "currentYear", "true" }
};
}
<a asp-route="speakerevalscurrent"
asp-all-route-data="parms">Speaker Evaluations</a>
The preceding code generates the following HTML:
Speaker Evaluations
Extension: From here the parameters can be accessed either explicitly in the parameter list of the method:
public IActionResult EvaluationCurrent(int speakerId, string currentYear)
or as a collection (See response: queryString:
public IActionResult EvaluationCurrent()
{
var queryString = this.Request.Query;
}
This works
Yes it works because it produces a route that is similar to this baseUrl/reportsics/?reportId=5
And the other produces a URL that is similar to this baseUrl/reportsics/?reportId=5&sicCode=678 and then it doesn't match your route definition. I think you should try this.
Experimental
asp-page="/reportSics/#myId/#sicCode
Though this would not be the right way to do what you're thinking. If you really want to change your URL structure, why not do url-rewrite?
Edit.
Form your recent comments, seems you want to pass many parameters in your action method and not targeting URL structure. Then I recommend you just
public IActionResult(string ReportId, string sicCode)
{
//......
}
//And the your URL target
<a asp-page="ReportSics" asp-route-ReportId="55" asp-route-sicCode="566" ></a>
And then it will match the route. I think you should remove that helper you placed after your #page definition and try it out if this is what you have already done and the problem persists.
It turns out that if a parameter has the constraint :alpha then it only works if the value being passed can not be parsed as an int or float.

custom boolean attributes not binding

Custom boolean attributes do not bind like built in. checked.bind='1===2' will not include the checked attribute in the tag. myboolatt.bind='1===2' WILL include the myboolatt in the tag. I did myboolatt.bind='1===2 | boolconverter' to log out the value and it says false.
So what am I doing wrong? It seems Aurelia is inconsistent on binding expressions. Another instance is I can do this title=${$index<12} inside a repeat and I get what is expected. So I thought this would work - myboolatt.bind=${$index<12}. That doesn't even compile.
Believe me I have read the all the doc (doesn't mean I didn't miss something) and many posts including the long running discussions between the Aurelia team concerning boolean attributes.
I have wrapped expressions in "" and in ${} and in both but just can't get it to work.
It feels like I am missing 1 vital piece of information that will magically explain these inconsistencies and slay my frustration. One of the reasons I like Aurelia so much (on top of convention based) is that I have actually just guessed at a few things - thinking this is how I would do it - and ding-dang if they didn't just work.
I really feel like this should just work. So again I ask - what am I doing wrong?
Thanks
If you are using .bind, you bind it to the att variable in your js/ts file, and you should not use any dollar signs or brackets.
For example, myboolatt.bind=${$index<12} should be myboolatt.bind="$index<12". The use of the dollar sign in index has nothing to do with the bindings. This is just a variable provided by Aurelia.
When you want to use variables without bind you use ${variable}.
The checked attribute not being present, I in the tag I'm guessing is because it's evaluated to false, and the checked attribute is not a true/false attribute. A input that's checked will look like <input type="checkbox" checked/>
It was not Aurelia binding. I initially created bool attributes but did not have a need to bind. They were just empty classes. Then I needed binding so I added the necessary methods. What ended up causing the confusion was using myboolatt sends no argument into valueChanged where myboolatt.bind sends T or F. Not being a regular js'er this threw me a bit and I see there are a number of ways to handle. Anyway here are the attributes and usage. Hope it helps someone else.
Thanks
function private_ValueChanged(self, att, value) {
if (value === false) self.element.removeAttribute(att);
else self.element.setAttribute(att, '');
}
export class toggleCustomAttribute {
static inject = [Element];
constructor(element) { this.element = element; }
valueChanged(newValue, oldValue) { private_ValueChanged(this, 'toggle', newValue);
}
export class radioCustomAttribute {
static inject = [Element];
constructor(element) { this.element = element; }
valueChanged(newValue, oldValue) { private_ValueChanged(this, 'radio', newValue); }
}
<ff-button repeat.for="keymen of keyChangeMenu" radio.bind="$index<12" class='ff-button' click.delegate="keyChangeClick($event.target)" id.bind="$index+'_key'" >
${keymen[0]}<sup>${keymen[1]}</sup>
</ff-button>

Use of SerializationFeature.WRAP_ROOT_VALUE ahead of xmlRootElement

I just want to understand what is the use of SerializationFeature.WRAP_ROOT_VALUE.
I have actually tried disabling the SerializationFeature.WRAP_ROOT_VALUE and for the class I have annotated with xmlRootElement. Here in this case after disabling the SerializationFeature.WRAP_ROOT_VALUE still after serializing I am getting the root value. To just avoid the root value I have to use the xmlType.
So trying to understand then what is the use of SerializationFeature.WRAP_ROOT_VALUE?
Sample code which I have tried
#XmlRootElement(name="person")
Public class Person {
#XmlElement(name = "insert")
private int insert;
#XmlElement(name = "update")
private int update;
}
The above is the POJO class which I was trying to serialize and also I have used
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
So with the above code the output is
"person" {
"insert" : 1,
"update" : 0
}
In the same case if I try to change the xmlRootElement to XmlType in Person class the output is
{
"insert" : 1,
"update" : 0
}
So I am confused like what is the use of SerializationFeature.WRAP_ROOT_VALUE if it is not giving the expected output?
I am using the Jackson version of 2.9.6
After digging more into this found that with the help of CXF I was able to solve this by adding small config in applicationcontext.xml file
<bean class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="dropRootElement" value="true" />
</bean>

MVC4 Html.DropDownListFor is not selecting specified value

I have the following classes:
public class PreviewImage_Edit
{
...
public List<GridDetail_Edit> GridDetails { get; set; }
public SelectList GridDetailTypesList { get; set; }
...
}
public class GridDetail_Edit
{
...
public int GridDetailTypeId { get; set; }
...
}
And, I have a partial view that expects a model of type PreviewImage_Edit, which has the following block of code:
#model PreviewImage_Edit
...
#if (Model.GridDetails != null)
{
for (var i = 0; i < Model.GridDetails.Count(); i++)
{
...
#Html.DropDownListFor(model => model.GridDetails[i].GridDetailTypeId, Model.GridDetailTypesList)
...
}
}
I am properly creating the SelectList in GridDetail_Edit and the dropdown is populating as expected. Below is the markup that is generated for the first GridDetails object:
<select data-val="true" data-val-number="The field GridDetailTypeId must be a number." data-val-required="The GridDetailTypeId field is required." id="GridDetails_0__GridDetailTypeId" name="GridDetails[0].GridDetailTypeId">
<option value="1">Top</option>
<option value="2">Bottom</option>
</select>
I've verified that the selected choice is properly saved in the database (even when the selected option isn't the first/default option in the dropdown) when the Save button is clicked. However, when I go back to re-edit, the selected option continues to be the first option in the dropdown.
I stepped through the code and verified that the data is properly retrieved from the database. I've even gone so far as converting the Html.DropDownListFor to Html.EditorFor and confirmed that the value stored in the database is making it to the view as expected.
I've used Html.DropDownListFor when the property associated with it was an integer value but never when it's an integer value that's part of a collection of objects. I would be apprehensive about what I've done so far, but everything appears to be working with this one key issue.
So far, I've tried moving the SelectList in PreviewImage_Edit into GridDetail_Edit and initializing them separately where I've programmatically set the "Selected" value for the appropriate SelectedListItem. That didn't work... same result.
Has anyone come across this issue? Any suggestions on the best way to resolve this?
Update
Below is the snippet of code that populates GridDetailTypesList
var gridDetailTypes = _db.GridDetailTypes.OrderBy(g => g.DisplayOrder).ToList();
return new SelectList(gridDetailTypes, "GridDetailTypeId", "Name");
It's pretty straightforward. The second parameter of the SelectList constructor represents the field whose values should be used in the "value" attribute. I don't believe the issue is related to the fact that the value field is an integer as I have similar code on the same page and that dropdown is functioning properly. The only difference is that my "problem" dropdowns are within a collection of my ViewModel.
The only time I've seen messages on a dropdown about "must be a number" was when I screwed up and the (numeric) value of the OPTIONs were being padded with spaces when I loaded them from a database. This doesn't appear to be your problem (and your example specifically shows no padding) but I would definitely want to look at the value of GridDetails[0].GridDetailTypeId to make sure it was of the correct type/value.
Wish I could add this as a comment rather than an answer - but my rep isn't high enough yet...
The only way it works for me is when my List is a simple IEnumerable<string>, or when I pass the same property of my custom object for both the DataText as the DataValue. As follows:
Html.DropDownListFor(m => m.TypeOfFilter, new SelectList(Model.Filters, "DataText", "DataText")
where TypeOfFilter is an enum and Model.Filters is a List<MySelectItemModel>.
That way you can see in the generated HTML that the right option is selected.