null?updateSuccess=true in successfull entity update/save

56 views
Skip to first unread message

Big Tom

unread,
Jan 4, 2016, 1:42:03 AM1/4/16
to Light Admin Group
I've plugged 1.2.0RC1 into spring boot 1.2.7 / Spring Security / JPA 2 / MySQL 5 and managed to get lightadmin working with the majority of my entities.
I had to disable CSRF protection for the lightadmin dashboard and it was a real pain but I finally got it working
I can get entities in the mysql DB but the success operation URL is, for some reason, malformed. The URL looks like this:

/admin/domain/valueAddedTaxes/1/null?updateSuccess=true

instead of

/admin/domain/valueAddedTaxes/1/?updateSuccess=true

I took a peek at the source and it looks like the create/edit jsp pages use the following code:

$(domain_form).submit(function () {
            return new FormViewController(ApplicationConfig.RESOURCE_NAME).updateDomainEntity(this, function (domainEntity) {
                window.location = domainEntity.getDomainLink() + '?updateSuccess=true';
            });
        });

I'm not sure about this, but it seems, for some reason domainEntity.getDomainLink() is returning null.
I've given up. Other than integrating the lightadmin source into my project and try to debug it - I'm helpless.

Please help! I've relied on light admin as a back office for a production site and it's giving me hell.

Thanks

Tom

James Kennedy

unread,
Jan 4, 2016, 1:42:08 PM1/4/16
to Light Admin Group
Not sure what the problem is but based on the code you posted it looks like domainEntity.getDomainLink() is returning:
"/admin/domain/valueAddedTaxes/1/null"
instead of null.

You should post more information about how this JPA entity is defined and how it's Administration in lightadmin is defined.
Any other special configuration in your application.properties? etc...

Big Tom

unread,
Jan 4, 2016, 5:12:02 PM1/4/16
to Light Admin Group
OK, entity is:

@Entity
@Table(name = "VAT", indexes = { @Index(columnList = "UPDATED_BY", name = "FK_VAT_UPDATED_BY_USER_ID") })
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({ "id", "vat"})
@JsonIdentityInfo(generator = IntSequenceGenerator.class, property = "@id")
public class ValueAddedTax extends AuditableEntity {

    private static final long serialVersionUID = 6287256601770398030L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID", unique = true, nullable = false)
    private Integer id;

    @Column(name = "VAT_PCT", nullable = false, precision = 4, scale = 2)
    private Double vat;
  
    //getters, setters, equals, hashcode, construcots, etc...
}

The repository is very simple

@RepositoryRestResource
public interface ValueAddedTaxRepository extends CrudRepository<ValueAddedTax, Integer> {

    @Query("Select v.vat from ValueAddedTax v WHERE v.validTo IS NULL AND v.validFrom = (Select MAX(vi.validFrom) from ValueAddedTax vi WHERE vi.validTo IS NULL)")
    public Double findCurrentVat();
}

and the administration:

public class ValueAddedTaxAdministration extends AdministrationConfiguration<ValueAddedTax> {

    private static Logger logger = LoggerFactory.getLogger(ValueAddedTaxAdministration.class);

    public ValueAddedTaxAdministration() {
        super();
        logger.trace(AppConstants.CONSTRUCTED_MSG);
    }

    @Override
    public EntityMetadataConfigurationUnit configuration(EntityMetadataConfigurationUnitBuilder configurationBuilder) {
        return configurationBuilder
                .singularName("VAT")
                .pluralName("VAT")
                .nameExtractor(vatNameExtractor())
                .build();
    }

    @Override
    public ScreenContextConfigurationUnit screenContext(ScreenContextConfigurationUnitBuilder screenContextBuilder) {
        return screenContextBuilder.screenName("VAT Administration").build();
    }

    @Override
    public FieldSetConfigurationUnit listView(FieldSetConfigurationUnitBuilder fragmentBuilder) {
        return fragmentBuilder
                .field("id").caption("ID")
                .field("vat").caption("Tax (%)")
                .field("status").caption("Status")
                .field("validFrom").caption("Valid From")
                .field("validTo").caption("Valid To")
                .field("updatedBy").caption("Updated By")
                .build();
    }

    @Override
    public FieldSetConfigurationUnit quickView(FieldSetConfigurationUnitBuilder fragmentBuilder) {
        return fragmentBuilder
                .field("id").caption("ID")
                .field("vat").caption("Tax (%)")
                .field("status").caption("Status")
                .field("validFrom").caption("Valid From")
                .field("validTo").caption("Valid To")
                .field("updatedBy").caption("Updated By")
                .build();
    }

    @Override
    public FieldSetConfigurationUnit showView(FieldSetConfigurationUnitBuilder fragmentBuilder) {
        return fragmentBuilder
                .field("id").caption("ID")
                .field("vat").caption("Tax (%)")
                .field("status").caption("Status")
                .field("validFrom").caption("Valid From")
                .field("validTo").caption("Valid To")
                .field("updatedBy").caption("Updated By")
                .build();

    }

    @Override
    public FieldSetConfigurationUnit formView(PersistentFieldSetConfigurationUnitBuilder fragmentBuilder) {
        return fragmentBuilder
                .field("id").caption("ID")
                .field("vat").caption("Tax (%)")
                .field("status").caption("Status")
                .field("validFrom").caption("Valid From")
                .field("validTo").caption("Valid To")
                .field("updatedBy").caption("Updated By")
                .build();
    }

    @Override
    public FiltersConfigurationUnit filters(FiltersConfigurationUnitBuilder filterBuilder) {
        return filterBuilder
                .filter("ID", "id")
                .filter("Tax (%)", "vat")
                .filter("Status", "status")
                .filter("Valid From", "validFrom")
                .build();
    }

    @Override
    public ScopesConfigurationUnit scopes(ScopesConfigurationUnitBuilder scopeBuilder) {
        return super.scopes(scopeBuilder);
    }

    @Override
    public SidebarsConfigurationUnit sidebars(SidebarsConfigurationUnitBuilder sidebarsBuilder) {
        return super.sidebars(sidebarsBuilder);
    }

    private static EntityNameExtractor<ValueAddedTax> vatNameExtractor() {
        return new EntityNameExtractor<ValueAddedTax>() {

            private static final long serialVersionUID = 5299671950081648728L;

            @Override
            public String apply(final ValueAddedTax valueAddedTax) {
                //String vat = valueAddedTax == null || valueAddedTax.getVat() == null ? "" : valueAddedTax.getVat().toString();
                return "vat";
            }
        };
    }
}

Big Tom

unread,
Jan 4, 2016, 11:39:19 PM1/4/16
to Light Admin Group
for what it's worth, I've played around with the edit.jsp jQuery function upon form submit to replace null values with an enpty string:


 $(domain_form).submit(function () {
            return new FormViewController(ApplicationConfig.RESOURCE_NAME).updateDomainEntity(this, function (domainEntity) {
                window.location = (domainEntity.getDomainLink() == null ? "" :  domainEntity.getDomainLink()) + '?updateSuccess=true';
            });
});

What I'm getting now upon success of DML is something like this:

https://localhost:8443/testapp/admin/domain/valueAddedTaxes/1/edit?updateSuccess=true

It's better than a redirect to the error page on acoount of 404, but not by much. I'm lost. Very disappointed too!

Big Tom

unread,
Jan 5, 2016, 2:08:52 AM1/5/16
to Light Admin Group
Update:
I've manages to work around this issue using the following code on the
edit.jsp and very similar code on the create.jsp (just replace var suffix = "/edit";  with var suffix = "/create";):

This is just a workaround. In my opinion we must find out why domainEntity.getDomainLink() returns null
even if the DML is successful. I'm very uncomfortable with this mystery.

<script type="text/javascript">

    $(function () {
        var domain_form = $("#${domainTypeFormName}");

        var url = window.location.href;
        var suffix = "/edit";
        url = url.substring(0,url.length - suffix.length);

        formViewVisualDecoration(domain_form);

        new FormViewController(ApplicationConfig.RESOURCE_NAME).loadDomainEntity('${entityId}', $(domain_form));

        <c:if test="${not dialogMode}">
        $(":button[name='cancel-changes']", $(domain_form)).click(function () {
            history.back();
        });

        $(":button[name='save-changes']", $(domain_form)).click(function () {
            $(domain_form).submit();
        });


        $(domain_form).submit(function () {
            return new FormViewController(ApplicationConfig.RESOURCE_NAME).updateDomainEntity(this, function (domainEntity) {

                 window.location = (domainEntity.getDomainLink() == null ? url : domainEntity.getDomainLink()) + '?updateSuccess=true';
            });
        });
        </c:if>
    });
</script>
Reply all
Reply to author
Forward
0 new messages