| Author |
Message |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 04/07/2008 00:04:19
|
anandn
Joined: 19/06/2008 00:00:00
Messages: 13
Offline
|
Hi,
I am new to JSF and ICEFaces.
Can I defined a managed bean property with only a getter method and no setter method.
In my sample application, I have a managed bean that has a property "needLogin". I have defined only a getter method. The value of this property will be set by the "login" action within the bean.
I get a NoSuchMethodException
javax.faces.FacesException: java.lang.NoSuchMethodException: Property 'needLogin' has no setter method
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:310)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
com.icesoft.faces.webapp.http.core.JsfLifecycleExecutor.apply(JsfLifecycleExecutor.java:18)
com.icesoft.faces.webapp.http.core.PageServer$1.respond(PageServer.java:25)
com.icesoft.faces.webapp.http.servlet.ServletRequestResponse.respondWith(ServletRequestResponse.java:161)
com.icesoft.faces.webapp.http.servlet.ThreadBlockingAdaptingServlet$ThreadBlockingRequestResponse.respondWith(ThreadBlockingAdaptingServlet.java:36)
com.icesoft.faces.webapp.http.core.PageServer.service(PageServer.java:30)
com.icesoft.faces.webapp.http.core.SingleViewServer.service(SingleViewServer.java:48)
com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer$Matcher.serviceOnMatch(PathDispatcherServer.java:50)
com.icesoft.faces.webapp.http.common.standard.PathDispatcherServer.service(PathDispatcherServer.java:19)
com.icesoft.faces.webapp.http.servlet.ThreadBlockingAdaptingServlet.service(ThreadBlockingAdaptingServlet.java:19)
com.icesoft.faces.webapp.http.servlet.EnvironmentAdaptingServlet.service(EnvironmentAdaptingServlet.java:29)
com.icesoft.faces.webapp.http.servlet.MainSessionBoundServlet.service(MainSessionBoundServlet.java:139)
com.icesoft.faces.webapp.http.servlet.SessionDispatcher.service(SessionDispatcher.java:35)
com.icesoft.faces.webapp.http.servlet.PathDispatcher$Matcher.serviceOnMatch(PathDispatcher.java:52)
com.icesoft.faces.webapp.http.servlet.PathDispatcher.service(PathDispatcher.java:29)
com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:79)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
MyBean.java
---------------
import javax.faces.event.ActionEvent;
public class MyBean {
public boolean needLogin = true;
public MyBean() {
// TODO Auto-generated constructor stub
}
public boolean getNeedLogin() {
return needLogin;
}
public void login (ActionEvent e)
{
needLogin = false;
}
public void logout(ActionEvent e )
{
needLogin = true;
}
}
hw.jspx
---------
<f:view xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ice:outputDeclaration doctypeRoot="HTML"
doctypePublic="-//W3C//DTD XHTML 1.0 Transitional//EN"
doctypeSystem="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<title id="dynamicTitle"><h:outputText value="Hello World" />
</title>
</head>
<body>
<ice:form>
<ice:panelGroup styleClass="pageHeaderNavArea"
style="padding-top: 5px;">
<ice:commandLink immediate="true" rendered="#{myBean.needLogin}"
actionListener="#{myBean.login}">
<ice:outputFormat value="Login" />
</ice:commandLink>
<ice:commandLink immediate="true"
rendered="#{not myBean.needLogin}"
actionListener="#{myBean.logout}">
<ice:outputFormat value="Logout" />
</ice:commandLink>
</ice:panelGroup>
</ice:form>
</body>
</html>
</f:view>
faces-config.xml
-------------------
<faces-config>
<managed-bean>
<managed-bean-name>myBean</managed-bean-name>
<managed-bean-class>MyBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>needLogin</property-name>
<property-class>boolean</property-class>
<value/>
</managed-property>
</managed-bean>
</faces-config>
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 04/07/2008 01:21:11
|
gevaudan
Joined: 10/05/2008 00:00:00
Messages: 5
Offline
|
No, but if you are using Spring 2.5 you might want to consult the following url, specifically the @Resource annotation:
http://www.infoq.com/articles/spring-2.5-part-1
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 04/07/2008 06:25:25
|
asherwin
Joined: 27/06/2008 00:00:00
Messages: 83
Offline
|
I do this all the time, often used with outputText value attributes and don't have a problem with it. However, if you are having an issue (it is attempting to call the setter, for example) just create a setter that doesnt do anything.
All it cares about is the method EXISTS, it doesnt know what the setter does; for example:
Code:
public void setNeedLogin(final boolean login) {
// do nothing
}
|
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 04/07/2008 10:44:43
|
deryk.sinotte

Joined: 26/10/2004 00:00:00
Messages: 526
Offline
|
Some app servers are more "strict" about this as well. I believe some versions of WebSphere always complains if there is no setter. The best course is, as already mentioned, to define a setter with no implementation code.
|
Deryk Sinotte
Team Lead
ICEsoft Technologies, Inc. |
|
|
 |
![[Post New]](/JForum/templates/default/images/icon_minipost_new.gif) 04/07/2008 12:03:11
|
anandn
Joined: 19/06/2008 00:00:00
Messages: 13
Offline
|
Thanks for the suggestions. I implemented a setter method which does nothing. That works.
Also, If remove that property from the managed bean definition in faces-config.xml I am able to use the property in the page. The getter method is invoked to get the property value and render page appropriately.
So why do I need to define the property in faces config file? I guess I don't understand property binding concept yet. Is there a good document I can read on this?
Thanks
Anand
|
|
|
 |
|
|