English 中文(简体)
JSF 2 - clearing component attributes on page load?
原标题:

The real question: Is there a way to clear certain attributes for all components on an initial page load?

Background info:

In my application, I have a JSF 2.0 frontend layer that speaks to a service layer (the service layer is made up of Spring beans that get injected to the managed beans).

The service layer does its own validation, and I do the same validation in the frontend layer using my own validator classes to try and avoid code duplication somehow. These validator classes aren t JSF validators, they re just POJOs.

I m only doing validation on an action, so in the action method, I perform validation, and only if it s valid do I call through to the service layer.

When I do my validation, I set the styleClass and title on the UIComponents using reflection (so if the UIComponent has the setStyleClass(:String) or setTitle(:String) methods, then I use them).

This works nicely, and on a validation error I see a nicely styled text box with a popup containing the error message if I hover over it. However, since the component is bound to a Session Scoped Managed Bean, it seems that these attributes stick. So if I navigate away and come back to the same page, the styleClass and title are still in the error state.

Is there a way to clear the styleClass and title attributes on each initial page load?

Thanks,

James

P.S. I m using the action method to validate because of some issues I had before with JSF 1.2 and it s validation methods, but can t remember why... so that s why I m using the action method to validate.

最佳回答

Ok, so I must use a PhaseListener, see this blog entry by BalusC and this other blog entry, that s a much better way of doing what I m doing already - setting the styleClass manually using reflection - which gets all components with messages and highlights them... I m gonna do the same, however think it s possible to add an attribute instead, haven t tried it yet.

问题回答

暂无回答




相关问题
Bind Button.IsEnabled to custom validation with XAML?

I am sorry I didn t know how to title my question any better, you name it if you got a good 1. I have an entity Contact. this person has navigation properties: Address, Phones (A collection of Phone)....

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

Rails 101 | validates_currency?

I ve searched high and low, but I could not find a solution, to what I think seems like a very common task. In a form I want to have a text input that accepts currency strings (i.e. $1,000,000 or ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签