I now have problem with using confirmDialog inside tabView.
Here is my confirmDialog
<p:confirmDialog global="true" showEffect="fade" hideEffect="explode">
<h:form>
<p:commandButton value="Yes" type="button"
styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="No" type="button"
styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</h:form>
</p:confirmDialog>
In the 1st tabView, I have a button with confirmation
<p:commandButton value="Import" icon="ui-icon-arrowrefresh-1-w"
update=":form:growl">
<p:confirm header="Confirmation" message="Are you sure?" />
</p:commandButton>
In the 2nd tabView, I have exactly that button.
And now my problem is: In the 1st tab, my confirmDialog have full text as I want: header and message, however in the 2nd tab, the header and message all become "null". Only button yes and no of confirmDialog still work. I don't know what is happening, please help me, how to make confirmDialog display full content in all tabView
p:confirm does not implement state saving, thus it loses its attributes' values after the first JSF lifecycle. It also evaluates EL only once at view build time.
How to fix state saving.
You can extends PrimeFaces' ConfirmBehavior, implement saveState, restoreState, and override the original behavior in faces-config.xml by behavior-id org.primefaces.behavior.ConfirmBehavior. Then you'll be able to render and re-render p:confirm on subsequent requests.
How to fix state saving and reevaluate EL bound attribute values.
You should create your own my:confirm, because you need a custom taghandler, and you can't substitute a taghandler of another taglibrary's tag in a non-ugly way.
Create ConfirmBehavior.
package my;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.component.behavior.ClientBehaviorContext;
import javax.faces.context.FacesContext;
import org.primefaces.behavior.base.AbstractBehavior;
import org.primefaces.component.api.Confirmable;
import org.primefaces.json.JSONObject;
public class ConfirmBehavior extends AbstractBehavior {
public final static String BEHAVIOR_ID = "my.ConfirmBehavior";
#Override
public String getScript(ClientBehaviorContext behaviorContext) {
FacesContext context = behaviorContext.getFacesContext();
UIComponent component = behaviorContext.getComponent();
String source = component.getClientId(context);
String headerText = JSONObject.quote(this.getHeader());
String messageText = JSONObject.quote(this.getMessage());
if (component instanceof Confirmable) {
String script = "PrimeFaces.confirm({source:\"" + source + "\",header:" + headerText + ",message:"
+ messageText + ",icon:\"" + getIcon() + "\"});return false;";
((Confirmable) component).setConfirmationScript(script);
return null;
} else {
throw new FacesException("Component " + source + " is not a Confirmable. ConfirmBehavior can only be "
+ "attached to components that implement org.primefaces.component.api.Confirmable interface");
}
}
public String getHeader() {
return eval(PropertyKeys.header, null);
}
public void setHeader(String header) {
setLiteral(PropertyKeys.header, header);
}
public String getMessage() {
return eval(PropertyKeys.message, null);
}
public void setMessage(String message) {
setLiteral(PropertyKeys.message, message);
}
public String getIcon() {
return eval(PropertyKeys.icon, null);
}
public void setIcon(String icon) {
setLiteral(PropertyKeys.icon, icon);
}
public enum PropertyKeys {
header(String.class), message(String.class), icon(String.class);
final Class<?> expectedType;
PropertyKeys(Class<?> expectedType) {
this.expectedType = expectedType;
}
}
#Override
protected Enum<?>[] getAllProperties() {
return PropertyKeys.values();
}
}
Create ConfirmBehaviorHandler.
package my;
import javax.faces.application.Application;
import javax.faces.view.facelets.BehaviorConfig;
import javax.faces.view.facelets.FaceletContext;
import javax.faces.view.facelets.TagAttribute;
import org.primefaces.behavior.base.AbstractBehaviorHandler;
public class ConfirmBehaviorHandler extends AbstractBehaviorHandler<ConfirmBehavior> {
private final TagAttribute header;
private final TagAttribute message;
private final TagAttribute icon;
public ConfirmBehaviorHandler(BehaviorConfig config) {
super(config);
this.header = this.getAttribute(ConfirmBehavior.PropertyKeys.header.name());
this.message = this.getAttribute(ConfirmBehavior.PropertyKeys.message.name());
this.icon = this.getAttribute(ConfirmBehavior.PropertyKeys.icon.name());
}
#Override
protected ConfirmBehavior createBehavior(FaceletContext ctx, String eventName) {
Application application = ctx.getFacesContext().getApplication();
ConfirmBehavior behavior = (ConfirmBehavior) application.createBehavior(ConfirmBehavior.BEHAVIOR_ID);
setBehaviorAttribute(ctx, behavior, this.header, ConfirmBehavior.PropertyKeys.header.expectedType);
setBehaviorAttribute(ctx, behavior, this.message, ConfirmBehavior.PropertyKeys.message.expectedType);
setBehaviorAttribute(ctx, behavior, this.icon, ConfirmBehavior.PropertyKeys.icon.expectedType);
return behavior;
}
}
Register ConfirmBehavior in faces-config.xml.
<?xml version="1.0" encoding="utf-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<behavior>
<behavior-id>my.ConfirmBehavior</behavior-id>
<behavior-class>my.ConfirmBehavior</behavior-class>
</behavior>
</faces-config>
Register ConfirmBehaviorHandler in your taglibrary my.taglib.xml.
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd"
version="2.2">
<namespace>http://mycompany.ru/my</namespace>
<tag>
<tag-name>confirm</tag-name>
<behavior>
<behavior-id>my.ConfirmBehavior</behavior-id>
<handler-class>my.ConfirmBehaviorHandler</handler-class>
</behavior>
</tag>
</facelet-taglib>
Now you can use my:confirm, just as you would use p:confirm, but with state saving and dynamic EL evaluation.
It seems to work ok for me. See example below
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>JSF User Dialog</title>
</h:head>
<h:body>
<h3>This is a JSF view.</h3>
<h:form id="form">
<p:confirmDialog global="true" showEffect="fade" hideEffect="explode">
<h:form>
<p:commandButton value="Yes" type="button"
styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="No" type="button"
styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</h:form>
</p:confirmDialog>
<p:tabView id="tabView">
<p:tab id="tab1" title="Tab one ">
<p:commandButton value="Import" icon="ui-icon-arrowrefresh-1-w"
update=":form">
<p:confirm header="Confirmation" message="Are you sure?" />
</p:commandButton>
</p:tab>
<p:tab id="tab2" title="Tab two">
<p:commandButton value="Import" icon="ui-icon-arrowrefresh-1-w"
update=":form">
<p:confirm header="Confirmation" message="Are you sure?" />
</p:commandButton>
</p:tab>
</p:tabView>
</h:form>
</h:body>
</html>
Output:
It would be good if you post your full xhtml code so we can see what could be the problem there.
I had the same problem with the component. The proposed solution of removing the dynamic true works, but when we have to work in a dialog does not meet because the data are no longer updated automatically resulting in that the fields are blank.
If this happens you must perform the following action.
Ex:.
<p:commandButton style="font-size: 12px;width:30px;height:20px;" icon="ui-icon-trash">
<p:confirm header="Confirmação" message="Você realmente quer excluir o item de despacho?" icon="ui-icon-alert" />
</p:commandButton>
<p:growl id="growl" showDetail="true" />
<p:confirmDialog global="true" showEffect="fade" hideEffect="explode" style="font-size: 12px;" closeOnEscape="true" widgetVar="confir">
<p:commandButton id="confirm" value="Sim" ajax="true" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" style="font-size: 12px;">
<p:ajax event="click" listener="#{tableExpedicao.excluiItem}" update="confirm" oncomplete="confir.hide()"> </p:ajax>
</p:commandButton>
<p:commandButton value="Não" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" style="font-size: 12px;" oncomplete="confir.hide()"/>
</p:confirmDialog>
Related
In a jsf/primefaces(version 6.2) project I have this peace of code to display a list of records in an accordion.
All the records are displayed correctly.
Inside a ui:repeat I have a p:commandButton to be able to save some text fragments (fragmt) using f:setPropertyActionListener.
I'm also implementing a second f:setPropertyActionListener to get an object (sRes). This one is working fine.
But the currentFrag variable get always populated with the text framgments from the last accordion.
<h:form id="accord" >
<p:accordionPanel value="#{myBean.lucSearchResults}" var="sRes" multiple="true">
<p:tab title="#{sRes.score}">
<ui:repeat value="#{sRes.frags}" var="fragmt">
<h:panelGrid columns="2" cellpadding="10">
<h:panelGrid columns="1" cellpadding="10">
<h:outputText value="#{fragmt}" escape="false"/>
<hr/>
</h:panelGrid>
<h:panelGrid columns="1" cellpadding="10">
<p:commandButton action="#{myBean.saveFrag}" value="Save" >
<f:setPropertyActionListener value="#{sRes}" target="#{myBean.currentSearchResult}" />
<f:setPropertyActionListener value="#{fragmt}" target="#{myBean.currentFrag}" />
</p:commandButton>
</h:panelGrid>
</h:panelGrid>
</ui:repeat>
</p:tab>
</p:accordionPanel>
</h:form>
I have a long experience with JSF and Java. I have no explanation for this strange behavior.
Any help or pointer on this issue is much appreciated.
I can reproduce this using Primefaces 7.0, Mojarra 2.3.3, JVM 1.8.0_152-b16, Apache Tomcat 9.0.21, Openwebbeans 2.0.7 using this example:
<h:form id="frm">
<p:accordionPanel id="accordion" value="#{myBean.cats}" var="cat"
multiple="true">
<p:tab id="tab" title="#{cat.name}">
<ui:repeat var="kid" value="#{cat.kitten}">
<h:panelGroup id="group">
<p:commandButton id="cmdSubmit" action="#{myBean.doSomething()}"
value="submit #{cat.name} - #{kid.name} " process="#form"
update=":frm:output">
<f:setPropertyActionListener value="#{cat}"
target="#{myBean.cat}" />
<f:setPropertyActionListener value="#{kid}"
target="#{myBean.kid}" />
</p:commandButton>
</h:panelGroup>
</ui:repeat>
</p:tab>
</p:accordionPanel>
<h:outputText id="output"
value="#{myBean.cat.name} - #{myBean.kid.name}" />
</h:form>
This is my bean:
package my.package;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
#Named
#ViewScoped
public class MyBean implements Serializable {
private static final long serialVersionUID = 43L;
private List<Cat> cats;
private Cat cat;
private Cat kid;
#PostConstruct
public void init() {
cats = new ArrayList<>();
for (int i = 0; i < 10; i++) {
final Cat cat = new Cat();
cats.add(cat);
cat.setName(String.valueOf(i));
cat.setKitten(new ArrayList<>());
for (int j = 0; j < 5; j++) {
final Cat kid = new Cat();
kid.setName(i + "." + j);
cat.getKitten().add(kid);
}
}
}
public void doSomething() {
System.err.println(cat.getName() + " / " + kid.getName());
}
// getters & setters ...
public static class Cat {
private String name;
private List<Cat> kitten;
// getters & setters ...
}
}
When hitting e.g. the command button reading "5 - 5.4" the output is "5 - 9.4":
When replacing p:accordion/p:tab with ui:repeat, this example works as expected. This suggests it has something todo with primefaces dynamic tabs and might be worth a bug report.
When replacing process="#form" with process="#this" or process="group" it also works as expected and outputs the correct label of the button pressed.
An even better work around for this is to use the p:repeat component implemented to solve known incompatibilities between tabView/accordion/dataTable and different ui:repeat implementations.
I am using primefaces 5.1 and still facing problem with p:dialog and p:inputText within that dialog.
Here is the .xhtml content
<ui:define name="content">
<f:metadata> <f:viewAction action="#{vLoginController.initSetup}" /> </f:metadata>
<h:form id="vhome" prependId="false">
<table>
<tr>
<td>
<p:commandButton value="Place Order" action="#{vLoginController.placeOrderHomePage}"
update="logindialog, signupdialog"/>
</td>
</tr>
</table>
<p:dialog id="logindialog" header="Login / Sign up" visible="#{vLoginController.loginDialog}"
draggable="false" resizable="false" modal="true">
<p:messages autoUpdate="true"/>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="inuserid" value="EmailID:" />
<p:inputText id="inuserid" size="40" value="#{vLoginController.user.userId}" />
<h:outputLabel for="inpassword" value="Password:" />
<p:password id="inpassword" size="20" value="#{vLoginController.user.password}" />
<f:facet name="footer">
<p:commandButton value="Login" process="#form" action="#{vLoginController.validateLogin}" update="logindialog"/>
<p:commandButton value="Sign up" action="#{vLoginController.showSignup}" update="logindialog, signupdialog"/>
</f:facet>
</h:panelGrid>
</p:dialog>
<p:dialog id="signupdialog" header="Sign up / Login" visible="#{vLoginController.signupDialog}"
draggable="false" resizable="false" modal="true">
<p:outputLabel>Test</p:outputLabel>
</p:dialog>
</h:form>
</ui:define>
Here is the supporting Bean
#Named
#SessionScoped
public class VLoginController extends BaseController implements Serializable {
private VUser user;
public VLoginController() {
}
public void placeOrderHomePage() {
loginDialog = true;
signupDialog = false;
}
public String validateLogin() {
// Validate the screen fields
FacesMessage msg = new FacesMessage();
msg.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext context = FacesContext.getCurrentInstance();
if (user.getUserId() == null || user.getPassword() == null) {
msg.setSummary("Enter User ID and Password");
context.addMessage("screenvalidation", msg);
return null;
}
}
}
public class VUser implements Serializable {
public VUser() {
}
private int userSeq;
private String userId;
private String userType;
private String password;
private String salt;
private int active;
}
The userID and password in the user object are always null. Have gone through various forums content and tried like adding outputpanel around them etc., but none works. Have kept the code very similar to what the primefaces showcase says, still doesn't work.
Any solution please.. Please note that there is no problem in showing or hiding the dialog boxes, those logic works perfect. I just need to get the values entered by the user in the dialog fields to the bean..
This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 5 years ago.
Am a newbie to JSF. Am using JSF 2 and primefaces 4.0 in my application. As stated in the Title, the input value given in the xhtml page, does not set the value to the ManagedBean. I have tried all the possible combination.
growlMessage.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form>
<p:growl id="growl" showDetail="true" sticky="true" />
<p:panel id="panelID" header="Growl">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="msg" value="Message:" />
<p:inputText id="msg" value="#{growlView.message}" required="true" />
</h:panelGrid>
<p:commandButton value="Save" actionListener="#{growlView.saveMessage}"/>
</p:panel>
</h:form>
</h:body>
</html>
`
GrowlView.java:
import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
#ManagedBean
#ViewScoped
public class GrowlView implements Serializable{
private String message;
public GrowlView() {
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public void saveMessage(){
System.out.println("##### hello");
System.out.println("#####"+ getMessage());
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Successful", "Your message: "+message));
context.addMessage(null, new FacesMessage("Second message", "Additional Message details"));
}
}
Do you have a good reason to use JSF 2.0 instead of 2.2? You should use CDI instead of JSF managed beans, which is more or less deprecated. So, use
#Named
#ViewScoped
public class GrowlView implements Serializable
Be sure the ViewScoped annotation is from javax.faces.view. And the beginning of the xhtml should use the new namespace:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
Your commandButton should look like this (according to PrimeFaces showcase):
<p:commandButton value="Save" actionListener="#{growlView.saveMessage}" update="growl"/>
Have you tried setting a larger scope to your managed bean, for example #SessionScoped ?
(just for testing purposes). So you could exclude a possible scope problem.
try this following code: using the process and partialSubmit attributes:
<p:commandButton value="Save" actionListener="#{growlView.saveMessage}" update="growl" process="#form" partialSubmit="true"/>
hy,
change for
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form>
<p:growl id="growl" showDetail="true" sticky="true" autoUpdate="true"/>
<p:panel id="panelID" header="Growl">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="msg" value="Message:" />
<p:inputText id="msg" value="#{pageView.message}" required="true" />
</h:panelGrid>
<p:commandButton value="Save" action="#{pageView.saveMessage}" update="growl"/>
</p:panel>
</h:form>
</h:body>
</html>
and replace
#ManagedBean
with
#ManagedBean(name="pageView")
I know this is a very common issue which happens for a variety of reasons, but although I have searched about it a lot, I didn't manage to find a solution for my case.
My primefaces commandButton is inside an h:form and is declared as follows:
<p:commandButton action="#{userGroupBean.createOrUpdateItemAction}"
value="#{userGroupBean.actionCreateOrUpdateLabel}"
icon="iconDisk"
update="#form"
oncomplete="window.scrollTo(0,0);" />
My UserGroupBean is ViewScoped.
This button when clicked is supposed to create a userGroup and show a "Successful creation" message. Instead of doing this it just shows "Please wait" loader for a second and then does nothing. There are no errors in the log and through remote debugging I confirmed that it doesn't enter the action method.
The weird thing is that when I run the same code in a local Tomcat installation it runs successfully. Also, on the remote server this application is deployed, this used to work just fine. All happened suddenly, and I have a lot of commandButtons like this one, across my application which still work great. Something seems to go wrong just with this particular page .
I use PrimeFaces 3.1 version, I dont know what other information is usefull to provide.
Any help/ideas is/are appreciated.
EDIT
This is userGroup.xhtml (the page whose buttons do not work) code:
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:comps="http://java.sun.com/jsf/composite/components"
template="/WEB-INF/templates/userGroup/edit.xhtml">
<f:metadata>
<f:event type="preRenderView" listener="#{userGroupBean.initUserGroupUsersList}" />
</f:metadata>
<ui:define name="title">
User Group
</ui:define>
<ui:define name="centerUnit">
<h:form>
<h:panelGrid columns="3" styleClass="ui-messages-info ui-corner-all" rendered="#{not empty flash.messages_info}">
<span class="ui-message-info-icon"></span>
#{flash.messages_info}
</h:panelGrid>
<p:messages showDetail="true" globalOnly="true" />
<p:panel header="Settings">
<h:panelGrid columns="3" cellpadding="5">
<h:outputLabel for="title" value="User Group Title:" />
<p:inputText id="title" value="#{userGroupBean.userGroup.title}" />
<p:message for="title" />
</h:panelGrid>
</p:panel>
<p:panel header="Members">
<p:pickList value="#{userGroupBean.usersGroupUsersList}" var="user"
iconOnly="true"
converter="userConverter"
itemLabel="#{user.username}" itemValue="#{user}">
<f:facet name="sourceCaption">Available</f:facet>
<f:facet name="targetCaption">Participating</f:facet>
<p:column style="width:25%">
<p:graphicImage value="#{facesContext.externalContext.request.contextPath}/../file?thumbnail=&downloadPath=#{user.contactDetails.picture.downloadPath}" width="40" height="40" />
</p:column>
<p:column style="width:25%">
<h:outputText value="#{user.username}" />
</p:column>
<p:column style="width: 50%">
<h:outputText value="#{user.contactDetails.lastName} #{user.contactDetails.firstName}"/>
</p:column>
</p:pickList>
</p:panel>
<p:commandButton
action="#{userGroupBean.createOrUpdateItemAction}"
value="#{userGroupBean.actionCreateOrUpdateLabel}"
icon="iconDisk"
update="#form"
oncomplete="window.scrollTo(0,0);" />
<p:separator />
<p:outputPanel style="text-align:right" layout="block" rendered="#{!userGroupBean.userGroup.isNew() and userGroupBean.hasUserModifyUserGroupAuthority()}">
<h:panelGroup>
<p:commandButton value="Delete" title="Do you want to delete this user group?"
action="#{userGroupBean.deleteItemAction}"
update="#form"
icon="iconDelete" />
<p:commandButton value="Leave user group" title="I want to leave this user group"
action="#{userGroupBean.userInSessionLeavesUserGroupAction}"
update="#form"
icon="iconUserGo"/>
</h:panelGroup>
</p:outputPanel>
</h:form>
</ui:define>
The UserGroupBean.java:
#Controller("userGroupBean")
#Scope(value = "view")
public class UserGroupBean extends GenericBean<UserGroup> {
private static final long serialVersionUID = 1L;
final Log logger = LogFactory.getLog(getClass());
#Autowired
private SessionServiceImpl sessionService;
#Autowired
protected UserGroupService userGroupService;
#Autowired
protected UserService userService;
#Override
public String getPageCreateOrUpdate() { return "userGroup.xhtml"; }
#Override
public String getPageList() { return "../../my/userGroups.xhtml"; }
/** Wrapper method which calls getItem() */
public UserGroup getUserGroup() { return getItem(); }
/** Wrapper method which calls setItem() */
public void setUserGroup(UserGroup UserGroup) { setItem(UserGroup); }
protected UserGroup findItemById(Integer userGroupId) {
return userGroupService.findUserGroupById(userGroupId);
}
#Override
protected void resolveCreateRequest(HttpServletRequest req) {
logger.debug("UserGroupBean::resolveCreateRequest()");
setItem( userGroupService.initializeUserGroup("") );
}
#Override
protected String createItem() {
try {
if(!isValidUsersSelection(new ArrayList<User>(usersGroupUsersList.getTarget())))
return null;
List<Integer> userIds = new ArrayList<Integer>();
for(User user: usersGroupUsersList.getTarget())
userIds.add(user.getId());
userGroupService.saveUserGroup(getUserGroup(), userIds);
helperFacesContext.addInfoMessageToFlash("User Group successfully created.");
return getPageCreateOrUpdate()+"?action=update&id="+getItem().getId()+"&faces-redirect=true";
}
catch (Exception e) {
JsfUtils.error("There was an error", e.getMessage());
return null;
}
}
.....
}
And finally the UservConverter.java
#FacesConverter(value = "userConverter")
public class UserConverter extends GenericConverter {
final Log logger = LogFactory.getLog(getClass());
private UserDAO getUserDAO(FacesContext facesContext) {
// #Autowired gives null
return (UserDAO) FacesContextUtils.getWebApplicationContext(facesContext).getBean("userDAO");
}
/**
* converts the String representation of the key back to the Object
*/
#Override
public Object getAsObject(FacesContext context, UIComponent component,
String value) throws ConverterException {
logger.info("UserConverter::getAsObject("+value+")");
Integer userId = Integer.valueOf(value);
try {
return getUserDAO(context).findById(userId);
} catch(Exception e) {
throw new ConverterException(handleException(context,e.getMessage()));
}
}
NEW CLUE: When I restart the server and only after that, when I access this page and manage to create a user group before userGroup.xhtml is fully loaded, the user group is created just fine. If I restart the server and wait till the page is loaded and then create a user group again nothing happens. This problem will drive me crazy at the end.
I'm unable to get the tabChange event to fire when the first form (id="form1") inputText doesn't have a value. When I supply a value in the inputText the tabChange event will fire. With that said the real question would be how to restructure the below so that the onChange will fire when the first tab's inputText if empty. Each of my tab's have different forms since they each have data entry and processing that is specific to each tab.
<html xmlns="http://www.w3c.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<p:tabView>
<p:ajax event="tabChange" listener="#{tabBean.onTabChange}"/>
<p:tab title="Tab I">
<h:form id="form1">
<p:inputText value="#{tabBean.inText}" required="true" requiredMessage="Required Field"/>
<p:commandButton value="test" actionListener="#{tabBean.submit}"/>
</h:form>
</p:tab>
<p:tab title="Tab II">
<h:form id="form2">
tab 2 content
</h:form>
</p:tab>
</p:tabView>
</h:body>
</html>
//Bean
public class TabBean extends BaseSessionBean{
private String inText;
public void onTabChange(TabChangeEvent event) {
FacesMessage msg = new FacesMessage("Tab Changed", "Active Tab: " + event.getTab().getTitle());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void submit(ActionEvent actionEvent){
System.out.println("form submitted");
}
public String getInText() {
return inText;
}
public void setInText(String inText) {
this.inText = inText;
}
}
one workaround: (remove required validation)
<p:inputText value="#{adminBean.registerationLocation}">
<p:ajax event="blur"/>
</p:inputText>
Try replacing TabChangeEvent with AjaxBehaviorEvent
javax.faces.event.AjaxBehaviorEvent