GXT TextField or TextArea not decode html entites - textfield

i use grid cell renderer... and form bindig...
grid cell renderer valus is good
form bindig value is bad (
i tested: ff9 and last chrome
this bug ? or browser error ? or something else ?
sorry i little speak english.... (i use gtranslate)
error picture => http://test.eggproject.hu/gxt/textfieldentitesbugg.PNG
about json(gxt model)
{"ID":1,"user_email":"xxxx#xxxx.com","display_name":"XXX YYYY","user_cegnev":"","user_jogosultsag":"administrator","user_kedvezmeny":0,"user_city":0,"user_irsz":-1,"user_district":3,"user_street":241,"user_hazszam":"2813","user_emelet":"10","user_ajto":"588","user_kapucsengo":"58","user_comment":"óüöú\u0151\u0171áí","first_name":"Harangozo","last_name":"Gabor","user_telephone":"06111111","user_street2":""}
user_comment error displaying just textarea or textfield why ?

This is due to the components each section is using. A grid is essentially a tag which means any HTML encoded data loaded into this table is rendered correctly. Conversely A TextBox is a tag which only displays exactly what can be seen.
A solution is a custom field binding which processes the data in and out.
public class HTMLParserBinding extends FieldBinding {
protected Field<?> field;`
public HTMLParserBinding( Field<?> field, String property ) {
super(field, property);
this.field = field;
}
protected Object onConvertFieldValue( Object value ) {
if (value == null) {
return null;
}
return Format.htmlDecode(value.toString());
}
protected Object onConvertModelValue( Object value ) {
if( value == null ) {
return null;
}
return Format.htmlEncode(value.toString());
}
}

Related

can't find all field of a pdf (acroform)

Considering this pdf
With this code I except retrieve all field but I get half of them:
pdfOriginal.getDocumentCatalog().getAcroForm().getFields().forEach(field -> {
System.out.println(field.getValueAsString());
});
What is wrong here ? It seems all annotations are not in aocroform reference, what is the correct way to add form field annotation into acroform object?
Update 1
The wierd thing here if I tried to set field's value which is not referenced/found in getAcroForm.getFields() like this :
doc.getDocumentCatalog().getAcroForm().getField("fieldNotInGetFields").setValue("a");
This works
Update 2
It seems using doc.getDocumentCatalog().getAcroForm().getFieldTree() retrieve all fields. I don't understand why doc.getDocumentCatalog().getAcroForm().getFields() not ?
What is the correct way retrieve all fields of a pdf acroform.getFieldTree() or acroform.getFields() (I need retrieve them to set them partialValue)
From the java doc on method public List<PDField> getFields() we can read:
A field might have children that are fields (non-terminal field) or does not have children which are fields (terminal fields).
In my case some fields contain non-terminal field so to print them all we need check if we are in a PDNonTerminalField like :
document.getDocumentCatalog().getAcroForm().getFields().forEach(f -> {
listFields(f);
});
// loop over PDNonTerminalField otherwise print field value
public static void listFields(PDField f){
if(f instanceof PDNonTerminalField) {
((PDNonTerminalField) f).getChildren().forEach(ntf-> {
listFields(ntf);
});
}else {
System.out.println(f.getValueAsString());
}
}

Aurelia validation errors not displayed when validation initialized on attached

I want to show invalid input fields when the view is shown.
I have validation rules setup in a separate class (UserValidation) with one function (initValidatorOn).
export class UserValidation {
public _validation: Validation;
constructor(validation: Validation) {
this._validation = validation;
}
initValidatorOn(user: UserDto): ValidationGroup {
return this._validation.on(user, null)
.ensure('name').isNotEmpty();
}
}
Everything works for this setup.
export class User {
public validationGroup : ValidationGroup;
public userValidation : UserValidation;
public user : UserDto;
constructor(uv: UserValidation) {
this.userValidation = uv;
//this code works here and in activate method
this.validationGroup = this.userValidation.initValidatorOn(this.user);
}
attached() {
this.validationGroup.validate();
}
}
As I said before, the above works. But sometimes the object that I need to validate I not available in constructor or in activate function so I need to initialize validation in attached function. When I do that, my view no longer shows validation errors until I update the value in input.
So, this doesn't work
attached() {
this.validationGroup = this.userValidation.initValidatorOn(this.user);
//no validation errors displayed on the view
this.validationGroup.validate();
}
Can someone explain why errors aren't displayed on the view after I call validate when I initialize validationGroup in attached function?
Thank you.

Validation messages from custom model validation attributes are locked to first loaded language

I am working on a multi lingual website using Umbraco 7.2.4 (.NET MVC 4.5). I have pages for each language nested under home nodes with their own culture:
Home (language selection)
nl-BE
some page
some other page
my form page
fr-BE
some page
some other page
my form page
The form model is decorated with validation attributes that I needed to translate for each language. I found a Github project, Umbraco Validation Attributes that extends decoration attributes to retrieve validation messages from Umbraco dictionary items. It works fine for page content but not validation messages.
The issue
land on nl-BE/form
field labels are shown in dutch (nl-BE)
submit invalid form
validation messages are shown in dutch (nl-BE culture)
browse to fr-BE/form
field labels are shown in french (fr-BE)
submit invalid form
Expected behavior is: validation messages are shown in french (fr-BE culture)
Actual behavior is: messages are still shown in dutch (data-val-required attribute is in dutch in the source of the page)
Investigation to date
This is not a browser cache issue, it is reproducible across separate browsers, even separate computers: whoever is generating the form for the first time will lock the validation message culture. The only way to change the language of the validation messages is to recycle the Application Pool.
I doubt that the Umbraco Validation helper class is the issue here but I'm out of ideas, so any insight is appreciated.
Source code
Model
public class MyFormViewModel : RenderModel
{
public class PersonalDetails
{
[UmbracoDisplayName("FORMS_FIRST_NAME")]
[UmbracoRequired("FORMS_FIELD_REQUIRED_ERROR")]
public String FirstName { get; set; }
}
}
View
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage
var model = new MyFormViewModel();
using (Html.BeginUmbracoForm<MyFormController>("SubmitMyForm", null, new {id = "my-form"}))
{
<h3>#LanguageHelper.GetDictionaryItem("FORMS_HEADER_PERSONAL_DETAILS")</h3>
<div class="field-wrapper">
#Html.LabelFor(m => model.PersonalDetails.FirstName)
<div class="input-wrapper">
#Html.TextBoxFor(m => model.PersonalDetails.FirstName)
#Html.ValidationMessageFor(m => model.PersonalDetails.FirstName)
</div>
</div>
note: I have used the native MVC Html.BeginForm method as well, same results.
Controller
public ActionResult SubmitFranchiseApplication(FranchiseFormViewModel viewModel)
{
if (!ModelState.IsValid)
{
TempData["Message"] = LanguageHelper.GetDictionaryItem("FORMS_VALIDATION_FAILED_MESSAGE");
foreach (ModelState modelState in ViewData.ModelState.Values)
{
foreach (ModelError error in modelState.Errors)
{
TempData["Message"] += "<br/>" + error.ErrorMessage;
}
}
return RedirectToCurrentUmbracoPage();
}
}
LanguageHelper
public class LanguageHelper
{
public static string CurrentCulture
{
get
{
return UmbracoContext.Current.PublishedContentRequest.Culture.ToString();
// I also tried using the thread culture
return System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
}
}
public static string GetDictionaryItem(string key)
{
var value = library.GetDictionaryItem(key);
return string.IsNullOrEmpty(value) ? key : value;
}
}
So I finally found a workaround. In attempt to reduce my app to its simplest form and debug it, I ended up recreating the "UmbracoRequired" decoration attribute. The issue appeared when ErrorMessage was set in the Constructor rather than in the GetValidationRules method. It seems that MVC is caching the result of the constructor rather than invoking it again every time the form is loaded. Adding a dynamic property to the UmbracoRequired class for ErrorMessage also works.
Here's how my custom class looks like in the end.
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter,
AllowMultiple = false)]
internal class LocalisedRequiredAttribute : RequiredAttribute, IClientValidatable
{
private string _dictionaryKey;
public LocalisedRequiredAttribute(string dictionaryKey)
{
_dictionaryKey = dictionaryKey;
}
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(
ModelMetadata metadata, ControllerContext context)
{
ErrorMessage = LanguageHelper.GetDictionaryItem(_dictionaryKey); // this needs to be set here in order to refresh the translation every time
yield return new ModelClientValidationRule
{
ErrorMessage = this.ErrorMessage, // if you invoke the LanguageHelper here, the result gets cached and you're locked to the current language
ValidationType = "required"
};
}
}

How to set in the Table methods field's properties from code?

I want to set field properties , in table method from code.
I would like to do as a Form
in modifiedField Table method, I wolud like to insered look like this code:
if(this.FieldControl == "valueToBlock")
{
// I want to set here the field property
//this.Field_II allowEdit(false);
}
It's possible to set the property from code in Table method ?
thanks community,
enjoy!
You can use dataSource result on the buffer. The result is FormDataSource if buffer source is from client form.
If record changes you have to re-calculate this (create new method and call it from the table modifiedFiled and form DS active).
public void modifiedField(FieldId _fieldId)
{
FormDataSource fds;
super(_fieldId);
switch (_fieldId)
{
case fieldNum(TableName,FieldI):
if (this.isFormDataSource())
{
fds = this.dataSource();
fds.object(fieldNum(MyTable, Field_II)).allowEdit(this.Field_I != "valueToBlock");
}
break;
}
}

AutoCompleteBox and SearchText Clear

This is not a question but my answer to a problem I could not find a solution to on the internet.
I had a problem clearing the SearchText in an MVVM Silverlight application. I could clear clear the SelectedItem and Text but the SearchText was left behind. It is read only and cannot be changed by binding.
Example: AutoCompleteBox with a list of Countries. When the user wants to enter Australia they enter 'au' at this point the list appers with Austria and Australia. The user can then select Australia and move on. At the end of editing they click on a 'Save' button. At this point it is likely that you would want to clear the data forn for entering new data.
Even if you have bindings to the SelectedItem and the Text properties and you set them to 'null' and string.Empty respectively the SearchText property remains and the AutoCompleteBox will not clear but will contain 'au'.
I posted about this all over the internet but could get no answer on the control itself and so I came at it from a different angle which may help someone who ends up frustrated like me.
I am using a Silverlight Navigation template application which uses a NavigationFrame in which to load Silverlight pages. I noticed that if I navigated to another page and returned to my data form the SearchText was cleared. Any values that were bound to properties remained valid, just the SearchText had cleared on all AutoCompleteBoxes. I therefore used the PageConductor method of injecting the NavigationFrame into the ViewModel where I could call the refresh method. I got this method from John Papa's example from the Silverlight Firestarter event , I simply added a Refresh method to the IPageConductor interface so I am now able to call 'PageConductor.Refresh()' which is like reloading the page. I hope this helps someone out there.
var t = ProductCombo.ItemsSource;
ProductCombo.ItemsSource = null;
ProductCombo.Text = string.Empty;
ProductCombo.SelectedValue = null;
//ProductCombo.Text = string.Empty;
ProductCombo.ItemsSource = t;
Try this please.it worked for me
You must clear the property bindeaded to Text inside set part of SelectedItem Binded property, like this:
public string AnalisisText
{
get { return _analisisText; }
set
{
if (_analisisText == value)
{
return;
}
_analisisText = value;
RaisePropertyChanged(AnalisisTextPropertyName);
}
}
public DatosAutoCompletaPedidosDetalleViewDTO AnalisisSelect
{
get { return _analisisSelect; }
set
{
if (_analisisSelect == value)
{
return;
}
_analisisSelect = value;
if (_analisisSelect == null) AnalisisText = "";
RaisePropertyChanged(AnalisisSelectPropertyName);
}
}
So, when you set null to property SelectedItem , the other property will set to "".
The easiest way I've found is to extend the AutoCompleteBox:
public class AutoCompleteBoxClear : AutoCompleteBox
{
public AutoCompleteBoxClear()
{
DataContextChanged += (o, e) =>
{
if (SelectedItem == null)
Text = string.Empty;
};
}
}
Now use your new AutoCompleteBoxClear control in your XAML.
This clears the text only when autocompletebox datacontext changes to null (ie the user clicks add in the dataform.)
Note: I think DataContextChanged is available only in Silverlight 5, but I'd guess that anyone still using Silverlight these days would likely have upgraded by now...
var t = ProductCombo.ItemsSource;
ProductCombo.ItemsSource = null;
ProductCombo.Text = string.Empty;
ProductCombo.SelectedValue = null;
//ProductCombo.Text = string.Empty;
ProductCombo.ItemsSource = t;
Unfotunately this is code-behind and I needed an MVVM solution.
I recently had the same problem with my WPF app. I found out that the solution is not to set the object bound to SelectedItem to null, but to its default value. Took me a while to figure this out. So in your example, it would not be SelectedCountry = null, but SelectedCountry = new SelectedCountry(). In this case the SearchText is cleared also. Check my SO post regarding this matter: Autocompletebox doesn't clear keyboard strokes.
Sure SearchText property is read-only, but we can get the child component of AutoCompleteBox:
var searchText = autoCompBox.GetChildByType<TextBox>(item => item.Name == "Text");
And now we can reset SearchText via Text property of TextBox-component:
if (searchText != null) searchText.Text = string.Empty;
In C# 6.0 it is more laconically:
autoCompBox.GetChildByType<TextBox>(item => item.Name == "Text")?.Text = string.Empty;