0

I am new in topic JSF and develop a simple web dialog: My currently problem is: that my selectOneMenu component doesn't fire the actionListener and doesn't reRender the other components. Here is my JSF page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="cache-control" content="no-cache, must-revalidate">
<link href='styles/kn.css' rel="styleSheet" type="text/css" />
</head>

<style>
.top {
    vertical-align: top;
}
</style>

<body>

    <f:view>

        <f:loadBundle basename="messages" var="msg" />

        <h:form id="navigation">
            <%@include file="include/kn_header.jsp"%>
        </h:form>
        <h:form >
            <rich:panel styleClass="mainPanel" header="#{msg.log_title}"
                id="logviewer">



                <h:selectOneMenu value="#{logviewer.machine} " onchange="submit()" immediate="true">
                    <f:selectItems value="#{logviewer.machineList}" />
                    <a4j:support event="onchange"
                        actionListener="#{logviewer.processValueChanged}"
                        ajaxSingle="true" immediate="true" reRender="progressPanel" />
                </h:selectOneMenu>

                <rich:spacer height="10px" />
                <a4j:outputPanel id="progressPanel"
                    rendered="#{logviewer.isMachine}">
                    <rich:progressBar value="#{logviewer.currentValue}" interval="1000"
                        label="#{logviewer.currentValue} %" enabled="#{logviewer.enabled}"
                        minValue="-1" maxValue="100" reRenderAfterComplete="progressPanel">
                        <f:facet name="initial">
                            <br />
                            <a4j:commandButton action="#{logviewer.startProcess}"
                                value="Start Download" reRender="progressPanel"
                                rendered="#{logviewer.buttonRendered}"
                                style="margin: 9px 0px 5px;" />

                        </f:facet>
                        <f:facet name="complete">
                            <br />
                            <rich:spacer height="10px" />
                            <a4j:commandButton id="doDownload"
                                action="#{logviewer.doDownload}" value="button"
                                alt="#{msg.download}" title="#{msg.download}"
                                image="#{icon.download}">

                                <rich:toolTip value="#{msg.download}"
                                    style="background-color:#{richSkin.generalBackgroundColor}; border-color:#{richSkin.headerBackgroundColor}">
                                </rich:toolTip>

                            </a4j:commandButton>
                            <div class="TextArea">
                                <rich:panel styleClass="mainPanel">
                                    <h:inputTextarea id="logView" value="#{logviewer.log}"
                                        rows="35" style="font-size:10pt; width:100%" readonly="true" />
                                </rich:panel>
                            </div>
                        </f:facet>
                    </rich:progressBar>
                </a4j:outputPanel>


            </rich:panel>
        </h:form>

    </f:view>
</body>
</html>

and hier is my Bean:

package com.kn.documentserver.jsf;

import java.util.ArrayList;
import java.util.List;

import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;


import com.kn.commons.util.BeanLocator;
import com.kn.dcs.distribution.DownloadFile;
import com.kn.documentserver.entity.Machine;
import com.kn.documentserver.interfaces.IMachine;

public class LogviewerBean extends AbstractBean {

    // private final static Logger LOG =
    // Logger.getLogger(AdministrationBean.class);

    private List<SelectItem> machineList;

    private Machine machine;
    private int maxlength;
    private String logfile= null;
    private DownloadFile logFile;
    private boolean buttonRendered = true;
    private boolean enabled = false;
    IMachine s = BeanLocator.lookup(IMachine.class,
            "java:global/KN_DocumentServerFrontendJBoss/MachineBean");

    public LogviewerBean() {
        super();
        machineList = new ArrayList<SelectItem>(); 
        initMachineList(readMachineList());
    }

    private List<Machine> readMachineList() {

        return s.findAll();
    }

    private void initMachineList(List<Machine> machines) {
        for (Machine m : machines) {
            if (m.getMachineName().contains("KN")
                    && !m.getMachineName().equals("ASKNGHST")
                    && !m.getMachineName().equals("ASKNITRA")) {
                SelectItem item= new SelectItem(m.getMachineName(),m.getMachineName());
            machineList.add(item);
            }
        }
    }

    public List<SelectItem> getMachineList() {
        return machineList;
    }
    public void changeEvent() {
        System.out.println("Works");
    }

    public void setMachineList(List<SelectItem> machineList) {
        this.machineList = machineList;
    }

    public Machine getMachine() {
        return machine;
    }

    public String getLog() {
        return logfile;
    }

//  public GenericConverter getMachineConverter() {
//      
//      return new GenericConverter(machineList.values());
//  }

    public void setMachine(Machine machine) {

        this.machine = machine;
    }

    public String processValueChanged(ValueChangeEvent vce) {
        String temp = (String) vce.getNewValue();
        this.machine=s.findByName(temp);
        return null;

    }

    public void doshowLog() {
        setMachine(this.machine);

    }

    public int getMaxlength() {
        return maxlength;
    }

    public void setMaxlength(int maxlength) {
        this.maxlength = maxlength;
    }

    public boolean getIsMachine() {
        return (this.machine == null) ? false : true;
    }

    public String getLogfile() {
        return logfile;
    }

    public String startProcess() {
        setEnabled(true);
        setButtonRendered(false);
        logFile = new DownloadFile(machine);
        System.out.println(getTotalValue());
        logFile.start();
        return null;
    }

    public void setLogfile() {
        byte[] bytes = logFile.getLogfileAsbyte();
        if (bytes != null) {
            this.logfile = new String(bytes);
        }

    }

    public boolean getIsLogfileDownloaded() {
        return (this.logfile == null) ? false : true;
    }

    public long getTotalValue() {
        return logFile.getFilelength();
    }

    public Long getCurrentValue() {
        if (isEnabled()) {
            Long current = new Long(logFile.getCurrfilelength());
            current = (current * 100) / getTotalValue();
            if (current >= 100) {
                setButtonRendered(true);
                setLogfile();
                return Long.valueOf(101);
            } else {
                return current;
            }

        } else {
            return Long.valueOf(-1);
        }

    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public boolean isButtonRendered() {
        return buttonRendered;
    }

    public void setButtonRendered(boolean buttonRendered) {
        this.buttonRendered = buttonRendered;
    }




}

Could you please help me to investigate, what exactly going wrong.

Kind regards Alex

1 Answers1

0

If you are using JSF 1.2 or higher, please add prependId="false" to your second form (containing your selectOneMenu). Else (using JSF prior to 1.2), you set an id for your form and add it your the reRender (reRender="formId:progressPanel")

Laabidi Raissi
  • 3,263
  • 1
  • 22
  • 28
  • Thank you for your replay. I have added the id to the form: and to the reRender: reRender="log:progressPanel", unfortunalety it's doesn't work. The Methods, in the Bean class, didn't call. – user2186105 Mar 19 '13 at 11:06
  • Sorry for being too late. Can you be sure the method in your managed bean was not called ? Did you add some log message ? It may get called, but the result is not shown in UI. In that case, please add ajaxRendered="true" to the a4j:outputPanel – Laabidi Raissi Mar 19 '13 at 22:32
  • I started the application in the debug mode and faced that the methods are not called, but what i figured out today. the generated event called them self like here: – user2186105 Mar 20 '13 at 12:03
  • as you can see, the rerender is located to selectedMachine:StartDownload instead of – user2186105 Mar 20 '13 at 12:04
  • this is because you do not set prependId to false in your form. So the form id is added to every component inside it. And this should not affect the functionality since you are also using the right ids – Laabidi Raissi Mar 20 '13 at 12:14
  • o.k now it's works. All forms shall have the id's and the order of the compnents must be strictly adhered. Thanks a lot of your support – user2186105 Mar 21 '13 at 12:50
  • glad for you, and please consider the comments of BalusC on your post – Laabidi Raissi Mar 21 '13 at 13:07