Domanda

I'm using smooks (v1.5) to map from a csv file to a java bean collection for the records. At the moment, it's 1 big java bean for each CSV record.

I have some static global application data that I want mapping into my java beans (i.e. some data items that aren't in the csv records).

Currently, I'm adding this static data to my java beans by doing some post-smooks processing in my calling java class.

However, I'd like to be able to handle this in smooks if poss. Was thinking it would be nice to add a map of global parameters before the smooks filter, then have my smooks xml file be able to set the relevant property on each java bean.

Is this possible?

EDIT

I've found that I can add attributes to my execution context:

ExecutionContext executionContext = smooks.createExecutionContext();
executionContext.setAttribute("someParam", "someValue");

But how do I access this attribute in my smooks config to pass into my java bean?

È stato utile?

Soluzione

I created a simple bean for my static parameter and add

ExecutionContext executionContext = smooks.createExecutionContext();

MappingStaticParams staticParams = new MappingStaticParams();
staticParams.setSomeTextParam = "someValue";
BeanId beanId = executionContext.getBeanContext().getBeanId("staticParams");
executionContext.getBeanContext().addBean(beanId, staticParams );

This puts the bean in scope for my smooks filter config file which can use a jb expression to map the parameters:

<jb:expression property="staticText">staticParams.someTextParam</jb:expression>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top