首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

JSF转换器解决办法

2012-01-01 
JSF转换器h:columnf:facetname header h:outputTextvalue 类型 //f:faceth:outputTextvalu

JSF转换器
<h:column>
    <f:facet   name= "header ">

    <h:outputText   value= "类型 "/>

    </f:facet>

    <h:outputText   value= "#{bean.infoType} "/>

  </h:column>

这句会输出信息的类型比如Enume-String,Int   等   ,如何写一个转换器遇到
Int自动转换为“整形”等等,书上网上都是输入时用的转换器,没见到输出用的,哪位有输出的转换器贴一下看看,我想了解   输出时   getAsObject
getAsString,这些是如何写的!如果有代码最好能帖全,谢谢各位!

[解决办法]
不清楚你想问什么,看不大懂你的问题。
[解决办法]
output组件没有转换器

自己在bean里写个新的get方法,返回你期望的结果吧
[解决办法]
<t:panelGroup rendered= "#{bean.infoType == 'aaa '} ">
<h:outputText value= "bbb "/>
</t:panelGroup>

[解决办法]
不是复杂的数据类型为何需要converter啊?
[解决办法]
public Object getAsObject(FacesContext context, UIComponent componet, String string)
throws ConverterException {

if(null != string && string.equals( "aaa ")){
return sss;
}

return string ;
}
getAsString反过来。。。试试看,应该是你说的意思
[解决办法]
package org.chy.test.bean;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;

public class UserConverter implements Converter {

public Object getAsObject(FacesContext context, UIComponent component,
String str) throws ConverterException {
// TODO 处理输入
if(null != string && string.equals( "sss ")){
            return new String( "aaa ");
          }

          return string ;
          }

public String getAsString(FacesContext context, UIComponent component,
Object obj) throws ConverterException {
//处理输出
if (obj == null) {
return new String( "对象是空的 ");
} else {

String str = ((String) obj).toString();
if(str.equals( "sss ")){
str= "aaa ";
}
}
return str;
}
}

仅供参考~
[解决办法]
package converter; 

import javax.faces.component.UIComponent; 
import javax.faces.context.FacesContext; 
import javax.faces.convert.Converter; 
import javax.faces.convert.ConverterException; 

public class StringConverter implements Converter { 

public Object getAsObject(FacesContext context, UIComponent component,String str) throws ConverterException { 
    return str; 
    } 

public String getAsString(FacesContext context,UIComponent component, Object obj) throws ConverterException{
if ("sss".equals((String)obj)) { 
return "aaa";
}
return (String)obj; 


然后在faces-config.xml中加入
<converter>
<converter-id>StringConverter</converter-id>


<converter-class>
converter.StringConverter
</converter-class>
</converter>
最后在页面上:
<h:outputText value= "#{bean.infoType}" converter=“StringConverter”/>
这样就可以了

热点排行