문제

나는 4567.00, 8976.00 등의 금액을 얻고 있습니다. 이제이 값을 디스플레이 태그에서 분리하는 동안 4567.00 대신 $ 4567.00으로 인쇄하고 싶습니다. 어떻게 할 수 있습니까? 단지 디스플레이 태그를 사용하고 싶다면. Core : Out 태그를 사용하여 같은 것을 달성 할 수 있습니다.

$<core:out value="${variableInMyList}" />

답변을 찾았습니다 [어떻게했는지

새 클래스 만들기 :

public class NumberFormatDecorator implements DisplaytagColumnDecorator{
    Logger logger = MyLogger.getInstance ( );

    public Object decorate(Object columnValue, PageContext pageContext, MediaTypeEnum media) throws DecoratorException {        
        try
        {
            Object colVal = columnValue;
            if ( columnValue != null ){
                colVal = Double.parseDouble( (String)columnValue );
            }
            return colVal;
        }catch ( Exception nfe ){}
        logger.error( "Unable to convert to Numeric Format");
        return columnValue; // even if there is some exception return the original value
    }
}

이제 디스플레이 태그에 있습니다

<displaytag:column title="Amount" property="amount" decorator="com.rj.blah.utils.decorator.NumberFormatDecorator" format="$ {0,number,0,000.00}"/>

메모: DisplayTag의 형식 속성으로 MessageFormat을 사용할 수 있습니다 : 열.

도움이 되었습니까?

해결책

DisplayTab은 JSTL 또는 EL 친화적이지 않으며 해당 스타일의 형식을 지원하지 않습니다. 대신, 표정식 클래스를 확장하고 디스플레이의 데코레이터 속성 : 테이블 태그를 사용하여 참조해야합니다.

데코레이터 서브 클래스는 다음과 같은 형식의 통화 열에 대한 getter 메소드를 정의해야합니다.

public class MyTableDecorator extends TableDecorator {
    public String getCurrency() {
        MyRowType row = getCurrentRowObject();
        return row.getCurrency.format();
    }
}

그리고

<display:table name="myList" decorator="test.MyTableDecorator">
    <display:column property="myProperty" title="My Property"/>
    <display:column property="currency" title="Currency"/>
</display:table>

또는 DisplayTagcolumnDecorator 인터페이스를 구현하고 JSP의 데코레이터를 참조 할 수 있습니다.

<display:table name="myList">
    <display:column property="myProperty" title="My Property"/>
    <display:column property="currency" title="Currency" decorator="test.MyColumnDecorator"/>
</display:table>

보다 문서 자세한 내용은

다른 팁

수업이 필요한 것은 무엇입니까? 다음과 같이 쓸 수 있습니다.

<displaytag:column property="amount" format="$ {0,number,0,000.00}"/>

데코레이터를 사용할 수 있습니다.

당신은 같은 것을 가질 것입니다

class myDecorator extends TableDecorator{

 public String getCurrency(){
   MyClass myClass  = (MyClass)getCurrentRow();


   return "$"+myClass.getCurrency;

 }
}

한번 봐봐! http://displaytag.sourceforge.net/10/tut_decorators.html

데코레이터를 사용하지 않으려면 ID 속성과 JSTL을 사용할 수 있습니다.

<display:table htmlId="list" name="mylist" id="row">

   <display:column>
    <%-- row is your current list object. row.currency calls getCurrency()
         $ goes right out to HTML
    --%>
     $ <c:out="${row.currency}"/>
   </display:column>
</display:table>

에서 디스플레이 : 태그 태그 참조

ID: uid 참조

uid:이 테이블을 식별하는 데 사용되는 고유 ID. 현재 행을 나타내는 객체 도이 이름의 PageContext에 추가되며 Key UID_Rownum을 사용하여 현재 행 번호가 추가됩니다. 같은 페이지의 두 테이블은 동일한 UID를 가질 수 없습니다 (페이징 및 분류는 둘 다에 영향을 미칩니다). "htmlid"가 지정되지 않은 경우 생성 된 테이블의 HTML ID에 동일한 값이 사용됩니다.

여기에 내가 사용하는 것은 다음과 같습니다.

<d:column title="Cost" property="cost" format="{0,number,currency}" sortable="true"/>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top