All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.feilong.taglib.display.option.OptionTag Maven / Gradle / Ivy

Go to download

feilong is a suite of core and expanded libraries that include utility classes, http, excel,cvs, io classes, and much much more.

There is a newer version: 4.0.8
Show newest version
/*
 * Copyright (C) 2008 feilong
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.feilong.taglib.display.option;

import javax.servlet.http.HttpServletRequest;

import com.feilong.taglib.AbstractLocaleSupportTag;
import com.feilong.taglib.display.LocaleSupportUtil;
import com.feilong.taglib.display.SimpleTagParamCacheManager;

/**
 * 用来基于 i18n配置文件,渲染select option选项,实现国际化功能,简化开发.
 * 
 * 

* 你可以访问 wiki 查看更多 feilongDisplay-option *

* *

示例:

*
* * 假设有 i18n/education_zh_CN.properties 内容如下: * *
 * edu.option1=初中
 * edu.option2=高中
 * edu.option3=中专
 * edu.option4=大专
 * edu.option5=本科
 * edu.option6=硕士
 * edu.option7=博士
 * edu.option8=其他
 * 
* * 我们现在需要在jsp中渲染成 select option 项,我们可以使用下面的方式: * *
{@code <%@ taglib prefix="feilongDisplay" uri="http://java.feilong.com/tags-display"%>}
{@code

}
 * 
* * 此时页面渲染结果为: * *
 * {@code 
        
   }
 * 
* *
* *

关于 selectedKey:

*
* *
 * 
 * 如果要做有值默认选中,那么可以设置  selectedKey 参数
 * {@code
    
}
 * 此时页面渲染结果为
 * {@code 
    
   }
 * 
* *
* *

关于 locale:

*
*

* 如果此时我们有英文语言站点,他的配置文件是i18n/education_en.properties,内容如下: * *

 * 
 * edu.option1=Middle School
 * edu.option2=Junior College
 * edu.option3=Bachelor
 * edu.option4=Others(Master/PHD)
 * 
* *

* * 可以传递 locale参数,如下: * *
    {@code <%}
        //此处是演示代码,实际开发过程中,不允许使用 {@code  <% %>} 里面写jsp scriptlet
        request.setAttribute("enLocale", Locale.ENGLISH);
    {@code %>}
    
    {@code }
 * 
* * 返回: * *
{@code 
    
}
 * 
* *
* * @author feilong * @see feilongDisplay-option * @since 1.5.4 */ @SuppressWarnings("squid:S110") //Inheritance tree of classes should not be too deep public class OptionTag extends AbstractLocaleSupportTag{ /** The Constant serialVersionUID. */ private static final long serialVersionUID = -4523036188885941366L; /** 选中的key,可以不传,那么没有option会是选中状态,如果设置了,那么对应的key option的状态是 选中. */ private String selectedKey; //--------------------------------------------------------------- /* * (non-Javadoc) * * @see com.feilong.taglib.AbstractWriteContentTag#writeContent() */ @Override protected Object buildContent(HttpServletRequest request){ OptionParam optionParam = new OptionParam(); optionParam.setBaseName(baseName); optionParam.setLocale(LocaleSupportUtil.toLocal(locale, request)); optionParam.setSelectedKey(selectedKey); return SimpleTagParamCacheManager.getContent(optionParam, OptionCacheContentBuilder.INSTANCE); } //--------------------------------------------------------------- /** * 设置 选中的key,可以不传,那么没有option会是选中状态,如果设置了,那么对应的key option的状态是 选中. * * @param selectedKey * the selectedKey to set */ public void setSelectedKey(String selectedKey){ this.selectedKey = selectedKey; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy