it does not heled for me
but i changed mu SpringPage one method
public Object getBean(String beanName) {
if (beanName == null) {
throw new IllegalArgumentException("Null name parameter");
}
if (applicationContext == null) {
try {
applicationContext = new
ClassPathXmlApplicationContext("classpath*:META-INF/application-context.xml");
} catch (IllegalStateException e) {
logger.error("Application context is not set" +
e.getMessage());
}
}
return applicationContext.getBean(beanName);
}
i added context assignedment to getBean
and now it works but is it logicaly good i don't know
sabob wrote:
>
> Hi,
>
> You cannot access the applicationContext from the Page constructor
> because Spring only injects the context after the Page is constructed.
>
> This problem line is this one:
>
> logger.error("Text from interface " +
> getDatabaseFunctions().getText(getUserName()));
>
> Move that line to Page#onInit() and it should work.
>
> Please note, this is not a Click limitation but simply they way setter
> dependency injection works.
>
> kind regards
>
> bob
>
> On 6/12/09, aurmam <[email protected]> wrote:
>>
>> ok it seems that my function is being null
>> so i created a new SpringPage file
>> that has some methods the BorderPage extends this page
>>
>> public class SpringPage extends Page implements ApplicationContextAware,
>> AuthorizationService {
>>
>> protected Logger logger;
>> private ApplicationContext applicationContext;
>>
>> @SuppressWarnings("unchecked")
>> public Logger getLogger(Class cl) {
>> if (logger == null) {
>> logger = Logger.getLogger(cl);
>> }
>> return logger;
>> }
>>
>> public DatabaseFunctions getDatabaseFunctions() {
>> logger.error("running getFunctions");
>> return (DatabaseFunctions) getBean("databaseFunctions");
>> }
>>
>> public DatabaseService getDatabaseService() {
>> return (DatabaseService) getBean("databaseService");
>> }
>>
>> public PermissionService getPermissionService() {
>> return (PermissionService) getBean("permissionService");
>> }
>>
>> public String getUserName() {
>> return
>> SecurityContextHolder.getContext().getAuthentication().getName();
>> }
>>
>> public boolean hasPermission(String permission) {
>> return AuthorityUtils.userHasAuthority(permission);
>> }
>>
>> public Authentication getAuthentication() {
>> return SecurityContextHolder.getContext().getAuthentication();
>> }
>>
>> public GrantedAuthority[] getAuthorities() {
>> return getAuthentication().getAuthorities();
>> }
>>
>> public Object getBean(String beanName) {
>> if (beanName == null) {
>> throw new IllegalArgumentException("Null name parameter");
>> }
>> if (applicationContext == null) {
>> throw new IllegalStateException("Application context is not
>> set");
>> }
>> return applicationContext.getBean(beanName);
>> }
>>
>> public void setApplicationContext(ApplicationContext applicationContext)
>> throws BeansException {
>> this.applicationContext = applicationContext;
>>
>> }
>>
>> as you see everything is implemented
>> when loading aplications applicationContext is being asigned but when i
>> run
>> my app file
>>
>> for example this one
>>
>> import org.apache.log4j.Logger;
>>
>> public class HomePage extends BorderPage {
>>
>> private Logger logger = getLogger(getClass());
>>
>> @SuppressWarnings("unchecked")
>> public HomePage() {
>>
>> if (hasPermission(Permission.LOGIN)) {
>> logger.error("has permision :" + getUserName());
>> }
>>
>> logger.error("Logged in as :" + getUserName());
>> logger.error("Text from interface " +
>> getDatabaseFunctions().getText(getUserName()));
>> getModel().put("title", getUserName());
>> }
>> }
>>
>> i get
>> java.lang.IllegalStateException: Application context is not set
>> the line in bold
>>
>> how can i save application context?
>>
>> i attaching my web.xml
>> besided i am using spring security libs with CAS al logins and my custom
>> UserDetailService is working
>> http://n2.nabble.com/file/n3066822/web.xml web.xml
>>
>>
>>
>> --
>> View this message in context:
>> http://n2.nabble.com/problem-with-spring-injection-tp3049285p3066822.html
>> Sent from the click-user mailing list archive at Nabble.com.
>>
>>
>
>
> --
> http://incubator.apache.org/click/
>
>
--
View this message in context:
http://n2.nabble.com/problem-with-spring-injection-tp3049285p3067436.html
Sent from the click-user mailing list archive at Nabble.com.