I have command buttons in the form. Those that are rendered on page load are invoking actions,
but those two in the <p:fragment>
tag are rendered on postback and are not working.
<h:form>
<p:commandButton action="#{bean.actionA()}"/>
<p:commandButton actionListener="#{bean.actionB()}"/>
<p:fragment rendered="#{not empty bean.field}">
<p:commandButton action="#{bean.actionA()}"/>
<p:commandButton actionListener="#{bean.actionB()}"/>
</p:fragment>
<ui:include ..>
...
<p:commandLink update="@form">
<i class="fa fa-folder"></i>
<f:setPropertyActionListener value="#{data.document}" target="#{bean.field}" />
</p:commandLink>
</ui:include>
</h:form>
I am noob in JSF. I know that issue is related to the JSF life cycle but I can not find a working solution.
My bean
is view scoped and I use primefaces 5.1.
Is this suppose to work or I am ussing wrong approach to show/hide buttons?
Thanks.
EDIT:
After some testing it seams that even when action is invoked is invoked on bean with null==bean.field
.
This doesn't make sense to me, because I get rendered value #{bean.field.name}
after update is done and hidden butons are displayed.
What am I missing?
Same effect when changing update=@form
to update=@all
.
Any help is appreciated.
My bean with session scope loks likek this. In this case of SessionScoped
buttons are working. Why view scope is not enough?
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import javax.faces.view.ViewScoped;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
//TODO: change to @ViewScoped
@ManagedBean(name="bean")
@SessionScoped
public class Bean extends BeanBase {
private static final long serialVersionUID = 1L;
private static final Logger LOGGER = LogManager.getLogger(Bean.class.getName());
@PostConstruct
protected void init() {
super.init();
}
public void actionA() {
LOGGER.debug("Action A triggerd!");
}
public void actionB( ActionEvent event) {
LOGGER.debug("Action B event triggerd!");
super.edit(event);
}
}
p:fragment
withp:outputPanel
orf:subview
buttons do not trigger. – urkonbean.field
setter and update call. I tried with the logging, but I do not know how to separate them into the JSF phases. On page load I have 12 cals of ´bean.field´ getter 3 of them are null. On button click I have 3 null returning getter cals. The difference is only that in one case action on bean is triggered. Hope this helps. – urkonnull==bean.field
. What am I missing? – urkon