使用jsf2为Web应用程序建模的国际化i18n消息

时间:2019-06-24 12:12:03

标签: jsf model internationalization

我有一个使用jsf2的应用程序JEE,并且我的应用程序模型带有消息的操作结果。

带有我的模型类代码的示例

/*
 * This code is under license Creative Commons Attribution-ShareAlike 1.0
 * <a href="https://creativecommons.org/licenses/by-sa/1.0/legalcode"></a>
 */
package it.unibas.printspooler.modello.logic.state;

import it.unibas.printspooler.Costanti;
import it.unibas.printspooler.modello.operations.Operation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 *
 * @author https://github.com/vincenzopalazzo
 */
public class FreeState extends AbstractSpoolerState {

    private final Log LOGGER = LogFactory.getLog(FreeState.class);

    public FreeState() {
        super(Costanti.State.STATE_FREE);
    }

    @Override
    public boolean isBusy() {
        return false;
    }

    @Override
    public boolean isError() {
        return false;
    }

    @Override
    public boolean isFree() {
        return true;
    }

    @Override
    public String getDescriptionState() {
        return super.getState();
    }

    @Override
    public String hasPrintable(PrintSpoiler spoller, Operation newOperation, Operation lastOperation) {
        super.hasPrintable(spoller, newOperation, lastOperation);

        if(spoller.getWaitOperation().isEmpty()){
            LOGGER.debug("The wait queue operation is empty");
            spoller.getSuccessulfuOperation().add(newOperation);
            return "The wait queue operation is empty";
        }

        return "The wait queue operation isn't empty, the spooler state is busy";
    }


}

将消息返回到screen.jsf的方法是

@Override
    public String hasPrintable(PrintSpoiler spoller, Operation newOperation, Operation lastOperation) {
        super.hasPrintable(spoller, newOperation, lastOperation);

        if(spoller.getWaitOperation().isEmpty()){
            LOGGER.debug("The wait queue operation is empty");
            spoller.getSuccessulfuOperation().add(newOperation);
            return "The wait queue operation is empty";
        }

        return "The wait queue operation isn't empty, the spooler state is busy";
    }

我应该使用jsf2框架将此消息国际化

  • 返回“等待队列操作不为空,后台打印程序状态为忙”;
  • 返回“等待队列操作为空”;

对不起,我的英语不好,但是我正在学习

1 个答案:

答案 0 :(得分:0)

您可以使用资源包来标记您的标签。可以直接从xhtml页面和/或Java Bean中使用捆绑软件。

很多网站都以很多细节介绍了这种技术,我个人将从这两个开始:

  1. https://www.tutorialspoint.com/jsf/jsf_internationalization.htm
  2. https://www.mkyong.com/jsf2/jsf-2-internationalization-example/