简体   繁体   English

JSF 1.2 到 JSF 2.3 与 Tomahawk-Savestate 自己的保存状态组件?

[英]JSF 1.2 to JSF 2.3 with Tomahawk-Savestate own savestate component?

We have a large Webapp that is still using JSF 1.2 with Myfaces and Tomahawk.我们有一个大型 Web 应用程序,它仍在使用 JSF 1.2 和 Myfaces 和 Tomahawk。 The migration of JSF itself seems to be no big problem but as tomahawk isn't developed anymore we have to get rid of all our savestate usages. JSF 本身的迁移似乎没有什么大问题,但由于不再开发战斧,我们必须摆脱所有保存状态的使用。 I know that we should use the Viewscope or similar Scopes to remove the savestate but this causes the problem that the behaviour is different to our savestate usage.我知道我们应该使用 Viewscope 或类似的 Scopes 来删除保存状态,但这会导致行为与我们的保存状态使用不同的问题。 We only stored a few specific values inside the savestate not the whole bean.我们只在 savestate 中存储了一些特定的值,而不是整个 bean。

So if we migrate by replacing the savestate with the scope we have to test every single site if it still works how it sould.因此,如果我们通过用 scope 替换保存状态进行迁移,我们必须测试每个站点是否仍然可以正常工作。

Would it be possible to develop an own savestate component that'll work with JSF2.3?是否有可能开发一个可以与 JSF2.3 一起使用的自己的保存状态组件? If yes we just could replace t:savestate with ne new component and migrate the old views when rebuilding them.如果是,我们可以将 t:savestate 替换为新组件,并在重建旧视图时迁移它们。

Would it be possible to develop an own savestate component that'll work with JSF2.3?是否有可能开发一个可以与 JSF2.3 一起使用的自己的保存状态组件?

Yes.是的。

Here's a kickoff example based off the original source code of <t:saveState> :这是一个基于<t:saveState>原始源代码的启动示例:

@FacesComponent(createTag=true)
public class SaveState extends UIParameter {

    public SaveState() {
        setRendererType(null);
    }

    @Override
    public Object saveState(FacesContext context) {
        Object[] values = new Object[2];
        values[0] = super.saveState(context);

        if (getValueExpression("value") != null) {
            values[1] = getValue();
        }

        return values;
    }

    @Override
    public void restoreState(FacesContext context, Object state) {
        Object values[] = (Object[]) state;
        super.restoreState(context, values[0]);
        ValueExpression valueExpression = getValueExpression("value");

        if (valueExpression != null) {
            valueExpression.setValue(context.getELContext(), values[1]);
        }
    }

}

In order to use it, declare against the predefined XML name space of http://xmlns.jcp.org/jsf/component :为了使用它,请针对http://xmlns.jcp.org/jsf/component的预定义 XML 名称空间声明:

<anyElement ... xmlns:my="http://xmlns.jcp.org/jsf/component">
    ...
    <my:saveState value="#{bean.property}" />
    ...
</anyElement>

That's all.就这样。 Thanks to the createTag=true feature of the @FacesComponent you don't need to explicitly register the custom component in any XML file.由于@FacesComponentcreateTag=true特性,您不需要在任何 XML 文件中显式注册自定义组件。

An alternative would be to use OmniFaces <o:inputHidden> , but that would potentially require an explicit converter as it's passed as a HTTP request parameter rather than via JSF state.另一种方法是使用OmniFaces <o:inputHidden> ,但这可能需要一个显式转换器,因为它作为 HTTP 请求参数而不是通过 JSF Z9ED39E2EA931586B67A985A6EZEF 传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM