This is the development blog of the Spring Rich Client Project Team.

Monday, January 14, 2008

Integrating xswingx Prompt

In this tutorial you will learn how to create your own FormComponentInterceptor, by integrating xswingx. The xswingx project provides input prompts.


As our new interceptor will intercept text components, we can subclass the TextComponentInterceptor class, which defines a protected void processComponent(String propertyName, JTextComponent textComponent) method:

public class PromptTextFieldFormComponentInterceptor extends TextComponentInterceptor {


The following attributes are needed. The MessageSource to fetch the prompt text, the FormModel to scope our message key, and the prompt key to construct the message key:

    private MessageSource messageSource;
private FormModel formModel;
private String promptKey;

public PromptTextFieldFormComponentInterceptor(FormModel formModel, MessageSource messageSource,
String promptKey) {
this.formModel = formModel;
this.messageSource = messageSource;
this.promptKey = promptKey;
}


The processComponent method will use the MessageSource to find the prompt text (using the keys created by the getMessageKeys method), and will use the xswingx PromptSupport class to install the prompt on the JTextComponent:

    protected void processComponent(String propertyName, JTextComponent textComponent) {
String prompt = messageSource.getMessage(new DefaultMessageSourceResolvable(getMessageKeys(formModel,
propertyName), ""), Locale.getDefault());

if (StringUtils.hasText(prompt)) {
PromptSupport.setPrompt(prompt, textComponent);
}
}


And finally the getMessageKeys method, which will create an array of message keys used to load the message. Two keys will be created, formModelId.propertyName.promptKey and propertyName.promptKey:

    protected String[] getMessageKeys(FormModel formModel, String propertyName) {
return new String[] { formModel.getId() + "." + propertyName + "." + promptKey,
propertyName + "." + promptKey };
}
}


Now define the interceptor in the formComponentInterceptorFactory bean in your application context:

 <bean class="org.springframework.richclient.form.PromptTextFieldFormComponentInterceptorFactory"/>


And add some messages to messages.properties:

firstName.prompt=<Enter the first name>
lastName.prompt=<Enter the last name>



This is the result:


14 comments:

Lieven Doclo said...

The bean definition won't work, since there is no default constructor. Trying to load the bean, results in a NoSuchMethodException for the empty constructor.

Ayodeji Onibalusi said...

good to be read post
read jokes

Ayodeji Onibalusi said...

good job read jokes

tania said...

@ Lieven Doclo, you are right!

- Tanya
Web Design Firm

Koon said...

good
Counter Depth French Door Refrigerator
How to Get Into Acting
Breville Smart Oven
How to Impress Woman
Picking Lottery Numbers
Canon Powershot A800
Adidas Barricade
Adidas Barricade 6.0
Cuisinart TOB-195
Acne Conglobata
Acer 11.6 Netbook
500 payday loan
acne inversa
VIZIO M261VP
checkmate payday loans
Pengurusan Masa

SEO Services said...

Thanks a lot for your interesting article. I have been looking for such content for a really long time. Not all your content is fully easy to understand to me, even though it is definitely interesting and worth reading.

SEO Services

Stacey said...

What a constructive blog! Many more people should do the same! Thank you very much. Regards - Android Application Development

sabreena said...

Hello,

Your Blogging techniques are very good and you are providing the knowledge in very light way, I have bookmarked your blog, Keep it up.

-------------

android bingo

hassan said...

great joke
android casino

sabreena said...

Good work dude.

-------------

android poker

sabreena said...

Nice post love your blog.This blog is awesome full of use full information that i was in dire need of.


-------------------

android blackjack

sabreena said...

Thanks for the awesome post. Keep on going; I will keep on eye on it.


---------------

iphone roulette

sabreena said...

I agree totally.
Even though the warnings are there, I can guarantee a lot of people have the code on their live box, or people will use it in the future.


-----------------

iphone slots

Kien Ha said...


Virtuemart Extensions

Virtuemart Templates

Joomla Furniture Template

Joomla Flower Template

One Page CheckOut for Virtuemart

Magento Jewelry Theme

Magento Printing Website Theme

Magento Facebook Login

Responsive Magento Themes

Magento Quick View Extension

Magento Color Swatch

Magento Themes

Magento Extensions