标签: viewaction

什么可以使用<f:metadata>,<f:viewParam>和<f:viewAction>?

任何人都可以澄清我们如何在一般情况下使用,或者在现实世界中使用这个代码片段?

<f:metadata>
    <f:viewParam id="id" value="#{bean.id}" />
    <f:viewAction action="#{bean.init}" />
</f:metadata>
Run Code Online (Sandbox Code Playgroud)

jsf jsf-2 viewparams viewaction

146
推荐指数
1
解决办法
12万
查看次数

何时使用f:viewAction/preRenderView与PostConstruct?

什么时候应该使用f:viewActionor preRenderView事件来初始化页面的数据而不是使用@PostConstruct注释?基于支持bean的范围类型使用一个或另一个的基本原理例如,如果支持bean是@RequestScoped,那么在呈现视图之前选择使用f:viewActionpreRenderView覆盖@PostConstruct初始化支持bean是不相关的,因为两者会结果是一样的吗?

f:viewAction或preRenderView

<f:metadata>
  <f:viewAction action="#{myBean.initialize}" />
</f:metadata>
Run Code Online (Sandbox Code Playgroud)
<f:metadata>
  <f:event type="preRenderView" listener="#{myBean.initialize}"/>
</f:metadata>
Run Code Online (Sandbox Code Playgroud)

要么

@PostConstruct

public class MyBean
{
    @PostConstruct
    public void initialize()
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

jsf postconstruct jsf-2 prerenderview viewaction

90
推荐指数
1
解决办法
7万
查看次数

Android安装apk与Intent.VIEW_ACTION无法使用文件提供程序

我的应用程序有一个自动更新功能,下载APK,下载完成后,Intent.VIEW_ACTION打开应用程序,让用户安装下载的apk

         Uri uri = Uri.parse("file://" + destination);
         Intent install = new Intent(Intent.ACTION_VIEW);
        install.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        install.setDataAndType(uri,
            manager.getMimeTypeForDownloadedFile(downloadId));
        activity.startActivity(install);
Run Code Online (Sandbox Code Playgroud)

这适用于所有设备<24

现在使用Android 24显然我们不再允许使用file:///启动意图并且在一些谷歌搜索之后建议使用A文件提供程序

新代码:

Intent install = new Intent(Intent.ACTION_VIEW);
    install.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    Uri apkUri = FileProvider.getUriForFile(AutoUpdate.this,
        BuildConfig.APPLICATION_ID + ".provider", file);
    install.setDataAndType(apkUri,
        manager.getMimeTypeForDownloadedFile(downloadId));
    activity.startActivity(install);
Run Code Online (Sandbox Code Playgroud)

现在activity.startActivity(安装); 抛出错误

找不到处理Intent的活动{act = android.intent.action.VIEW dat = content://com.xxxx.xx.provider/MyFolder/Download/MyApkFile.apk typ = application/vnd.android.package-archive flg = 0x4000000}

有什么方法可以在Android 7(24)中打开APK查看器吗?

android android-intent android-fileprovider viewaction android-7.0-nougat

61
推荐指数
3
解决办法
4万
查看次数

根据f:viewParam有条件地调用f:viewAction

我们有一个设置,我们将不同的可选视图参数传递给JSF页面,并在设置参数后处理后续视图操作.一个非常简单的例子如下所示:

page.xhtml:

<?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:h="http://xmlns.jcp.org/jsf/html"
  xmlns:f="http://xmlns.jcp.org/jsf/core">

<f:view>
    <f:metadata>
        <f:viewParam name="a" value="#{page.a}"/>
        <f:viewAction action="#{page.populateA()}" if="#{not empty page.a}"/>

        <f:viewParam name="b" value="#{page.b}"/>
        <f:viewAction action="#{page.populateB()}"/>
    </f:metadata>

    <h:outputLabel value="#{page.message}"/>
</f:view>
</html>
Run Code Online (Sandbox Code Playgroud)

import javax.faces.view.ViewScoped;
import javax.inject.Named;

@ViewScoped
@Named
public class Page {

    private String a;

    private String b;

    private String message;

    public String getA() {
        return a;
    }

    public void setA(String a) {
        this.a = a;
    }

    public String getB() {
        return b;
    } …
Run Code Online (Sandbox Code Playgroud)

jsf jsf-2.2 viewaction

3
推荐指数
1
解决办法
2229
查看次数