Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 呈现的属性不能与请求参数一起使用_Jsf_Jsf 2_Primefaces - Fatal编程技术网

Jsf 呈现的属性不能与请求参数一起使用

Jsf 呈现的属性不能与请求参数一起使用,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,我将JSF2.2与primefaces 5.0一起使用。我有一个xhtml文件,其中有两个文件上传,其中一个应该始终可见,而另一个应该只有在请求参数(名为signmethod)为JAVAME时才可见 <h:panelGrid> <h:panelGroup> <h:outputLabel for="selected_signmethod" value="Selected S

我将JSF2.2与primefaces 5.0一起使用。我有一个xhtml文件,其中有两个文件上传,其中一个应该始终可见,而另一个应该只有在请求参数(名为signmethod)为JAVAME时才可见

            <h:panelGrid>
                <h:panelGroup>
                    <h:outputLabel for="selected_signmethod" value="Selected Signethod : "/>
                    <h:outputText id="selected_signmethod" value="#{param.signmethod}" />
                </h:panelGroup>                    
                <h:panelGroup>
                    <b>Select file(s) to upload:</b>
                </h:panelGroup>                    
            </h:panelGrid>                
            <h:form id="uploadForm" enctype="multipart/form-data">
                <p:message for="file_upload"/>
                <p:fileUpload id="file_upload" allowTypes="#{fileUploadView.allowedTypes}" label="Select file" fileUploadListener="#{fileUploadView.handleFileUpload}"
                              mode="advanced" dragDropSupport="false" update="growl" multiple="true" fileLimit="5"/>
                <p:message for="javame_upload"/>

                <h:panelGroup rendered="#{param.signmethod == 'JAVAME'}" >
                    <b>Select corresponding jar file(s) to upload:</b>
                <p:fileUpload id="javame_upload" allowTypes="" label="Select Jar file for javame" fileUploadListener="#{fileUploadView.handleFileUpload}"
                              mode="advanced" dragDropSupport="false" multiple="true" fileLimit="5"/>
                </h:panelGroup>

                <p:commandButton ajax="false" id="signProceed" value="Proceed" action="#{fileUploadView.submit}"/>
            </h:form> 

选择要上载的文件:
选择要上载的相应jar文件:
但这似乎没有发生。第二个上载组件根本没有得到渲染。我还打印param.signmethod的值,以确保正确的值进入param.signmethod,这是正确的。那么,停止该组件以进行渲染是什么呢

托管Bean代码:

@ManagedBean
@ViewScoped
public class FileUploadView implements Serializable {

@ManagedProperty(value = "#{signBundleBean}")
private SignBundleBean signBundleBean;
static String uploadDirRoot = InitialisationHelper.getUploadDirRoot();
transient Map<String, Object> sessionMap;
ArrayList<Signing> signings;
String username;
SignMethod signMethod;


public FileUploadView() {
    System.out.println("NEW FileUploadView created.");
}

@PostConstruct
public void init() {
    System.out.println("@POstConstruct FileuploadView");
    System.out.println("signMethod : " + signMethod);
    sessionMap = FacesContext.getCurrentInstance().getExternalContext().getSessionMap();        
    signings = signBundleBean.getSignings();
    username = (String) sessionMap.get("username");        
}

public void handleFileUpload(FileUploadEvent e) {
    String signId = "" + DatabaseHelper.genrateSigningId();
    FacesContext ctx = FacesContext.getCurrentInstance();
    UploadedFile uploadedFile = e.getFile();
    String filename = uploadedFile.getFileName();
    if (signId.equals("-1")) {
        FacesMessage fm = new FacesMessage();
        fm.setDetail("Database Connection not working. Please try later.");
        fm.setSummary("DBConnection_Error");
        fm.setSeverity(FacesMessage.SEVERITY_ERROR);
        //ctx.addMessage(null, fm);
        ctx.addMessage("uploadForm:file_upload", fm);
        return;
    }
    if (username == null) {
        FacesMessage fm = new FacesMessage();
        fm.setDetail("You are not in session to upload.");
        fm.setSummary("Session_Error");
        fm.setSeverity(FacesMessage.SEVERITY_ERROR);
        ctx.addMessage("uploadForm:file_upload", fm);
        return;
    }

    Signing sg;
    sg = new Signing(signId, username, filename, signMethod, false);
    signings.add(sg);
    System.out.println("Signing added : " + sg);
    signBundleBean.setMaxParameters(SignParametersInitialisation.getNumberOfParameters(signMethod));

    try {
        InputStream is = uploadedFile.getInputstream();
        OutputStream os = new FileOutputStream(sg.getUploadfile());
        byte[] bytes = new byte[1024];
        int read = 0;
        while ((read = is.read(bytes)) != -1) {
            os.write(bytes, 0, read);
        }
        os.flush();
        sg.setUploaded(true);
        is.close();
        os.close();
    } catch (IOException ex) {
        signings.remove(sg);
        Logger.getLogger(FileUploadView.class.getName()).log(Level.SEVERE, null, ex);
    }
    FacesMessage fm = new FacesMessage();
    fm.setDetail(filename);
    fm.setSummary("FileUploaded");
    fm.setSeverity(FacesMessage.SEVERITY_INFO);
    //ctx.addMessage(null, fm);
    ctx.addMessage(null, fm);
    System.out.println(sg + " File uploaded to " + sg.getUploadfile());

}


}
@ManagedBean
@视域
公共类FileUploadView实现可序列化{
@ManagedProperty(value=“#{signBundleBean}”)
私有SignBundleBean SignBundleBean;
静态字符串uploadDirRoot=InitialisationHelper.getUploadDirRoot();
瞬态地图会话地图;
ArrayList签名;
字符串用户名;
SignMethod SignMethod;
公共文件上载视图(){
System.out.println(“创建了新文件上传视图”);
}
@施工后
公共void init(){
System.out.println(“@POstConstruct FileuploadView”);
System.out.println(“signMethod:+signMethod”);
sessionMap=FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
signings=signBundleBean.getSignings();
用户名=(字符串)sessionMap.get(“用户名”);
}
公共无效handleFileUpload(文件上载事件e){
String signed=“+DatabaseHelper.genrateSigningId();
FacesContext ctx=FacesContext.getCurrentInstance();
UploadedFile UploadedFile=e.getFile();
字符串文件名=uploadedFile.getFileName();
if(符号等于(“-1”)){
FacesMessage fm=新的FacesMessage();
setDetail(“数据库连接不工作,请稍后再试”);
fm.setSummary(“DBConnection_错误”);
fm.设置严重性(面部信息严重性错误);
//ctx.addMessage(null,fm);
添加消息(“上传形式:文件上传”,fm);
返回;
}
如果(用户名==null){
FacesMessage fm=新的FacesMessage();
setDetail(“您不在上传会话中。”);
fm.setSummary(“会话_错误”);
fm.设置严重性(面部信息严重性错误);
添加消息(“上传形式:文件上传”,fm);
返回;
}
签署sg;
sg=新签名(签名、用户名、文件名、签名方法、false);
签名。添加(sg);
System.out.println(“添加签名:+sg”);
signBundleBean.setMaxParameters(SignParametersInitialization.getNumberOfParameters(signMethod));
试一试{
InputStream is=uploadedFile.getInputstream();
OutputStream os=新文件OutputStream(sg.getUploadfile());
字节[]字节=新字节[1024];
int read=0;
而((read=is.read(bytes))!=-1){
写入(字节,0,读取);
}
os.flush();
sg.setUploaded(真);
is.close();
os.close();
}捕获(IOEX异常){
签名。移除(sg);
Logger.getLogger(FileUploadView.class.getName()).log(Level.SEVERE,null,ex);
}
FacesMessage fm=新的FacesMessage();
setDetail(文件名);
fm.setSummary(“文件上传”);
fm.setSeverity(面部信息、严重程度信息);
//ctx.addMessage(null,fm);
ctx.addMessage(null,fm);
System.out.println(sg+“文件上载到”+sg.getUploadfile());
}
}

您可以发布托管bean代码吗?或者您没有运行您认为正在运行的代码,或者参数值不完全是
JAVAME
。可能是空白?我访问页面的方式是:/FileUpload.xhtml?I=1&server=ADC&signmethod=JAVAME,因此signmethod不能有空白,param.signmethod正在打印正确的值。添加到代码中的托管Bean代码请在用以下内容(大小写更正)替换呈现子句后再试一次:“#{param.signmethod='JAVAME'}”