Showing posts with label webDeployment. Show all posts
Showing posts with label webDeployment. Show all posts

2023-03-30

Valid redirect URIs for Keycloak 20.0.1

 
Keycloak Error:

Invalid parameter: redirect_uri


 

Recognized:
http://localhost:9099/sfa/*

Unrecognized
http://localhost*/sfa/*














2023-01-12

Finding - 2 different ways to get result from API to showing by using Datatables.net

 


Reference URL: https://stackoverflow.com/a/68456824/6462295

As of 2023Feb07_1503 - failed to achieve by method of: data: data

Published on
1/12/23 2:25 PM






My html table:

<table id="listaVideos2" class="display">
        <thead>
        <tr>
            <th>nombre</th>
            <th>descripcion</th>
            <th>codigoYoutube</th>
            <th>bpm</th>
        </tr>
        </thead>
    </table>

My JavaScript:

$.ajax({
        "url": "listado2",
        "type": "GET",
        "datatype": 'json',
        "success": function (data) {
            $('#listaVideos2').DataTable({
                "fixedHeader" : true,
                "paging":   false,
                "info":     true,
                "autoWidth": true,
                "order": [],
                data: data,
                select: true,
                columns: [
                    { "data": "nombre" },
                    { "data": "descripcion" },
                    { "data": "codigoYoutube",
                        "title": "Youtube",
                        "orderable": false
                    },
                    { "data": "bpm" },
                ]
            });
        }
    });

or another way you can use:

$('#listaVideos2').DataTable({
        "fixedHeader" : true,
        "paging":   false,
        "info":     true,
        "autoWidth": true,
        "order": [],
        ajax: {
            url: 'listado2',
            dataSrc: ''
        },
        select: true,
        columns: [
            { "data": "nombre" },
            { "data": "descripcion" },
            { "data": "codigoYoutube",
                "title": "Youtube",
                "orderable": false
            },
            { "data": "bpm" },
        ],
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor }
        ],
        dom: "Bfrtip",
    });

And my Controller: (if your controller is a @RestController I think you wouldn't need the @ResponseBody)

@GetMapping("/listado2")
    @ResponseBody
    public List<Video> apiListadoVideos() {
        return videosServicio.buscarTodosLosVideos();
    }

where my Video class is this simple (I just remove de getters, setters...):

public class Video {
    private Integer id;
    @NotEmpty
    @NotBlank
    private String nombre;
    private String descripcion;
    @NonNull @NotBlank
    private String codigoYoutube;
    private String bpm;
    private Categoria categoria;
    private Tono tono;
    private Modo modo;
}















2022-07-21

ajax, upload file, json string, Spring Controller, DTO

 



Googled: json to dto spring boot controller




Resolved by follow the example on: 

Spring Boot controller - Upload Multipart and JSON to DTO




thread solution at: https://stackoverflow.com/a/49993072


Ajax Javascript
formData.append( 'dtoName', new Blob([JSON.stringify(dtoJavascriptObject)], {
type: "application/json"
}));

Spring Controller parameter

@RequestPart ManualGenerateCsv dtoName






couldn't parse json attribute to java object attribute.

 







private boolean isRequiredFtpToSSS;

public void setRequiredFtpToSSS(boolean isRequiredFtpToSSS) {
this.isRequiredFtpToSSS = isRequiredFtpToSSS;
}

Since your attribute name: isRequiredFtpToSSS
Due to jackson is expecting: setIsRequiredFtpToSSS
But there has no "is for the auto generated setter: setRequiredFtpToSSS





So u have to add this.

@JsonProperty("isRequiredFtpToSSS")
private boolean isRequiredFtpToSSS;


















Jackson JSON parsing from string to date.

 









@JsonFormat(pattern = "yyyy-MMM-dd")
private Date dateFrom;





not sure if were causing by:
MethodArgumentConversionNotSupportedException when I try to map json string onto java domain class in Spring controller's method






jquery 3.3.1 change checkbox checked

 







Found: 
Make checkbox value checked with jQuery or JavaScript
but seems not the same case.



the one i'm using.

$("#chkHasDateTo").prop('checked', dto.hasDateTo);



But i remember there are more elegant way to do the same thing....

Jquery Datepicker: click on a checkbox, then open/pop datepicker of a textbox.

 


click on a checkbox, then open/pop datepicker of a textbox.



if($("#chkHasDateTo").is(":checked")){
$( "#dateTo" ).trigger( "select" );
$( "#dateTo" ).trigger( "focus" );
}

















2021-12-30

What is the 1st thing to do after check out angular project from git?

 

What is the 1st thing to do after check out angular project from git?

Reference URL: https://stackoverflow.com/a/54142081



npm install



2021-11-18

Angular pipe could not be found

 


Angular pipe could not be found



Reference URL: https://stackoverflow.com/a/40463405


see this is working for me.

ActStatus.pipe.ts First this is my pipe

import {Pipe,PipeTransform} from "@angular/core"; @Pipe({ name:'actStatusPipe' }) export class ActStatusPipe implements PipeTransform{ transform(status:any):any{ switch (status) { case 1: return "UN_PUBLISH"; case 2: return "PUBLISH"; default: return status } } }



main-pipe.module.ts in pipe module, i need to declare my pipe/s and export it.

import { NgModule } from '@angular/core'; import {CommonModule} from "@angular/common"; import {ActStatusPipe} from "./ActStatusPipe.pipe"; // <--- @NgModule({ declarations:[ActStatusPipe], // <--- imports:[CommonModule], exports:[ActStatusPipe] // <--- }) export class MainPipe{}



app.module.ts user this pipe module in any module.

@NgModule({ declarations: [...], imports: [..., MainPipe], // <--- providers: [...], bootstrap: [AppComponent] })



you can directly user pipe in this module. but if you feel that your pipe is used with in more than one component i suggest you to follow my approach.

  1. create pipe .

  2. create separate module and declare and export one or more pipe.

  3. user that pipe module.

How to use pipe totally depends on your project complexity and requirement. you might have just one pipe which used only once in the whole project. in that case you can directly use it without creating a pipe/s module (module approach).










2021-09-10

Angular 8 ng-select value object

 





Because you set the binding to ID: bindValue="ID". Remove it and it should work.

Read more about bindings here: https://ng-select.github.io/ng-select#/bindings








Source URL: https://stackblitz.com/run?file=src%2Fbindings-default-example.component.ts




html

<ng-select [items]="defaultBindingsList"
           [(ngModel)]="selectedCity">
</ng-select>



ts
import { ComponentOnInit } from '@angular/core';

@Component({
    selector: 'bindings-default-example',
    templateUrl: './bindings-default-example.component.html',
    styleUrls: ['./bindings-default-example.component.scss']
})
export class BindingsDefaultExampleComponent implements OnInit {

    defaultBindingsList = [
        { value: 1label: 'Vilnius' },
        { value: 2label: 'Kaunas' },
        { value: 3label: 'Pavilnys'disabled: true }
    ];

    selectedCity = null;

    ngOnInit() {
        this.selectedCity = this.defaultBindingsList[0];
    }
}









Angular 8 bindLabel append values


Both has no issue to show appended "full name".

Eventually go for option#2, which loop through the list to custom the display label, as the ng-select filtering in options#1 won't search through item.lastName.



Option#1
Source URL: https://stackoverflow.com/a/56531503

It is possible to display it via a custom label and item template:

<ng-select [items]="users" bindLabel="firstName"> 

  <ng-template ng-label-tmp let-item="item">
      <span >{{ item.firstName + ' ' + item.lastName }}</span>
  </ng-template>
  <ng-template ng-option-tmp let-item="item" let-search="searchTerm" let-index="index">
        <span >{{ item.firstName + ' ' + item.lastName }}</span>
  </ng-template>

</ng-select>











Displaying values with interpolation
Interpolation refers to embedding expressions into marked up text. By default, interpolation uses the double curly braces {{ and }} as delimiters.


if using Option#1 u might need to check optional checking as below, in case u got undefined for both value to be appended.

<span >{{ item? item.firstName + ' ' + item.lastName:'' }}</span>


You can use nested ternary if

{{element.source == 1 ? 'upwork' : (element.source == 2 ? 'refer from friend' : '')}}

or probably better

export class MyComponent {
  sourceNames = {1: 'upwork', 2: 'refer from friend', 3: 'other' };
}
{{sourceNames[element.source]}}







Option#2

ng-select only accepts a string value in the attribute. I may be misunderstanding but I believe that if you say bindLabel="firstName+lastName", ng-select is attempting to reference item[firstNamelastName] which does not exist.

I think your best option is to transform the collection. You can add a .map to the end of your array declaration and use bindLabel="fullName" in your template:

[
  {firstName: "John", lastName: "Doe"},
  {firstName: "Jane", lastName: "Doe"}
].map((i) => { i.fullName = i.firstName + ' ' + i.lastName; return i; });







Google Referrals