How to use XML parameter in Java?

381 views Asked by At

I have this XML-Code:

<extension id="free_textfield" label="Description notes" readOnly="true"/>

Now I want to add a parameter there like

<extension id="free_textfield" label="Description notes" readOnly="true" text="sample string maybe with links"/>

Now I want to use this text-parameter in my Java class:

    public class FormExtensionExample implements IFormExtension {
    public static final String ID = "free_textfield";

    @Inject
    private IDataService service;

    @Override
    public String render(IPObject object, Map<String, String> attributes) {
        
        return null;
    }

How can I do this?

Thanks for your help!

1

There are 1 answers

0
Tanque On

Well all attributes that you specify in the Form Configuration like this:

<extension id="free_textfield" label="Description notes" readOnly="true" text="sample string maybe with links"/>

can be found in the attributes map parameter of the render() method you have to override:

@Override
public String render(IPObject object, Map<String, String> attributes) {

    // here you go:
    String myAttributeValue = attributes.get("text");
    // the following will print "sample string maybe with links"
    System.out.println(myAttributeValue);
    
    return null;
}