Amit,
One more thing: Is there any h:messages tag on your page? If the form
doesn't pass validation, then your action method will never get called.
Amit Kushwaha wrote:
Jeff,
Yup and Sure.
Below's some code snippet..
<h:form id="TaskSearch">
<h:inputText id="dateFrom"
value="#{postSearch.searchCriteria.dateFrom}"/>
<h:inputText id="dateTo" value="#{postSearch.searchCriteria.dateTo}"/>
.. some more inputs here....
<h:commandButton id="Submit" action="#{postSearch.search}"
value="Search"/>
</h:form>
The managed bean in the faces config is configured as,
<managed-bean>
<managed-bean-name>postSearch</managed-bean-name>
<managed-bean-class>backingbeans.PostSearch</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
... some service definitions here that reference spring beans...
</managed-bean>
The managed bean is defined as below,
public class TaskSearch {
private List posts;
private PostSearchCriteria searchCriteria;
... some service definitions....
public String search() {
// log or print that method got executed.
// do the search
}
}
So it seems that the search() is called just once, the 1st time when we
press the commandButton. The rest of the
times it gets the info from the session, w/o executing anything. If the
scope is changed to request, the search method
is executed however many times you press the commandButton. Is this
something that's expected and I need to
add anything when the scope is changed to session or its missing something?
Please let me know if you need more complete definitions or any other info.
TIA.
Amit.
Jeff Bischoff wrote:
You mean an action method on a commandButton? Can you show it to us?
Amit Kushwaha wrote:
Sorry by method, I meant the managed bean method that gets executed
through the method value binding expression on a button on the form.
Jeff Bischoff wrote:
Amit Kushwaha wrote:
Okay. The domain object part is working fine now ie when I set the
beans in the request / session scope.
Sorry for the confusion. Am still wondering why it didnt work on
the 1st attempt yesterday.
Anyway though, when the bean is put into session scope the
behaviour is a bit different from when its in
the request scope. The methods on the managed bean seem to get
executed just once. After that it sort
of gets the components from the session and repaints the view w/o
executing the method again. Is this
expected?
TIA.
Amit.
Without executing which method again? The managed bean constructor?
The getter method on the property for the domainObject?
Andrew Robinson wrote:
Request scope works fine as long as you don't expect your managed
bean's data to be there on the POST back. Reqest means just that, the
managed bean is created for the life of one request and one request
only. So in your case, your member variables (domainObject) will be
null when you POST your form. t:saveState restores values between
requests by storing variables into the component state and restoring
them on POST of the form.
On 11/30/06, Amit Kushwaha <[EMAIL PROTECTED]> wrote:
Andrew,
Yup, the managed bean was in the session scope.
But why wouldn't it work for a request scope? Cos, all managed
beans in
the application are dealing with domain objects. It would ideal
to put
some managed beans in just the request scope.
TIA.
Amit
Andrew Robinson wrote:
> Sounds like your managedBean's scope is not what you need. Use
session
> scope, Conversation scope (from 3rd parties) or use t:saveState.
>
> On 11/30/06, Amit Kushwaha <[EMAIL PROTECTED]> wrote:
>> Hi.
>>
>> Am trying to set/push in some properties on a domain object in
a managed
>> bean from an input form.
>>
>> So on the input form, I got some fields like this,
>>
>> <h:inputText id="someProperty"
>> value="#{managedBean.domainObject.property}"/>
>>
>> And in the managed bean and domain object,
>>
>> class ManagedBean {
>>
>> private DomainObject domainObject;
>>
>> public ManagedBean() {
>> domainObject = new DomainObject();
>> }
>>
>> setters/getters...
>>
>> }
>>
>> class DomainObject {
>>
>> private String property;
>>
>> setters/getters...
>>
>> }
>>
>> The property doesn't get set. What is missing?
>>
>> If the property in the domain object is moved in to the
managed bean and
>> the view changed to,
>>
>> <h:inputText id="someProperty" value="#{managedBean.property}"/>
>>
>> It works okay. This is using JSF + JSP.
>>
>> TIA.
>>
>> Amit.
>>
>>
>>
>>
>>
>>
>>
>