Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7895275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:36:12+00:00 2026-06-03T07:36:12+00:00

I am using spring and I have a child model with a objectify key

  • 0

I am using spring and I have a child model with a objectify key object – “Key parent”

The getAsText prints ok when form is being loaded, but when the form submit, setAsText is skipped. Any reason? and the parentType is empty when it arrives the Controller. Is it the form issue or controller or the editor?

(side track: Is there an editor written for Objectify Key <-> String mapping?)

Jsp

<form:hidden path="parentType"  />

Controller

    @InitBinder
    protected void initBinder(HttpServletRequest request,
            ServletRequestDataBinder binder) throws Exception {


        /** Key Conversion **/
        binder.registerCustomEditor(com.googlecode.objectify.Key.class,  new KeyEditor());
}
@RequestMapping(value = "/subtype-formsubmit", method = RequestMethod.POST)
    public ModelAndView subTypeFormSubmit(@ModelAttribute("productSubType") @Valid ProductSubType productSubType,
            BindingResult result){
        ModelAndView mav = new ModelAndView();

        //OK, getting the value
        log.info(productSubType.getType()); 

            //NOT OK, productSubType.getParentType() always null, and setAsText is not called?!
        log.info(productSubType.getParentType().toString()); 

        return mav;
    }

KeyEditor.java

public class KeyEditor extends PropertyEditorSupport {

private static final Logger log = Logger
        .getLogger(KeyEditor.class.getName());

public KeyEditor(){
    super();
}

@Override
public String getAsText() {
    Long id = ((Key) getValue()).getId();
    String kind = ((Key) getValue()).getKind();
    log.info(kind + "." + id.toString());
    return kind + "." + id.toString();
}

@Override
public void setAsText(String text) throws IllegalArgumentException {
    log.info(text);
    String clazz = text.substring(0, text.indexOf("."));
    Long id = Long.parseLong(text.substring(text.indexOf(".")));
    log.info(clazz+":"+id);
    Class c=null;
    Key<?> key=null;
    try {
        c = Class.forName(clazz);
        key = new Key(c, id);
    } catch (Exception ex) {
        log.info("ex" + ex.toString());
        ex.printStackTrace();
    }

    setValue(key);
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T07:36:14+00:00Added an answer on June 3, 2026 at 7:36 am

    You need to call Class.forName with the complete class name, including packages.

    I think that Key#getKind() returns the simple class name without packages. Also text.substring(0, text.indexOf(".")); (in setAsText) tells me there are no dots in clazz, so you’re not feeding the correct input to Class.forName

    Options:

    • if all your classes are in the same package, then just prepend that to clazz (not a very robust solution)
    • Since you have to register all of your entities anyway (ObjectifyService.register(YourEntity.class);), then you can simultaneously create a map from kind to complete class name, and then use it in setAsText.

    But there might be better options…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Spring 2.5 tag library, I have an Integer value in a command form
So I have model with an association and I'm using a single form with
I have a object model like this public class Parent{ public int Id; public
I have a rather complex model that I am using to render a form
I have an object from my domain model that has a child object. How
So I have a parent and child store, illustrated here: Parent Model Ext.define('APP.model.Client', {
I have two tables Parent and Child. Both tables have a primary key MyDate
I have my application using Spring MVC + Apache 2 tiles + Spring security,
I have been using spring for a while as my IOC. It has also
I have developed a web application using Spring 3.1 In one of the module

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.