JSF/Seam - new component instance on submit?
And my confusion with JSF continues. This is a continuation of a question asked yesterday, but I feel it warrants a new question. I have a single seam component that expects a URL parameter to be injected for retrieving a List<String>
from a method. This works perfectly on the first navigation to the page. The List
is used to display many different selectOneRadio
groups that populate a <h:form/>
.
Now on the submit, I cannot get the URL parameter to be injected or otherwise set on the component! Adding <h:inputHidden/>
causes FacesExceptions to be thrown.
Then I tried setting the List
as an instance variable on the object, and when the subsequent call is made on the submit (which I also do not understand why that is done) I check to see if the variable is non-null: if it isn't, return it.
Now I found that a new instance of the component is created on submit!!!
getList() called
this.toString(): .BeanAction@5fd98420
#### This is when submit is clicked
getList() called
this.toString(): .BeanAction@22aacbce
The component has the following annotations:
Stateful
@Scope(ScopeType.CONVERSATION)
@Name("bean")
@Restrict("#{identity.loggedIn}")
Can someone explain why there is a new instance of the component created? I'm really not quite sure how to go about handling this. I thought the hidden parameter would work, because that is how I would do it with straight HTML, and I'm a little surprised that its not working for JSF/Seam.
I hit upon the solution, but I still dont understand why it is required. By adding <S:conversationId/>
to the <h:commandButton/>
tag I am now getting the conversationId propagated across the form submit.
However, the seam documentation states:
If you don't do anything special, a non-faces request (a GET request for example)
will not propagate the conversation context and will be processed in a new
temporary conversation.
Which means Seam/JSF was treating my form submit as a "non-faces request". Why is that?
When you enter the page (or after the submit), do you see a conversation id in the url? I am concerned that perhaps the Seam Conversation is not being initialized correctly.
精彩评论