zoukankan      html  css  js  c++  java
  • Switch View when host XmlFormView in aspx

    当把XmlFormView放到自己的aspx页面的时候,可能需要切换视图的逻辑,比如当流程绑定到表单库的时候,QuickFlow的FormServiceFormTask页面会按照任务活动的TaskFields中的__CurrentView字段来切换视图。

    XmlFormView本身提供2个方法:

    XmlViewer.XmlForm.ViewInfos.SwitchView("Approval")

    XmlViewer.XmlForm.ViewInfos.Initial = XmlViewer.XmlForm.ViewInfos["Approval"]

    但这两个方法或者出错,或者没用。

    找到的最合理的方式是采用js切换,参考 http://www.moss2007.be/blogs/vandest/archive/2008/10/10/forms-server-xmlformview-and-setting-the-initialview-on-load.aspx

    但这样会造成页面二次刷新。

    没办法用Reflect分析代码,找到这个用反射设置视图的方法:

    1)for SharePoint2007

    void SwitchView12(string viewName)
            {
                if (String.IsNullOrEmpty(viewName))
                    throw new ArgumentNullException("viewName");
    
                //check view exist.
                object viewInfo = null;
    
                try
                {
                    viewInfo = this.XmlViewer.XmlForm.ViewInfos[viewName];
                }
                catch { }
    
                if (viewInfo == null)
                {
                    throw new NotSupportedException("view doesn't exist:" + viewName);
                    return;
                }
    
                //利用反射控制  this.XmlViewer.XmlForm.Document.CurrentViewName
                System.Reflection.PropertyInfo pDocument = this.XmlViewer.XmlForm.GetType().GetProperty("Document", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                if (pDocument == null)
                {
                    throw new NullReferenceException("can't get property XmlForm.Document");
                    return;
                }
                object objDoc = pDocument.GetValue(this.XmlViewer.XmlForm, null);
                if (objDoc == null)
                {
                    throw new NullReferenceException("can't get value: XmlForm.Document");
                    return;
                }
    
                //objDoc.CurrentView = objDoc.Solution.Views[this._xmlFormHost.ViewInfos.Default.Name];
    
                System.Reflection.PropertyInfo pCurrentView = objDoc.GetType().GetProperty("CurrentView");
                //Debug("CurrentView: " + pCurrentView);
    
                System.Reflection.PropertyInfo pSolution = objDoc.GetType().GetProperty("Solution");
                //Debug("pSolution: " + pSolution);
    
                object objSolution = pSolution.GetValue(objDoc, null);
                //Debug("objSolution: " + objSolution); 
    
                IDictionary views = objSolution.GetType().GetProperty("Views", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(objSolution, null) as IDictionary;
                //Debug("views: " + views); 
    
                object v = views[viewName];
                //Debug("v: " + v); 
    
                pCurrentView.SetValue(objDoc, v, null);
            }
    

      此方法在OnInitlized方法中调用。

    2)for SharePoint2010

    以上方法在2010上应该也是可以的,但2010提供了一个更方便的方法:XmlFormView.DefaultView,

    bool SwitchView14(string viewName)
    {
    var pDefaultView = XmlViewer.GetType().GetProperty("DefaultView");//只能在DataBind之前设置

    //DefaultView属性可能是公共方法,这样就不必用反射了,但笔者是在2007下实现的这段代码,所以必须用反射
    if (pDefaultView == null)
    return false;
    pDefaultView.SetValue(XmlViewer, viewName, null);
    return true;
    }

    这个方法不同的是:不能在OnInitlized方法中调用,必须在XmlFormView DataBind之前调用。

  • 相关阅读:
    JAVA基础学习之路(九)[2]String类常用方法
    [MYSQL]练习(一)
    JAVA基础学习之路(十一)引用传递
    java--多线程编程简介
    序列化和反序列化的理解
    简单的socket编程
    php-生成数据库设计文档
    centos7 jenkins安装和使用
    centos7 rabbitmq安装以及应用
    centos7 dubbokeeper安装
  • 原文地址:https://www.cnblogs.com/jianyi0115/p/2280791.html
Copyright © 2011-2022 走看看