h:commandLink action doens't fire within the same snippet that is to be replaced
In the Question commandButton/commandLink/ajax action/listener method not invoked or input value not updated there are 7 issues mentioned. Now, I have the same problem, but 开发者_如何学GoI don't see which of the issues mentioned are causes the problem I'm having... nor did I manage to find the solution in any articles I've read. I have an h:commandLink inside a snippet, which is in :main:profileContentSnippet in regard to the project:
...
<h:commandLink action="#{usersController.prepareModel}" value="ViewDetails" immediate="true">
<f:param name="pageViewId" value="EditDetails"/>
<f:ajax render=":main:profileContentSnippet" />
</h:commandLink>
...
Now, it is supposed to render :main:profileContentSnippet and modify it to present another snippet (which the commandLink is not a part of...). It renders EditProfilePersonalDetails, as sent by parameter. The commandLink action doesn't fire. Now if I remove it from the snippet that holds it, it works, but the h:commandLink is still there - and I wish it to disappear, as the snippet it resided on did... I wonder why's that? How can a control modify its own appearance if it is inside the snippet that is about to be replaced by another snippet using AJAX?
Thanks in advance.
Additional code:
The snippetFileName should change (and it is) after clicking on the h:commandLink from above. Now, the file that contains the h:commnandLink is replaced by:
<h:panelGroup id="messagePanel" layout="block">
<h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
</h:panelGroup>
</ui:composition>
Note: the h:commnadLink is in a ui:composition too. The Action in the managed bean that should be fired is:
@ManagedBean (name="usersController") @RequestScoped public class UsersController { public String prepareConnected() { //need to add getting user id from session System.out.println("in prepareConnected"); current = ejbFacade.find( (long)2);
if (current == null){
System.out.println("in prepareConnected is null");
JsfUtil.addSuccessMessage("User Deleted in other request");
return null;
}
return "viewPersonalDetails-snippet";
}
} ...
This include part holds the commandLink from above:
<h:panelGroup id="profileContentSnippet" >
<ui:include src="#{snippetsProfileLinkerBean.snippetFileName}"/>
</h:panelGroup>
basically, the snippet is modified, but the current variable stays null since the preapareConnected doesn't fire. If I remove it from the snippet to other part in the site that is not in the include part it works. The problem is that I wish the h:commandLink part will disappear as well.`
It seems that there is a web.xml definition that should have been made for this to work:
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
The problem was in the JSF 2 flow. First time the page is rendered, JSF builds a component tree, which means that only one of the snippets was in that tree at the time of the creation of the component tree. Therefore, in other requests (of the same page) only that component could have an action and an action listener registered. The other component didn't, because it was not in the component tree that was built from the start (though I could see it in the view). Now, modifying the definition of javax.faces.PARTIAL_STATE_SAVING to false, makes JSF 2 flow create on every request the component tree. It is not the best solution, but I didn't find any documentation on how inserting dynamically a component to the compont tree after it tree has already been built, other than build it again for each request.
精彩评论