PrimeFaces commandButton不起作用

时间:2013-04-07 14:41:37

标签: primefaces commandbutton

我知道这是一个非常常见的问题,出于各种原因,但是虽然我已经搜索了很多,但我没有设法为我的案例找到解决方案。

我的primefaces commandButton在h:表单中,声明如下:

<p:commandButton action="#{userGroupBean.createOrUpdateItemAction}"
                 value="#{userGroupBean.actionCreateOrUpdateLabel}" 
                 icon="iconDisk"
                 update="@form"
                 oncomplete="window.scrollTo(0,0);" />

我的UserGroupBean是ViewScoped。

单击此按钮应该创建一个userGroup并显示“成功创建”消息。而不是这样做只是显示“请等待”加载器一秒钟,然后什么都不做。日志中没有错误,通过远程调试我确认它没有进入操作方法。

奇怪的是,当我在本地Tomcat安装中运行相同的代码时,它成功运行。此外,在远程服务器上部署了此应用程序,这用于工作得很好。一切都突然发生了,我有很多像这样的commandButtons,在我的应用程序中仍然很好用。这个特定的页面似乎出现了问题。

我使用的是PrimeFaces 3.1版本,我不知道其他哪些信息是有用的 任何帮助/想法是/赞赏。

EDIT
这是userGroup.xhtml(按钮不起作用的页面)代码:

<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>

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;
    } 
}
 .....
}

最后是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:当我重新启动服务器并且之后,当我访问此页面并设法在userGroup.xhtml完全加载之前创建用户组时,创建用户组就好了。如果我重新启动服务器并等到页面加载,然后再次创建用户组则没有任何反应。这个问题最终会让我发疯。

0 个答案:

没有答案