1

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=&amp;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.

Dani
  • 3,744
  • 4
  • 27
  • 35
kasimoglou
  • 384
  • 3
  • 17
  • Did you try "process" attribute(ex: process="@form"), if not, you should share more code :) – Rong Nguyen Apr 08 '13 at 02:36
  • I tried what you said but it didnt work. I added more code as you asked, though I am not sure if this is the case. Is it possible the same code to run on one machine correctly and on one other not? Thank you for your reply! – kasimoglou Apr 08 '13 at 09:55
  • Take a look here: http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked BalusC's reply helped me to solve a lot of problems like yours! – StepTNT Apr 08 '13 at 10:07
  • Yes, I know BalusC is great,his posts have helped me too in many other cases.Thank you very much for this post. But can this be a code matter? I mean why locally it runs fine? – kasimoglou Apr 08 '13 at 11:08
  • Ok I dont know why but I had to remove line for it to work. – kasimoglou Oct 31 '13 at 10:45

0 Answers0